chooseDealer.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. console.log(this.pagination)
  161. const params = { pageSize: 20, pageNo: 1, ...this.pagination }
  162. dealerQueryList(Object.assign(params, this.queryParam)).then(res => {
  163. let data
  164. if (res.status == 200) {
  165. data = res.data
  166. const pagination = { ...this.pagination }
  167. pagination.total = data.count
  168. const no = 0
  169. for (var i = 0; i < data.list.length; i++) {
  170. data.list[i].no = no + i + 1
  171. }
  172. this.dealerList = data.list
  173. this.pagination = pagination
  174. if (this.chooseInfo.length > 0 && !this.pageFlag) {
  175. this.pageFlag = true
  176. this.selectedRowKeys = this.chooseInfo
  177. }
  178. }
  179. this.spinning = false
  180. })
  181. },
  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 () {
  192. this.loadData()
  193. this.spinning = false
  194. },
  195. subareaChange (val) {
  196. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : undefined
  197. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : undefined
  198. },
  199. // 重置
  200. resetSearchForm () {
  201. this.queryParam = {
  202. nameLike: '',
  203. dealerType: null,
  204. dealerLevel: null,
  205. subareaArea: {
  206. subareaSn: undefined, // 区域
  207. subareaAreaSn: undefined // 分区
  208. },
  209. auditState: undefined,
  210. provinceSn: undefined,
  211. citySn: undefined,
  212. districtSn: undefined
  213. }
  214. if (this.pageType != 'viewDealers') {
  215. this.$refs.subarea.clearData()
  216. if (this.pageType == 'dealerPromotion') {
  217. this.$refs.areaList.clearData()
  218. }
  219. } else {
  220. this.$refs.areaList.clearData()
  221. }
  222. this.pagination.pageNo = 1
  223. this.pagination.current = 1
  224. this.loadData()
  225. this.pageFlag = false
  226. },
  227. // 批量添加
  228. async handleBatchAudit () {
  229. const _this = this
  230. if (_this.selectedRowKeys && _this.selectedRowKeys.length < 1) {
  231. _this.$message.warning('请在列表勾选后再进行批量操作!')
  232. return
  233. }
  234. const dealerInfoList = await getDealerListInfo({ dealerSnList: _this.selectedRowKeys })
  235. this.spinning = false
  236. this.$emit('plAdd', dealerInfoList.data)
  237. },
  238. handleAdd (row) {
  239. if (row.subareaArea) {
  240. const _this = this
  241. this.$confirm({
  242. title: '提示',
  243. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  244. centered: true,
  245. onOk () {
  246. _this.spinning = true
  247. _this.$emit('add', row)
  248. }
  249. })
  250. } else {
  251. this.spinning = true
  252. this.$emit('add', row)
  253. }
  254. },
  255. pageInit (data) {
  256. const _this = this
  257. this.$nextTick(() => { // 页面渲染完成后的回调
  258. _this.setTableH()
  259. })
  260. this.selectedRowKeys = []
  261. this.chooseInfo = data || []
  262. this.resetSearchForm()
  263. },
  264. setTableH () {
  265. const tableSearchH = this.$refs.tableSearch.offsetHeight
  266. this.tableHeight = window.innerHeight - tableSearchH - 285
  267. }
  268. },
  269. watch: {
  270. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  271. this.setTableH()
  272. }
  273. }
  274. }
  275. </script>