chooseDealer.vue 10 KB

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