CompanyManagement.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. <tables :suspension="true" :tableList="tableList" :tableData="tableData" @buttonData="buttonData"></tables>
  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. addCompany,
  30. putCompany,
  31. delCompany
  32. } from '@/api/company'
  33. import actionBar from '@/components/actionBar'
  34. import tables from '@/components/tables'
  35. import pagination from '@/components/pagination'
  36. import forms from '@/components/forms'
  37. import {
  38. formRules,
  39. employee
  40. } from "./company.js";
  41. export default {
  42. name: 'UserManagement',
  43. components: {
  44. actionBar,
  45. tables,
  46. pagination,
  47. forms
  48. },
  49. data() {
  50. return {
  51. operateList: [{
  52. type: 'add',
  53. title: '添加公司',
  54. icon: 'el-icon-plus',
  55. }],
  56. formList: [{
  57. type: 'input',
  58. label: '名称',
  59. field: 'name',
  60. placeholder: '名称',
  61. }],
  62. searchRuleForm: {
  63. name: '',
  64. },
  65. Pagination: {
  66. PageIndex: 1,
  67. PageSize: 10,
  68. },
  69. Total: 0,
  70. tableData: [],
  71. operationType: '',
  72. tableList: employee(),
  73. tableData: [],
  74. staffTitle: '添加',
  75. staffDialogVisible: false,
  76. formRuleList: [],
  77. ruleForm: {},
  78. confirmLoading: false,
  79. }
  80. },
  81. mounted() {
  82. const dataList = formRules();
  83. this.formRuleList = dataList;
  84. this.getList()
  85. },
  86. methods: {
  87. // 搜索
  88. searchProtocol(value) {
  89. this.searchValue = value
  90. this.getList()
  91. },
  92. // 获取订单列表
  93. getList() {
  94. var params = {
  95. page: this.Pagination.PageIndex,
  96. pageSize: this.Pagination.PageSize,
  97. ...this.searchValue
  98. }
  99. getCompany(params).then(res => {
  100. if (res.code == 200) {
  101. this.tableData = res.data.list
  102. this.Total = res.data.count
  103. }
  104. })
  105. },
  106. // 弹窗表单添加
  107. handleAdd() {
  108. let flag = this.$refs['childRules'].validateForm();
  109. if (flag) {
  110. if (this.operationType == 'add') {
  111. this.confirmLoading = true
  112. var params = {
  113. ...this.ruleForm
  114. }
  115. addCompany(params).then(res => {
  116. if (res.code == 200) {
  117. this.$message({
  118. message: '操作成功',
  119. type: 'success'
  120. });
  121. this.getList()
  122. }
  123. this.staffDialogVisible = false
  124. this.confirmLoading = false
  125. }).catch(() => {
  126. this.confirmLoading = false
  127. })
  128. } else if (this.operationType == 'edit') {
  129. this.confirmLoading = true
  130. var params = {
  131. ...this.ruleForm
  132. }
  133. putCompany(params).then(res => {
  134. if (res.code == 200) {
  135. this.$message({
  136. message: '操作成功',
  137. type: 'success'
  138. });
  139. this.getList()
  140. }
  141. this.staffDialogVisible = false
  142. this.confirmLoading = false
  143. }).catch(() => {
  144. this.confirmLoading = false
  145. })
  146. }
  147. } else {
  148. this.$message.error('表单信息不完整,请继续填写完整');
  149. }
  150. },
  151. buttonData(row, type) {
  152. this.operationType = type
  153. if (type == 'edit') {
  154. this.staffTitle = '编辑'
  155. this.staffDialogVisible = true
  156. setTimeout(() => {
  157. this.$nextTick(() => {
  158. this.ruleForm = JSON.parse(JSON.stringify(row))
  159. })
  160. })
  161. } else if (type == 'del') {
  162. this.deleteUser(row.id)
  163. }
  164. },
  165. openModel(type) {
  166. this.staffTitle = '添加'
  167. this.staffDialogVisible = true
  168. this.operationType = type
  169. },
  170. // 删除公司
  171. deleteUser(id) {
  172. this.$confirm('此操作将永久删除该公司, 是否继续?', '提示', {
  173. confirmButtonText: '确定',
  174. cancelButtonText: '取消',
  175. type: 'warning'
  176. }).then(() => {
  177. delCompany({
  178. id: id,
  179. }).then(res => {
  180. if (res.code == 200) {
  181. this.$message({
  182. message: '操作成功',
  183. type: 'success'
  184. });
  185. this.getList()
  186. }
  187. })
  188. }).catch(() => {});
  189. },
  190. changeSize(val) {
  191. this.Pagination.PageSize = val
  192. this.getList()
  193. },
  194. changeCurrent(val) {
  195. this.Pagination.PageIndex = val
  196. this.getList()
  197. },
  198. // 清空表单
  199. closeDialog() {
  200. this.ruleForm = {}
  201. this.$refs.childRules.resetCheck();
  202. }
  203. }
  204. }
  205. </script>