chooseDealer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. <dealerType id="chooseDealer-dealerType" changeOnSelect v-model="dealerType" @change="getDealerType" allowClear></dealertype>
  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 id="chooseDealer-batchAdd" 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 subarea from '@/views/common/subarea.js'
  80. import dealerType from '@/views/common/dealerType.js'
  81. import { dealerQueryList, getDealerListInfo } from '@/api/dealer'
  82. export default {
  83. name: 'ChooseDealer',
  84. mixins: [commonMixin],
  85. components: { STable, VSelect, subarea, AreaList, dealerType },
  86. props: {
  87. pageType: { // 添加or编辑
  88. type: String,
  89. default: ''
  90. },
  91. itemSn: { // 单据sn
  92. type: String,
  93. default: ''
  94. }
  95. },
  96. data () {
  97. return {
  98. spinning: false,
  99. dealerType: [], // 商户类型默认值
  100. queryParam: { // 查询条件
  101. nameLike: '', // 商户名称
  102. dealerType1: undefined, // 商户类型1
  103. dealerType2: undefined, // 商户类型2
  104. dealerLevel: null, // 商户等级
  105. subareaArea: {
  106. subareaSn: undefined, // 区域
  107. subareaAreaSn: undefined // 分区
  108. },
  109. auditState: undefined, // 审核状态
  110. provinceSn: undefined, // 省
  111. citySn: undefined, // 市
  112. districtSn: undefined // 区
  113. },
  114. pagination: {
  115. pageSize: 20, // 每页数
  116. showSizeChanger: true, // 是否显示页码输入框
  117. pageSizeOptions: ['20', '50', '100', '200', '500'] // 可选页码
  118. },
  119. pageFlag: false, // 经销商加载完成是否
  120. chooseInfo: [], // 已选商户
  121. selectedRowKeys: [], // 已选商户key
  122. dealerList: [], // 商户列表
  123. tableHeight: 0, // 表格高度
  124. disabled: false, // 查询、重置按钮是否可操作
  125. loading: false // 批量添加loading
  126. }
  127. },
  128. computed: {
  129. // 已选商户数量
  130. selectCount () {
  131. return this.selectedRowKeys && this.selectedRowKeys.length
  132. },
  133. // 列
  134. columns () {
  135. const arr = [
  136. { title: '经销商名称', dataIndex: 'dealerName', width: '25%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  137. { title: '商户别名', dataIndex: 'dealerAlias', align: 'left', width: '25%', customRender: function (text) { return text || '--' }, ellipsis: true },
  138. { title: '商户类型', dataIndex: 'dealerTypeName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  139. { title: '商户级别', dataIndex: 'dealerLevelDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '所在区域', dataIndex: 'subareaArea.subareaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  141. { title: '所在分区', dataIndex: 'subareaArea.subareaAreaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } }
  142. ]
  143. // 如果时经销商促销活动
  144. if (this.pageType === 'dealerPromotion') {
  145. arr.unshift({ title: '地区', scopedSlots: { customRender: 'addressInfo' }, width: '30%', align: 'center', ellipsis: true })
  146. }
  147. return arr
  148. }
  149. },
  150. methods: {
  151. // 全选
  152. onSelectChange (selectedRowKeys) {
  153. this.selectedRowKeys = selectedRowKeys
  154. },
  155. // 表格页码变化
  156. handlePage (pagination, filters, sorter) {
  157. const pager = { ...this.pagination }
  158. pager.pageNo = pagination.pageSize != pager.pageSize ? 1 : pagination.current
  159. pager.pageSize = pagination.pageSize
  160. pager.current = pager.pageNo
  161. this.pagination = pager
  162. this.loadData()
  163. },
  164. // 查询列表
  165. loadData () {
  166. this.spinning = true
  167. const params = { pageSize: 20, pageNo: 1, ...this.pagination }
  168. this.queryParam.notDealerSn = this.itemSn ? this.itemSn : undefined
  169. dealerQueryList(Object.assign(params, this.queryParam)).then(res => {
  170. let data
  171. if (res.status == 200) {
  172. data = res.data
  173. const pagination = { ...this.pagination }
  174. pagination.total = data.count
  175. const no = 0
  176. for (var i = 0; i < data.list.length; i++) {
  177. data.list[i].no = no + i + 1
  178. if (data.list[i].dealerTypeName1) {
  179. data.list[i].dealerTypeName = data.list[i].dealerTypeName1 + '>' + data.list[i].dealerTypeName2
  180. }
  181. }
  182. this.dealerList = data.list
  183. this.pagination = pagination
  184. // 是否已选
  185. if (this.chooseInfo.length > 0 && !this.pageFlag) {
  186. this.pageFlag = true
  187. this.selectedRowKeys = this.chooseInfo
  188. }
  189. }
  190. this.spinning = false
  191. })
  192. },
  193. // 表格选中项
  194. rowSelectionFun (obj) {
  195. this.rowSelectionInfo = obj || null
  196. },
  197. // 地区选择
  198. areaChange (val) {
  199. this.queryParam.provinceSn = val[0] ? val[0] : ''
  200. this.queryParam.citySn = val[1] ? val[1] : ''
  201. this.queryParam.districtSn = val[2] ? val[2] : ''
  202. },
  203. // 查询
  204. searchForm () {
  205. this.loadData()
  206. this.spinning = false
  207. },
  208. // 分区选择
  209. subareaChange (val) {
  210. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : undefined
  211. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : undefined
  212. },
  213. // 商户类型选项
  214. getDealerType (v, o) {
  215. this.queryParam.dealerType1 = v[0]
  216. this.queryParam.dealerType2 = v[1]
  217. },
  218. // 重置列表
  219. resetSearchForm () {
  220. this.dealerType = []
  221. this.queryParam = {
  222. nameLike: '',
  223. dealerType1: undefined, // 商户类型
  224. dealerType2: undefined, // 商户类型
  225. dealerLevel: null,
  226. subareaArea: {
  227. subareaSn: undefined, // 区域
  228. subareaAreaSn: undefined // 分区
  229. },
  230. auditState: undefined,
  231. provinceSn: undefined,
  232. citySn: undefined,
  233. districtSn: undefined
  234. }
  235. if (this.pageType != 'viewDealers') {
  236. this.$refs.subarea.clearData()
  237. if (this.pageType == 'dealerPromotion') {
  238. this.$refs.areaList.clearData()
  239. }
  240. } else {
  241. this.$refs.areaList.clearData()
  242. }
  243. this.pagination.pageNo = 1
  244. this.pagination.current = 1
  245. this.loadData()
  246. this.pageFlag = false
  247. },
  248. // 批量添加
  249. async handleBatchAudit () {
  250. const _this = this
  251. if (_this.selectedRowKeys && _this.selectedRowKeys.length < 1) {
  252. _this.$message.warning('请在列表勾选后再进行批量操作!')
  253. return
  254. }
  255. const dealerInfoList = await getDealerListInfo({ dealerSnList: _this.selectedRowKeys })
  256. this.spinning = false
  257. this.$emit('plAdd', dealerInfoList.data)
  258. },
  259. // 绑定关系
  260. handleAdd (row) {
  261. if (row.subareaArea) {
  262. const _this = this
  263. this.$confirm({
  264. title: '提示',
  265. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  266. centered: true,
  267. onOk () {
  268. _this.spinning = true
  269. _this.$emit('add', row)
  270. }
  271. })
  272. } else {
  273. this.spinning = true
  274. this.$emit('add', row)
  275. }
  276. },
  277. // 页面初始化
  278. pageInit (data) {
  279. const _this = this
  280. this.$nextTick(() => { // 页面渲染完成后的回调
  281. _this.setTableH()
  282. })
  283. this.selectedRowKeys = []
  284. this.chooseInfo = data || []
  285. this.resetSearchForm()
  286. },
  287. // 设置表格高度
  288. setTableH () {
  289. const tableSearchH = this.$refs.tableSearch.offsetHeight
  290. this.tableHeight = window.innerHeight - tableSearchH - 285
  291. }
  292. },
  293. watch: {
  294. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  295. this.setTableH()
  296. }
  297. }
  298. }
  299. </script>