index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
  3. :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
  4. :operation="operation()" :exportList="exportList">
  5. <el-dialog title="" width="500px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog"
  6. :show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel">
  7. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  8. <zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
  9. :form-data="formData" :form-items="formItems">
  10. </zj-form-module>
  11. </zj-form-container>
  12. <div slot="footer" class="dialog-footer">
  13. <el-button size="mini" @click="formCancel">取 消</el-button>
  14. <el-button size="mini" @click="formConfirm" type="primary">确 定</el-button>
  15. </div>
  16. </el-dialog>
  17. </template-page>
  18. </template>
  19. <script>
  20. import TemplatePage from '@/components/template/template-page-1.vue'
  21. import import_mixin from '@/components/template/import_mixin.js'
  22. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  23. import { storageListPageV2, storagePageExport, addStorage, deleteStorage, editStorage, getStorageDetail } from "@/api/storage";
  24. import operation_mixin from '@/components/template/operation_mixin.js'
  25. export default {
  26. components: { TemplatePage },
  27. mixins: [import_mixin,operation_mixin],
  28. data() {
  29. return {
  30. // 表格属性
  31. tableAttributes: {
  32. // 启用勾选列
  33. selectColumn: false
  34. },
  35. // 表格事件
  36. tableEvents: {
  37. 'selection-change': this.selectionChange
  38. },
  39. // 勾选选中行
  40. recordSelected: [],
  41. /** 表单变量 */
  42. formDialogType: 0,
  43. formDialogTitles: ["新增", "编辑"],
  44. formDialog: false,
  45. formData: {
  46. storageName: '',
  47. storageMobile: '',
  48. storageAddress: '',
  49. },
  50. }
  51. },
  52. computed: {
  53. // 事件组合
  54. optionsEvensGroup() {
  55. return [
  56. [
  57. [
  58. this.optionsEvensAuth("add", {
  59. click: () => {
  60. this.addData
  61. }
  62. })
  63. ],
  64. ]
  65. ]
  66. },
  67. // 更多参数
  68. moreParameters() {
  69. return []
  70. },
  71. formItems() {
  72. return [{
  73. md: 24,
  74. isShow: true,
  75. name: 'el-input',
  76. attributes: { placeholder: '请输入' },
  77. formItemAttributes: {
  78. label: '仓储名称',
  79. prop: 'storageName',
  80. rules: [...required]
  81. }
  82. }, {
  83. md: 24,
  84. isShow: true,
  85. name: 'el-input',
  86. attributes: { placeholder: '请输入' },
  87. formItemAttributes: {
  88. label: '仓储电话',
  89. prop: 'storageMobile',
  90. rules: [...mobile]
  91. }
  92. }, {
  93. md: 24,
  94. isShow: true,
  95. name: 'el-input',
  96. attributes: { placeholder: '请输入' },
  97. formItemAttributes: {
  98. label: '仓储地址',
  99. prop: 'storageAddress',
  100. rules: []
  101. }
  102. }]
  103. }
  104. },
  105. methods: {
  106. // 列表请求函数
  107. getList: storageListPageV2,
  108. // 列表导出函数
  109. exportList: storagePageExport,
  110. // 表格列解析渲染数据更改
  111. columnParsing(item, defaultData) {
  112. return defaultData
  113. },
  114. // 监听勾选变化
  115. selectionChange(data) {
  116. this.recordSelected = data
  117. },
  118. // 表格操作列
  119. operation() {
  120. return this.operationBtn({
  121. edit: {
  122. btnType: 'text',
  123. click: ({ row, index, column }) => {
  124. getStorageDetail({ id: row.storageId }).then(res => {
  125. Object.assign(this.formData, res.data)
  126. this.formDialogType = 1
  127. this.openForm()
  128. })
  129. }
  130. },
  131. del: {
  132. btnType: 'text',
  133. prompt: '确定删除吗?',
  134. click: ({ row, index, column }) => {
  135. deleteStorage({ storageId: row.storageId }).then(() => {
  136. this.$message({ type: 'success', message: '删除成功!' })
  137. this.$refs.pageRef.refreshList()
  138. })
  139. }
  140. }
  141. })
  142. },
  143. addData() {
  144. this.formDialogType = 0
  145. this.openForm()
  146. },
  147. openForm() {
  148. this.formDialog = true;
  149. },
  150. formCancel() {
  151. this.$refs.formRef.$refs.inlineForm.clearValidate()
  152. this.$data.formData = this.$options.data().formData
  153. this.formDialog = false
  154. },
  155. formConfirm() {
  156. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  157. if (valid) {
  158. ([addStorage, editStorage][this.formDialogType])(this.formData).then(res => {
  159. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  160. this.formCancel()
  161. this.$refs.pageRef.refreshList()
  162. })
  163. }
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped></style>