list.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper newTableSearchName">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-model-item label="人员类型">
  10. <subarea id="businessOwnerSettings-subareaSn" ref="subarea" @change="subareaChange"></subarea>
  11. </a-form-model-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="人员姓名">
  15. <a-input id="businessOwnerSettings-dealerName" v-model.trim="queryParam.dealerName" allowClear placeholder="请输入人员姓名"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="24" :sm="24" style="margin-top: 10px;text-align:center;">
  19. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="businessOwnerSettings-refresh">查询</a-button>
  20. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="businessOwnerSettings-reset">重置</a-button>
  21. </a-col>
  22. </a-row>
  23. </a-form>
  24. </div>
  25. </a-card>
  26. <a-card size="small" :bordered="false" class="dealerZoneSearch-wrap">
  27. <a-spin :spinning="spinning" tip="Loading...">
  28. <div class="table-operator">
  29. <a-button id="businessOwnerSettings-add" type="primary" class="button-error" @click="handleAdd">+新增</a-button>
  30. </div>
  31. <!-- 列表 -->
  32. <s-table
  33. class="sTable fixPagination"
  34. ref="table"
  35. :style="{ height: tableHeight+84.5+'px' }"
  36. size="small"
  37. :rowKey="(record) => record.id"
  38. :columns="columns"
  39. :showPagination="false"
  40. :data="loadData"
  41. :scroll="{ y: tableHeight }"
  42. :defaultLoadData="false"
  43. bordered>
  44. <!-- 操作 -->
  45. <template slot="action" slot-scope="text, record">
  46. <a-button size="small" type="link" class="button-warning" @click="handleSetCategory(record)">设置管辖范围</a-button>
  47. <a-button size="small" type="link" class="button-info" @click="handleEdit(record)">编辑</a-button>
  48. <a-button size="small" type="link" class="button-error" @click="handleDelete(record)">删除</a-button>
  49. </template>
  50. </s-table>
  51. </a-spin>
  52. </a-card>
  53. <!-- 新增 -->
  54. <addModal :openModal="openAddModal" @close="openAddModal = false"></addModal>
  55. </div>
  56. </template>
  57. <script>
  58. import { commonMixin } from '@/utils/mixin'
  59. import { STable, VSelect } from '@/components'
  60. import { subareaQueryIncludeAreaAll, subareaDeleteBySn } from '@/api/subarea'
  61. import subarea from '@/views/common/subarea.js'
  62. import addModal from './addModal'
  63. export default {
  64. name: 'BusinessOwnerSettings',
  65. mixins: [commonMixin],
  66. components: { STable, VSelect, subarea, addModal },
  67. data () {
  68. return {
  69. spinning: false,
  70. disabled: false, // 查询、重置按钮是否可操作
  71. tableHeight: 0,
  72. queryParam: {
  73. subareaSn: undefined,
  74. subareaAreaSn: undefined,
  75. dealerName: ''
  76. },
  77. columns: [
  78. { title: '创建时间', dataIndex: 'subareaName', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  79. { title: '人员姓名', dataIndex: 'subareaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  80. { title: '人员类型', dataIndex: 'subareaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  81. { title: '管辖经销商', dataIndex: 'subareaName', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  82. { title: '管辖品类', dataIndex: 'subareaName', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  83. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  84. ],
  85. // 加载数据方法 必须为 Promise 对象
  86. loadData: parameter => {
  87. this.disabled = true
  88. this.spinning = true
  89. return subareaQueryIncludeAreaAll(Object.assign(parameter,this.queryParam)).then(res => {
  90. let data
  91. if (res.status == 200) {
  92. data = res.data
  93. const no = 0
  94. for (var i = 0; i < data.length; i++) {
  95. data[i].no = no + i + 1
  96. }
  97. this.disabled = false
  98. }
  99. this.spinning = false
  100. return data
  101. })
  102. },
  103. openAddModal: false, // 编辑 弹框
  104. nowData: null,
  105. itemId: null // 当前产品id
  106. }
  107. },
  108. methods: {
  109. handleSetCategory (row) {
  110. this.$router.push({ name: 'categorySet', query: { sn: row.sn } })
  111. },
  112. // 新增
  113. handleAdd () {
  114. this.openAddModal = true
  115. },
  116. subareaChange(val){
  117. this.queryParam.subareaSn = val[0] ? val[0] : undefined
  118. this.queryParam.subareaAreaSn = val[1] ? val[1] : undefined
  119. },
  120. // 重置
  121. resetSearchForm () {
  122. this.queryParam = {
  123. subareaSn: undefined,
  124. subareaAreaSn: undefined,
  125. dealerName: ''
  126. }
  127. this.$refs.subarea.clearData()
  128. this.$refs.table.refresh(true)
  129. },
  130. // 删除
  131. handleDelete (row) {
  132. const _this = this
  133. this.$confirm({
  134. title: '提示',
  135. content: '确定要删除吗?',
  136. centered: true,
  137. onOk () {
  138. _this.spinning = true
  139. subareaDeleteBySn({ sn: row.subareaSn }).then(res => {
  140. if (res.status == 200) {
  141. _this.$message.success(res.message)
  142. _this.$refs.table.refresh()
  143. _this.spinning = false
  144. } else {
  145. _this.spinning = false
  146. }
  147. })
  148. }
  149. })
  150. },
  151. // 编辑
  152. handleEdit (row) {
  153. this.itemId = row && row.subareaSn ? row.subareaSn : null
  154. this.nowData = row
  155. this.openModal = true
  156. },
  157. // 关闭弹框
  158. closeModal () {
  159. this.itemId = null
  160. this.nowData = null
  161. this.openModal = false
  162. },
  163. pageInit () {
  164. const _this = this
  165. this.$nextTick(() => { // 页面渲染完成后的回调
  166. _this.setTableH()
  167. })
  168. },
  169. setTableH () {
  170. const tableSearchH = this.$refs.tableSearch.offsetHeight
  171. this.tableHeight = window.innerHeight - tableSearchH - 275
  172. }
  173. },
  174. watch: {
  175. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  176. this.setTableH()
  177. }
  178. },
  179. mounted () {
  180. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  181. this.pageInit()
  182. this.resetSearchForm()
  183. }
  184. },
  185. activated () {
  186. // 如果是新页签打开,则重置当前页面
  187. if (this.$store.state.app.isNewTab) {
  188. this.pageInit()
  189. this.resetSearchForm()
  190. }
  191. // 仅刷新列表,不重置页面
  192. if (this.$store.state.app.updateList) {
  193. this.pageInit()
  194. this.$refs.table.refresh()
  195. }
  196. },
  197. beforeRouteEnter (to, from, next) {
  198. next(vm => {})
  199. }
  200. }
  201. </script>
  202. <style lang="less">
  203. .dealerZoneSearch-wrap{
  204. height: 100%;
  205. margin-top:6px;
  206. .table-operator{
  207. text-align:right;
  208. }
  209. }
  210. </style>