index.vue 5.4 KB

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