list.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <a-card size="small" :bordered="false" class="marketingDivisionSetList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 操作按钮 -->
  5. <div class="table-operator">
  6. <a-button id="marketingDivisionSetList-add" type="primary" v-if="$hasPermissions('B_marketingDivisionSet_add')" class="button-error" @click="handleEdit()">新增</a-button>
  7. </div>
  8. <!-- 列表 -->
  9. <s-table
  10. class="sTable"
  11. ref="table"
  12. size="default"
  13. :rowKey="(record) => record.id"
  14. :columns="columns"
  15. :showPagination="false"
  16. :data="loadData"
  17. bordered>
  18. <!-- 市区 -->
  19. <template slot="cityArea" slot-scope="text, record">
  20. <div style="display: inline-block;margin-right: 15px;" v-for="item in record.subareaAreaList" :key="item.id">
  21. {{ item.areaName }}
  22. <span v-if="item.citySubareaAreaList">(</span>
  23. <span style="color: #999;margin:0 3px;" v-for="area in item.citySubareaAreaList" :key="area.id">
  24. {{ area.areaName }}
  25. </span>
  26. <span v-if="item.citySubareaAreaList">)</span>
  27. </div>
  28. </template>
  29. <!-- 操作 -->
  30. <template slot="action" slot-scope="text, record">
  31. <a-button
  32. size="small"
  33. type="link"
  34. v-if="$hasPermissions('B_marketingDivisionSet_edit')"
  35. class="button-info"
  36. @click="handleEdit(record)"
  37. id="marketingDivisionSetList-edit-btn">编辑</a-button>
  38. <a-button
  39. size="small"
  40. type="link"
  41. v-if="$hasPermissions('B_marketingDivisionSet_del')"
  42. class="button-error"
  43. @click="handleDel(record)"
  44. id="marketingDivisionSetList-del-btn">删除</a-button>
  45. <span v-if="!$hasPermissions('B_marketingDivisionSet_edit') && !$hasPermissions('B_marketingDivisionSet_del')">--</span>
  46. </template>
  47. </s-table>
  48. </a-spin>
  49. <!-- 编辑分区 -->
  50. <marketing-division-set-edit-modal :nowData="nowData" :openModal="openModal" :itemId="itemId" @ok="$refs.table.refresh()" @close="closeModal" />
  51. </a-card>
  52. </template>
  53. <script>
  54. import { STable, VSelect } from '@/components'
  55. import marketingDivisionSetEditModal from './editModal.vue'
  56. import { subareaQueryIncludeAreaAll, subareaDeleteBySn } from '@/api/subarea'
  57. export default {
  58. components: { STable, VSelect, marketingDivisionSetEditModal },
  59. data () {
  60. return {
  61. spinning: false,
  62. disabled: false, // 查询、重置按钮是否可操作
  63. columns: [
  64. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  65. { title: '分区名', dataIndex: 'subareaName', width: 200, align: 'center' },
  66. { title: '省份/市', scopedSlots: { customRender: 'cityArea' }, align: 'left' },
  67. { title: '操作', scopedSlots: { customRender: 'action' }, width: 150, align: 'center' }
  68. ],
  69. // 加载数据方法 必须为 Promise 对象
  70. loadData: parameter => {
  71. this.disabled = true
  72. return subareaQueryIncludeAreaAll(parameter).then(res => {
  73. const data = res.data
  74. const no = 0
  75. for (var i = 0; i < data.length; i++) {
  76. data[i].no = no + i + 1
  77. }
  78. this.disabled = false
  79. return data
  80. })
  81. },
  82. openModal: false, // 编辑 弹框
  83. nowData: null,
  84. itemId: null // 当前产品id
  85. }
  86. },
  87. methods: {
  88. // 重置
  89. resetSearchForm () {
  90. this.$refs.table.refresh(true)
  91. },
  92. // 删除
  93. handleDel (row) {
  94. const _this = this
  95. this.$confirm({
  96. title: '提示',
  97. content: '确认要删除吗?',
  98. centered: true,
  99. onOk () {
  100. _this.spinning = true
  101. subareaDeleteBySn({ sn: row.subareaSn }).then(res => {
  102. if (res.status == 200) {
  103. _this.$message.success(res.message)
  104. _this.$refs.table.refresh()
  105. _this.spinning = false
  106. } else {
  107. _this.spinning = false
  108. }
  109. })
  110. }
  111. })
  112. },
  113. // 编辑
  114. handleEdit (row) {
  115. this.itemId = row && row.subareaSn ? row.subareaSn : null
  116. this.nowData = row
  117. this.openModal = true
  118. },
  119. // 关闭弹框
  120. closeModal () {
  121. this.itemId = null
  122. this.nowData = null
  123. this.openModal = false
  124. }
  125. },
  126. beforeRouteEnter (to, from, next) {
  127. next(vm => {
  128. })
  129. }
  130. }
  131. </script>