chooseDealer.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. <dealerType id="chooseDealer-dealerType" v-model="dealerType" @change="getDealerType" allowClear></dealerType>
  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: pageType=='viewDealers'?!!record.subareaAreaSn: !!record.chooseId} }) }"
  60. @rowSelection="rowSelectionFun"
  61. :columns="columns"
  62. :data="loadData"
  63. :style="{ height:pageType=='viewDealers'? tableHeight+84.5+'px':tableHeight-15+'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.subareaArea">{{ record.subareaArea.subareaName }}>{{ record.subareaArea.subareaAreaName }}</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 dealerType from '@/views/common/dealerType.js'
  91. export default {
  92. name: 'ChooseDealer',
  93. mixins: [commonMixin],
  94. components: { STable, VSelect, subarea, AreaList, dealerType },
  95. props: {
  96. pageType: {
  97. type: String,
  98. default: ''
  99. },
  100. parentData: {
  101. type: Object,
  102. default: function () {
  103. return null
  104. }
  105. }
  106. },
  107. data () {
  108. return {
  109. spinning: false,
  110. dealerType: [],
  111. queryParam: { // 查询条件
  112. nameLike: '',
  113. dealerType1: undefined, // 商户类型
  114. dealerType2: undefined, // 商户类型
  115. dealerLevel: null,
  116. auditState: undefined,
  117. provinceSn: undefined,
  118. citySn: undefined,
  119. districtSn: undefined,
  120. subareaArea: {
  121. subareaSn: undefined,
  122. subareaAreaSn: undefined
  123. }
  124. },
  125. tableHeight: 0,
  126. disabled: false, // 查询、重置按钮是否可操作
  127. loading: false, // 批量添加loading
  128. // 加载数据方法 必须为 Promise 对象
  129. loadData: parameter => {
  130. this.spinning = true
  131. return queryDealerPageList(Object.assign(parameter, this.queryParam)).then(res => {
  132. let data
  133. const _this = this
  134. if (res.status == 200) {
  135. data = res.data
  136. const no = 0
  137. for (var i = 0; i < data.list.length; i++) {
  138. data.list[i].no = no + i + 1
  139. if (data.list[i].dealerTypeName1) {
  140. data.list[i].dealerTypeName = data.list[i].dealerTypeName1 + '>' + data.list[i].dealerTypeName2
  141. }
  142. }
  143. }
  144. this.spinning = false
  145. return data
  146. })
  147. },
  148. rowSelectionInfo: null
  149. }
  150. },
  151. computed: {
  152. columns () {
  153. const _this = this
  154. const arr = [
  155. { title: '经销商名称', dataIndex: 'dealerName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  156. { title: '商户别名', dataIndex: 'dealerAlias', align: 'left', width: '30%', customRender: function (text) { return text || '--' }, ellipsis: true },
  157. { title: '商户类型', dataIndex: 'dealerTypeName', width: '25%', align: 'center', customRender: function (text) { return text || '--' } },
  158. { title: '商户级别', dataIndex: 'dealerLevelDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } }
  159. ]
  160. if (_this.pageType == 'viewDealers') {
  161. arr.splice(4, 0, { title: '审核状态', dataIndex: 'auditStateDictValue', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  162. arr.splice(5, 0, { title: '当前所属区域', scopedSlots: { customRender: 'areas' }, width: '20%', align: 'center' })
  163. arr.splice(6, 0, { title: '操作', scopedSlots: { customRender: 'action' }, width: '20%', align: 'center' })
  164. } else {
  165. arr.splice(4, 0, { title: '所在区域', dataIndex: 'subareaArea.subareaName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } })
  166. arr.splice(5, 0, { title: '所在分区', dataIndex: 'subareaArea.subareaAreaName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } })
  167. }
  168. return arr
  169. },
  170. selectCount () {
  171. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  172. }
  173. },
  174. methods: {
  175. // 表格选中项
  176. rowSelectionFun (obj) {
  177. this.rowSelectionInfo = obj || null
  178. },
  179. getDealerType (v, o) {
  180. this.queryParam.dealerType1 = v[0]
  181. this.queryParam.dealerType2 = v[1]
  182. },
  183. areaChange (val) {
  184. this.queryParam.provinceSn = val[0] ? val[0] : ''
  185. this.queryParam.citySn = val[1] ? val[1] : ''
  186. this.queryParam.districtSn = val[2] ? val[2] : ''
  187. },
  188. searchForm (flag) {
  189. this.$refs.table.refresh(flag)
  190. this.$refs.table.clearSelected()
  191. this.spinning = false
  192. },
  193. subareaChange (val) {
  194. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : undefined
  195. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : undefined
  196. },
  197. // 重置
  198. resetSearchForm () {
  199. this.dealerType = []
  200. this.queryParam = {
  201. nameLike: '',
  202. dealerType1: undefined, // 商户类型
  203. dealerType2: undefined, // 商户类型
  204. dealerLevel: null,
  205. auditState: undefined,
  206. provinceSn: undefined,
  207. citySn: undefined,
  208. districtSn: undefined,
  209. subareaArea: {
  210. subareaSn: undefined,
  211. subareaAreaSn: undefined
  212. }
  213. }
  214. if (this.pageType != 'viewDealers') {
  215. this.$refs.subarea.clearData()
  216. } else {
  217. this.$refs.areaList.clearData()
  218. }
  219. this.$refs.table.refresh(true)
  220. this.$refs.table.clearSelected()
  221. },
  222. clearTable () {
  223. this.rowSelectionInfo = null
  224. this.$refs.table.clearTable()
  225. },
  226. // 批量添加
  227. handleBatchAudit () {
  228. const _this = this
  229. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  230. _this.$message.warning('请在列表勾选后再进行批量操作!')
  231. return
  232. }
  233. const dealerSnList = _this.rowSelectionInfo.selectedRowKeys
  234. this.spinning = false
  235. this.$emit('plAdd', dealerSnList)
  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 () {
  255. const _this = this
  256. this.$nextTick(() => { // 页面渲染完成后的回调
  257. _this.setTableH()
  258. })
  259. this.resetSearchForm()
  260. },
  261. setTableH () {
  262. const tableSearchH = this.$refs.tableSearch.offsetHeight
  263. this.tableHeight = window.innerHeight - tableSearchH - 285
  264. }
  265. },
  266. mounted () {
  267. this.pageInit()
  268. },
  269. activated () {
  270. this.pageInit()
  271. },
  272. watch: {
  273. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  274. this.setTableH()
  275. }
  276. }
  277. }
  278. </script>