CompanyManagement.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <!-- 公司管理 -->
  3. <div class="home">
  4. <actionBar :operateList="operateList" :formList="formList" :ruleForm="searchRuleForm" @openModel="openModel"
  5. @searchProtocol="searchProtocol"></actionBar>
  6. <div class="card_content">
  7. <!-- 表单 -->
  8. <treeTable :treeData="treeData" :treeDataList="treeDataList" @buttonData="buttonData"></treeTable>
  9. <!-- 分页 -->
  10. <div v-if="Total">
  11. <pagination :total="Total" :currentPage="Pagination.PageIndex" @changeSize="changeSize"
  12. @changeCurrent="changeCurrent">
  13. </pagination>
  14. </div>
  15. </div>
  16. <el-dialog :title="staffTitle" :visible.sync="staffDialogVisible" width="600px" :close-on-click-modal="false"
  17. @close="closeDialog">
  18. <forms ref="childRules" :formNewList="formRuleList" :ruleForm="ruleForm" labelWidth="150px"></forms>
  19. <span slot="footer" class="dialog-footer">
  20. <el-button plain @click="staffDialogVisible = false">取 消</el-button>
  21. <el-button type="primary" :loading="confirmLoading" @click="handleAdd">确 定</el-button>
  22. </span>
  23. </el-dialog>
  24. </div>
  25. </template>
  26. <script>
  27. import {
  28. getCompany,
  29. getCompanyDetails,
  30. addCompany,
  31. putCompany,
  32. delCompany
  33. } from '@/api/company'
  34. import actionBar from '@/components/actionBar'
  35. import treeTable from '@/components/treeTable'
  36. import pagination from '@/components/pagination'
  37. import forms from '@/components/forms'
  38. import {
  39. formRules,
  40. employee
  41. } from "./company.js";
  42. export default {
  43. name: 'UserManagement',
  44. components: {
  45. actionBar,
  46. treeTable,
  47. pagination,
  48. forms,
  49. },
  50. data() {
  51. return {
  52. operateList: [{
  53. type: 'add',
  54. title: '添加公司',
  55. icon: 'el-icon-plus',
  56. }],
  57. formList: [{
  58. type: 'input',
  59. label: '名称',
  60. field: 'name',
  61. placeholder: '名称',
  62. }],
  63. searchRuleForm: {
  64. name: '',
  65. },
  66. searchValue: {},
  67. Pagination: {
  68. PageIndex: 1,
  69. PageSize: 10,
  70. },
  71. Total: 0,
  72. operationType: '',
  73. tableList: employee(),
  74. tableData: [],
  75. staffTitle: '添加',
  76. staffDialogVisible: false,
  77. formRuleList: [],
  78. ruleForm: {
  79. name: '',
  80. appName: '',
  81. companyAddress: '',
  82. coldKey: '',
  83. isIceReleaseCold: false,
  84. isCoolerReleaseCold: false,
  85. isOutStorage: false,
  86. iceRaftManage: false,
  87. remark: '',
  88. },
  89. confirmLoading: false,
  90. treeData: employee(),
  91. treeDataList: [],
  92. parentId: null,
  93. }
  94. },
  95. mounted() {
  96. const dataList = formRules();
  97. this.formRuleList = dataList;
  98. this.getList()
  99. },
  100. methods: {
  101. // 搜索
  102. searchProtocol(value) {
  103. this.searchValue = value
  104. this.getList()
  105. },
  106. // 获取公司列表
  107. getList() {
  108. var params = {
  109. page: this.Pagination.PageIndex,
  110. pageSize: this.Pagination.PageSize,
  111. ...this.searchValue
  112. }
  113. getCompany(params).then(res => {
  114. if (res.code == 200) {
  115. this.treeDataList = res.data
  116. this.Total = res.data.count
  117. }
  118. })
  119. },
  120. // 弹窗表单添加
  121. handleAdd() {
  122. let flag = this.$refs['childRules'].validateForm();
  123. if (flag) {
  124. if (this.operationType == 'add' || this.operationType == 'subAdd') {
  125. this.confirmLoading = true
  126. var params = {
  127. ...this.ruleForm
  128. }
  129. if (this.operationType == 'subAdd') {
  130. params.parentId = this.parentId
  131. }
  132. addCompany(params).then(res => {
  133. if (res.code == 200) {
  134. this.$message({
  135. message: '操作成功',
  136. type: 'success'
  137. });
  138. this.getList()
  139. }
  140. this.staffDialogVisible = false
  141. this.confirmLoading = false
  142. }).catch(() => {
  143. this.confirmLoading = false
  144. })
  145. } else if (this.operationType == 'edit') {
  146. this.confirmLoading = true
  147. var params = {
  148. id: this.ruleForm.id,
  149. name: this.ruleForm.name,
  150. appName: this.ruleForm.appName,
  151. remark: this.ruleForm.remark,
  152. coldKey: this.ruleForm.coldKey,
  153. companyAddress: this.ruleForm.companyAddress,
  154. isIceReleaseCold: this.ruleForm.isIceReleaseCold,
  155. isCoolerReleaseCold: this.ruleForm.isCoolerReleaseCold,
  156. isOutStorage: this.ruleForm.isOutStorage,
  157. iceRaftManage: this.ruleForm.iceRaftManage,
  158. }
  159. putCompany(params).then(res => {
  160. if (res.code == 200) {
  161. this.$message({
  162. message: '操作成功',
  163. type: 'success'
  164. });
  165. this.getList()
  166. }
  167. this.staffDialogVisible = false
  168. this.confirmLoading = false
  169. }).catch(() => {
  170. this.confirmLoading = false
  171. })
  172. }
  173. } else {
  174. this.$message.error('表单信息不完整,请继续填写完整');
  175. }
  176. },
  177. buttonData(row, type) {
  178. this.operationType = type
  179. if (type == 'edit') {
  180. this.staffTitle = '编辑'
  181. this.staffDialogVisible = true
  182. setTimeout(() => {
  183. this.$nextTick(() => {
  184. this.ruleForm = JSON.parse(JSON.stringify(row))
  185. })
  186. })
  187. } else if (type == 'del') {
  188. this.deleteUser(row.id)
  189. } else if (type == 'subAdd') {
  190. this.staffTitle = '添加子级'
  191. this.staffDialogVisible = true
  192. this.parentId = row.id
  193. }
  194. },
  195. openModel(type) {
  196. this.staffTitle = '添加'
  197. this.staffDialogVisible = true
  198. this.operationType = type
  199. },
  200. // 删除公司
  201. deleteUser(id) {
  202. this.$confirm('此操作将永久删除该公司, 是否继续?', '提示', {
  203. confirmButtonText: '确定',
  204. cancelButtonText: '取消',
  205. type: 'warning'
  206. }).then(() => {
  207. delCompany({
  208. id: id,
  209. }).then(res => {
  210. if (res.code == 200) {
  211. this.$message({
  212. message: '操作成功',
  213. type: 'success'
  214. });
  215. this.getList()
  216. }
  217. })
  218. }).catch(() => {});
  219. },
  220. changeSize(val) {
  221. this.Pagination.PageSize = val
  222. this.getList()
  223. },
  224. changeCurrent(val) {
  225. this.Pagination.PageIndex = val
  226. this.getList()
  227. },
  228. // 清空表单
  229. closeDialog() {
  230. // this.ruleForm = {}
  231. this.ruleForm.name = ''
  232. this.ruleForm.appName = ''
  233. this.ruleForm.companyAddress = ''
  234. this.ruleForm.coldKey = ''
  235. this.ruleForm.isIceReleaseCold = false
  236. this.ruleForm.isCoolerReleaseCold = false
  237. this.ruleForm.isOutStorage = false
  238. this.ruleForm.iceRaftManage = false
  239. this.ruleForm.remark = ''
  240. this.$refs.childRules.resetCheck();
  241. }
  242. }
  243. }
  244. </script>