chooseDealer.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <a-spin :spinning="spinning" tip="Loading...">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper newTableSearchName">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="8" :sm="24">
  8. <a-form-item label="经销商名称/别名">
  9. <a-input id="chooseDealer-nameLike" v-model.trim="queryParam.nameLike" allowClear placeholder="请输入经销商名称/别名"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="8" :sm="24">
  13. <a-form-item label="商户类型">
  14. <v-select code="DEALER_TYPE" id="chooseDealer-dealerType" v-model="queryParam.dealerType" allowClear placeholder="请选择商户类型"></v-select>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="8" :sm="24">
  18. <a-form-model-item label="商户级别" prop="dealerLevel">
  19. <v-select code="DEALER_LEVEL" id="ucModal-dealerLevel" v-model="queryParam.dealerLevel" allowClear placeholder="请选择商户级别"></v-select>
  20. </a-form-model-item>
  21. </a-col>
  22. <a-col :md="8" :sm="24" v-if="pageType!='viewDealers'">
  23. <a-form-item label="所在区域/分区">
  24. <subarea id="chooseDealer-subarea" ref="subarea" @change="subareaChange"></subarea>
  25. </a-form-item>
  26. </a-col>
  27. <div v-else>
  28. <a-col :md="8" :sm="24">
  29. <a-form-item label="审核状态">
  30. <v-select code="AUDIT_STATE" id="viewDealers-auditState" v-model="queryParam.auditState" allowClear placeholder="请选择审核状态"></v-select>
  31. </a-form-item>
  32. </a-col>
  33. <a-col :md="8" :sm="24">
  34. <a-form-model-item label="地区">
  35. <AreaList id="viewDealers-areaList" changeOnSelect ref="areaList" @change="areaChange" defValKey="id"></AreaList>
  36. </a-form-model-item>
  37. </a-col>
  38. </div>
  39. <a-col :md="pageType!='viewDealers'?8:6" :sm="24" style="margin-bottom: 10px;">
  40. <a-button type="primary" @click="searchForm(true)" :disabled="disabled" id="chooseDealer-refresh">查询</a-button>
  41. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseDealer-reset">重置</a-button>
  42. </a-col>
  43. </a-row>
  44. </a-form>
  45. <!-- 列表 -->
  46. <div style="margin-bottom: 10px">
  47. <a-button type="primary" ghost :loading="loading" @click="handleBatchAudit">批量添加</a-button>
  48. <span style="margin-left: 5px">
  49. <template v-if="selectCount"> {{ `已选 ${selectCount} 项` }} </template>
  50. </span>
  51. </div>
  52. </div>
  53. <s-table
  54. class="sTable"
  55. ref="table"
  56. size="small"
  57. :rowKey="(record) => record.dealerSn"
  58. rowKeyName="dealerSn"
  59. :row-selection="{ columnWidth: 40, getCheckboxProps: record => ({ props: { disabled: !!record.subareaAreaSn } }) }"
  60. @rowSelection="rowSelectionFun"
  61. :columns="columns"
  62. :data="loadData"
  63. :style="{ height: tableHeight+84.5+'px' }"
  64. :scroll="{ y: pageType=='viewDealers'?tableHeight:tableHeight+80 }"
  65. :defaultLoadData="false"
  66. bordered>
  67. <template slot="areas" slot-scope="text, record">
  68. <span v-if="record.subareaNameSet">{{ record.subareaNameSet[0] }}</span>
  69. <span v-else>--</span>
  70. </template>
  71. <template slot="action" slot-scope="text, record">
  72. <a-button
  73. size="small"
  74. type="link"
  75. class="button-error"
  76. @click="handleAdd(record)"
  77. v-if="record.subareaAreaSn != parentData.subareaAreaSn"
  78. id="marketingDivisionSetNew-del-btn">添加</a-button>
  79. <span style="color:#666" v-else>已添加</span>
  80. </template>
  81. </s-table>
  82. </a-spin>
  83. </template>
  84. <script>
  85. import { commonMixin } from '@/utils/mixin'
  86. import { STable, VSelect } from '@/components'
  87. import AreaList from '@/views/common/areaList.js'
  88. import { queryDealerPageList } from '@/api/dealer'
  89. import subarea from '@/views/common/subarea.js'
  90. import Array from 'core-js/library/fn/array'
  91. export default {
  92. name: 'ChooseDealer',
  93. mixins: [commonMixin],
  94. components: { STable, VSelect, subarea, AreaList },
  95. props: {
  96. pageType: {
  97. type: String,
  98. default: ''
  99. },
  100. parentData: {
  101. type: Object,
  102. default: function () {
  103. return null
  104. }
  105. }
  106. // chooseInfo: {
  107. // type: Array,
  108. // defatut: () => {
  109. // return []
  110. // }
  111. // }
  112. },
  113. data () {
  114. return {
  115. spinning: false,
  116. queryParam: { // 查询条件
  117. nameLike: '',
  118. dealerType: null,
  119. dealerLevel: null,
  120. auditState: undefined,
  121. provinceSn: undefined,
  122. citySn: undefined,
  123. districtSn: undefined,
  124. subareaSn: undefined,
  125. subareaAreaSn: undefined
  126. },
  127. chooseInfo: [],
  128. tableHeight: 0,
  129. disabled: false, // 查询、重置按钮是否可操作
  130. loading: false, // 批量添加loading
  131. // 加载数据方法 必须为 Promise 对象
  132. loadData: parameter => {
  133. this.spinning = true
  134. return queryDealerPageList(Object.assign(parameter, this.queryParam)).then(res => {
  135. let data
  136. const _this = this
  137. if (res.status == 200) {
  138. data = res.data
  139. const no = 0
  140. if (!_this.pageType && _this.chooseInfo && _this.chooseInfo.length > 0) {
  141. for (var i = 0; i < data.list.length; i++) {
  142. data.list[i].no = no + i + 1
  143. _this.chooseInfo.forEach(con => {
  144. if (data.list[i].dealerSn == con) {
  145. data.list[i].subareaAreaSn = con
  146. }
  147. })
  148. }
  149. }
  150. }
  151. this.spinning = false
  152. return data
  153. })
  154. },
  155. rowSelectionInfo: null
  156. }
  157. },
  158. computed: {
  159. columns () {
  160. const _this = this
  161. const arr = [
  162. { title: '经销商名称', dataIndex: 'dealerName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  163. { title: '商户别名', dataIndex: 'dealerAlias', align: 'left', width: '30%', customRender: function (text) { return text || '--' } },
  164. { title: '商户类型', dataIndex: 'dealerTypeDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  165. { title: '商户级别', dataIndex: 'dealerLevelDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } }
  166. ]
  167. if (_this.pageType == 'viewDealers') {
  168. arr.splice(4, 0, { title: '审核状态', dataIndex: 'auditStateDictValue', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  169. arr.splice(5, 0, { title: '当前所属区域', scopedSlots: { customRender: 'areas' }, width: '30%', align: 'center' })
  170. arr.splice(6, 0, { title: '操作', scopedSlots: { customRender: 'action' }, width: '20%', align: 'center' })
  171. } else {
  172. arr.splice(4, 0, { title: '所在区域', dataIndex: 'subareaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true })
  173. arr.splice(5, 0, { title: '所在分区', dataIndex: 'subareaAreaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true })
  174. }
  175. return arr
  176. },
  177. selectCount () {
  178. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  179. }
  180. },
  181. methods: {
  182. // 表格选中项
  183. rowSelectionFun (obj) {
  184. this.rowSelectionInfo = obj || null
  185. },
  186. areaChange (val) {
  187. this.queryParam.provinceSn = val[0] ? val[0] : ''
  188. this.queryParam.citySn = val[1] ? val[1] : ''
  189. this.queryParam.districtSn = val[2] ? val[2] : ''
  190. },
  191. searchForm (flag) {
  192. this.$refs.table.refresh(flag)
  193. this.$refs.table.clearSelected()
  194. this.spinning = false
  195. },
  196. subareaChange (val) {
  197. this.queryParam.subareaSn = val[0] ? val[0] : undefined
  198. this.queryParam.subareaAreaSn = val[1] ? val[1] : undefined
  199. },
  200. // 重置
  201. resetSearchForm () {
  202. this.queryParam = {
  203. nameLike: '',
  204. dealerType: null,
  205. dealerLevel: null,
  206. auditState: undefined,
  207. provinceSn: undefined,
  208. citySn: undefined,
  209. districtSn: undefined,
  210. subareaSn: undefined,
  211. subareaAreaSn: undefined
  212. }
  213. this.$refs.subarea.clearData()
  214. this.$refs.table.refresh(true)
  215. this.$refs.table.clearSelected()
  216. },
  217. clearTable () {
  218. this.rowSelectionInfo = null
  219. this.$refs.table.clearTable()
  220. },
  221. // 批量添加
  222. handleBatchAudit () {
  223. const _this = this
  224. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  225. _this.$message.warning('请在列表勾选后再进行批量操作!')
  226. return
  227. }
  228. const dealerSnList = _this.rowSelectionInfo.selectedRowKeys
  229. this.spinning = false
  230. this.$emit('plAdd', dealerSnList)
  231. },
  232. handleAdd (row) {
  233. if (row.subareaNameSet && row.subareaNameSet.length) {
  234. const _this = this
  235. this.$confirm({
  236. title: '提示',
  237. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  238. centered: true,
  239. onOk () {
  240. _this.spinning = true
  241. _this.$emit('add', row)
  242. }
  243. })
  244. } else {
  245. this.spinning = true
  246. this.$emit('add', row)
  247. }
  248. },
  249. pageInit (data) {
  250. const _this = this
  251. this.$nextTick(() => { // 页面渲染完成后的回调
  252. _this.setTableH()
  253. })
  254. this.chooseInfo = data
  255. this.resetSearchForm()
  256. },
  257. setTableH () {
  258. const tableSearchH = this.$refs.tableSearch.offsetHeight
  259. this.tableHeight = window.innerHeight - tableSearchH - 245
  260. }
  261. },
  262. mounted () {
  263. this.pageInit()
  264. },
  265. watch: {
  266. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  267. this.setTableH()
  268. }
  269. }
  270. }
  271. </script>