chooseDealer.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. ></a-table>
  69. </a-spin>
  70. </template>
  71. <script>
  72. import { commonMixin } from '@/utils/mixin'
  73. import { STable, VSelect } from '@/components'
  74. import AreaList from '@/views/common/areaList.js'
  75. import { dealerQueryList, getDealerListInfo } from '@/api/dealer'
  76. import subarea from '@/views/common/subarea.js'
  77. export default {
  78. name: 'ChooseDealer',
  79. mixins: [commonMixin],
  80. components: { STable, VSelect, subarea, AreaList },
  81. props: {
  82. pageType: {
  83. type: String,
  84. default: ''
  85. },
  86. parentData: {
  87. type: Object,
  88. default: function () {
  89. return null
  90. }
  91. }
  92. },
  93. data () {
  94. return {
  95. spinning: false,
  96. queryParam: { // 查询条件
  97. nameLike: '',
  98. dealerType: null,
  99. dealerLevel: null,
  100. subareaArea: {
  101. subareaSn: undefined, // 区域
  102. subareaAreaSn: undefined // 分区
  103. },
  104. auditState: undefined,
  105. provinceSn: undefined,
  106. citySn: undefined,
  107. districtSn: undefined
  108. },
  109. pagination: {
  110. pageSize: 20,
  111. showSizeChanger: true
  112. },
  113. pageFlag: false,
  114. chooseInfo: [],
  115. selectedRowKeys: [],
  116. columns: [
  117. { title: '经销商名称', dataIndex: 'dealerName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  118. { title: '商户别名', dataIndex: 'dealerAlias', align: 'left', width: '30%', customRender: function (text) { return text || '--' }, ellipsis: true },
  119. { title: '商户类型', dataIndex: 'dealerTypeDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  120. { title: '商户级别', dataIndex: 'dealerLevelDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  121. { title: '所在区域', dataIndex: 'subareaArea.subareaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } },
  122. { title: '所在分区', dataIndex: 'subareaArea.subareaAreaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } }
  123. ],
  124. dealerList: [],
  125. tableHeight: 0,
  126. disabled: false, // 查询、重置按钮是否可操作
  127. loading: false // 批量添加loading
  128. }
  129. },
  130. computed: {
  131. selectCount () {
  132. return this.selectedRowKeys && this.selectedRowKeys.length
  133. }
  134. },
  135. methods: {
  136. onSelectChange (selectedRowKeys) {
  137. this.selectedRowKeys = selectedRowKeys
  138. },
  139. handlePage (pagination, filters, sorter) {
  140. const pager = { ...this.pagination }
  141. pager.current = pagination.current
  142. pager.pageSize = pagination.pageSize
  143. this.pagination = pager
  144. this.loadData({ pageNo: pagination.current, pageSize: pagination.pageSize })
  145. },
  146. loadData (pager) {
  147. this.spinning = true
  148. const params = { pageSize: 20, pageNo: 1, ...pager }
  149. dealerQueryList(Object.assign(params, this.queryParam)).then(res => {
  150. let data
  151. if (res.status == 200) {
  152. data = res.data
  153. const pagination = { ...this.pagination }
  154. pagination.total = data.count
  155. const no = 0
  156. for (var i = 0; i < data.list.length; i++) {
  157. data.list[i].no = no + i + 1
  158. }
  159. this.dealerList = data.list
  160. this.pagination = pagination
  161. if (this.chooseInfo && !this.pageFlag) {
  162. this.pageFlag = true
  163. this.selectedRowKeys = this.chooseInfo
  164. }
  165. }
  166. this.spinning = false
  167. })
  168. },
  169. // 表格选中项
  170. rowSelectionFun (obj) {
  171. this.rowSelectionInfo = obj || null
  172. },
  173. areaChange (val) {
  174. this.queryParam.provinceSn = val[0] ? val[0] : ''
  175. this.queryParam.citySn = val[1] ? val[1] : ''
  176. this.queryParam.districtSn = val[2] ? val[2] : ''
  177. },
  178. searchForm () {
  179. this.loadData()
  180. this.spinning = false
  181. },
  182. subareaChange (val) {
  183. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : undefined
  184. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : undefined
  185. },
  186. // 重置
  187. resetSearchForm () {
  188. this.queryParam = {
  189. nameLike: '',
  190. dealerType: null,
  191. dealerLevel: null,
  192. subareaArea: {
  193. subareaSn: undefined, // 区域
  194. subareaAreaSn: undefined // 分区
  195. },
  196. auditState: undefined,
  197. provinceSn: undefined,
  198. citySn: undefined,
  199. districtSn: undefined
  200. }
  201. if (this.pageType != 'viewDealers') {
  202. this.$refs.subarea.clearData()
  203. if (this.pageType == 'dealerPromotion') {
  204. this.$refs.areaList.clearData()
  205. }
  206. } else {
  207. this.$refs.areaList.clearData()
  208. }
  209. this.pagination = {
  210. pageSize: 20,
  211. showSizeChanger: true,
  212. current: 1
  213. }
  214. this.selectedRowKeys = []
  215. this.loadData()
  216. this.pageFlag = false
  217. },
  218. clearTable () {
  219. this.rowSelectionInfo = null
  220. this.$refs.table.clearTable()
  221. },
  222. // 批量添加
  223. async handleBatchAudit () {
  224. const _this = this
  225. if (_this.selectedRowKeys && _this.selectedRowKeys.length < 1) {
  226. _this.$message.warning('请在列表勾选后再进行批量操作!')
  227. return
  228. }
  229. const dealerInfoList = await getDealerListInfo({ dealerSnList: _this.selectedRowKeys })
  230. this.spinning = false
  231. this.$emit('plAdd', dealerInfoList.data)
  232. },
  233. handleAdd (row) {
  234. if (row.subareaArea) {
  235. const _this = this
  236. this.$confirm({
  237. title: '提示',
  238. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  239. centered: true,
  240. onOk () {
  241. _this.spinning = true
  242. _this.$emit('add', row)
  243. }
  244. })
  245. } else {
  246. this.spinning = true
  247. this.$emit('add', row)
  248. }
  249. },
  250. pageInit (data) {
  251. const _this = this
  252. this.$nextTick(() => { // 页面渲染完成后的回调
  253. _this.setTableH()
  254. })
  255. this.chooseInfo = data || []
  256. this.resetSearchForm()
  257. },
  258. setTableH () {
  259. const tableSearchH = this.$refs.tableSearch.offsetHeight
  260. this.tableHeight = window.innerHeight - tableSearchH - 285
  261. }
  262. },
  263. watch: {
  264. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  265. this.setTableH()
  266. }
  267. }
  268. }
  269. </script>