chooseDealer.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.dealer.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" changeOnSelect v-model="dealerType" @change="getDealerType" allowClear></dealertype>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="8" :sm="24">
  18. <a-form-item label="商户级别" prop="dealerLevel">
  19. <v-select code="DEALER_LEVEL" id="chooseDealer-dealerLevel" v-model="queryParam.dealer.dealerLevel" allowClear placeholder="请选择商户级别"></v-select>
  20. </a-form-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="chooseDealer-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-item label="地区">
  35. <AreaList id="chooseDealer-areaList" changeOnSelect ref="areaList" @change="areaChange" defValKey="id"></AreaList>
  36. </a-form-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" id="chooseDealer-add" 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. <!-- 列表 -->
  54. <s-table
  55. class="sTable"
  56. ref="table"
  57. size="small"
  58. :rowKey="(record) => record.dealerSn"
  59. rowKeyName="dealerSn"
  60. :row-selection="{ columnWidth: 40, getCheckboxProps: record => ({ props: { disabled: pageType=='viewDealers'?!!record.subareaAreaSn: !!record.chooseId} }) }"
  61. @rowSelection="rowSelectionFun"
  62. :columns="columns"
  63. :data="loadData"
  64. :style="{ height:pageType=='viewDealers'? tableHeight+84.5+'px':tableHeight-15+'px' }"
  65. :scroll="{ y: pageType=='viewDealers'?tableHeight:tableHeight+80 }"
  66. :defaultLoadData="false"
  67. bordered>
  68. <template slot="areas" slot-scope="text, record">
  69. <span v-if="record.subareaArea">{{ record.subareaArea.subareaName }}>{{ record.subareaArea.subareaAreaName }}</span>
  70. <span v-else>--</span>
  71. </template>
  72. <template slot="action" slot-scope="text, record">
  73. <a-button
  74. size="small"
  75. type="link"
  76. class="button-error"
  77. @click="handleAdd(record)"
  78. v-if="record.subareaAreaSn != parentData.subareaAreaSn"
  79. :id="'chooseDealer-add-btn'+record.dealerSn">添加</a-button>
  80. <span style="color:#666" v-else>已添加</span>
  81. </template>
  82. </s-table>
  83. </a-spin>
  84. </template>
  85. <script>
  86. import { commonMixin } from '@/utils/mixin'
  87. // 组件
  88. import { STable, VSelect } from '@/components'
  89. import AreaList from '@/views/common/areaList.js'
  90. import subarea from '@/views/common/subarea.js'
  91. import dealerType from '@/views/common/dealerType.js'
  92. // 接口
  93. import { bizuserScopeQueryDealer } from '@/api/bizuser'
  94. export default {
  95. name: 'ChooseDealer',
  96. mixins: [commonMixin],
  97. components: { STable, VSelect, subarea, AreaList, dealerType },
  98. props: {
  99. pageType: {
  100. type: String,
  101. default: ''
  102. },
  103. parentData: {
  104. type: Object,
  105. default: function () {
  106. return null
  107. }
  108. }
  109. },
  110. data () {
  111. return {
  112. spinning: false,
  113. tableHeight: 0, // 表格高度
  114. disabled: false, // 查询、重置按钮是否可操作
  115. loading: false, // 批量添加loading
  116. dealerType: [], // 商户类型
  117. // 查询条件
  118. queryParam: {
  119. dealer: {
  120. nameLike: '', // 经销商名称/别名
  121. dealerType1: undefined, // 商户类型
  122. dealerType2: undefined, // 商户类型
  123. dealerLevel: null
  124. },
  125. auditState: undefined, // 审核状态
  126. provinceSn: undefined, // 省sn
  127. citySn: undefined, // 市sn
  128. districtSn: undefined, // 区sn
  129. subareaSn: undefined, // 区域
  130. subareaAreaSn: undefined// 分区
  131. },
  132. userSn: '', // 用户sn
  133. pageFlag: false, // 是否显示选择框
  134. chooseInfo: [], // 选中数据
  135. // 加载数据方法 必须为 Promise 对象
  136. loadData: parameter => {
  137. this.spinning = true
  138. this.queryParam.userSn = this.userSn
  139. // 获取列表数据 有分页
  140. return bizuserScopeQueryDealer(Object.assign(parameter, this.queryParam)).then(res => {
  141. let data
  142. const _this = this
  143. if (res.status == 200) {
  144. data = res.data
  145. // 计算列表序号
  146. const no = 0
  147. const chooseData = []
  148. for (var i = 0; i < data.list.length; i++) {
  149. data.list[i].no = no + i + 1
  150. data.list[i].dealerSn = data.list[i].dealer.dealerSn
  151. if (data.list[i].dealer.dealerTypeName1) {
  152. data.list[i].dealerTypeName = data.list[i].dealer.dealerTypeName1 + '>' + data.list[i].dealer.dealerTypeName2
  153. }
  154. if (!_this.pageType && _this.chooseInfo && _this.chooseInfo.length > 0) {
  155. // 回显选中数据
  156. const flag = _this.chooseInfo.includes(data.list[i].dealer.dealerSn)
  157. if (flag) {
  158. chooseData.push(data.list[i])
  159. }
  160. }
  161. }
  162. if (!this.pageFlag) {
  163. this.pageFlag = true
  164. _this.$refs.table.setTableSelected(_this.chooseInfo, chooseData) // 设置表格选中项
  165. }
  166. }
  167. this.spinning = false
  168. return data
  169. })
  170. },
  171. rowSelectionInfo: null// 选中数据
  172. }
  173. },
  174. computed: {
  175. columns () {
  176. const _this = this
  177. const arr = [
  178. { title: '经销商名称', dataIndex: 'dealer.dealerName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  179. { title: '商户别名', dataIndex: 'dealer.dealerAlias', align: 'left', width: '30%', customRender: function (text) { return text || '--' }, ellipsis: true },
  180. { title: '商户类型', dataIndex: 'dealerTypeName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  181. { title: '商户级别', dataIndex: 'dealer.dealerLevelDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } }
  182. ]
  183. if (_this.pageType == 'viewDealers') {
  184. arr.splice(4, 0, { title: '审核状态', dataIndex: 'auditStateDictValue', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  185. arr.splice(5, 0, { title: '当前所属区域', scopedSlots: { customRender: 'areas' }, width: '30%', align: 'center' })
  186. arr.splice(6, 0, { title: '操作', scopedSlots: { customRender: 'action' }, width: '20%', align: 'center' })
  187. } else {
  188. arr.splice(4, 0, { title: '所在区域', dataIndex: 'subareaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  189. arr.splice(5, 0, { title: '所在分区', dataIndex: 'subareaAreaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  190. }
  191. return arr
  192. },
  193. // 计算选中数据条数
  194. selectCount () {
  195. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  196. }
  197. },
  198. methods: {
  199. // 表格选中项
  200. rowSelectionFun (obj) {
  201. this.rowSelectionInfo = obj || null
  202. },
  203. // 商户类型 change
  204. getDealerType (v, o) {
  205. this.queryParam.dealer.dealerType1 = v[0]
  206. this.queryParam.dealer.dealerType2 = v[1]
  207. },
  208. // 地区 change
  209. areaChange (val) {
  210. this.queryParam.provinceSn = val[0] ? val[0] : ''
  211. this.queryParam.citySn = val[1] ? val[1] : ''
  212. this.queryParam.districtSn = val[2] ? val[2] : ''
  213. },
  214. // 查询
  215. searchForm (flag) {
  216. this.$refs.table.refresh(flag)
  217. this.spinning = false
  218. },
  219. // 区域分区
  220. subareaChange (val) {
  221. this.queryParam.subareaSn = val[0] ? val[0] : undefined
  222. this.queryParam.subareaAreaSn = val[1] ? val[1] : undefined
  223. },
  224. // 重置
  225. resetSearchForm () {
  226. this.dealerType = []
  227. this.queryParam = {
  228. dealer: {
  229. nameLike: '',
  230. dealerType1: undefined, // 商户类型
  231. dealerType2: undefined, // 商户类型
  232. dealerLevel: null// 商户级别
  233. },
  234. auditState: undefined,
  235. provinceSn: undefined,
  236. citySn: undefined,
  237. districtSn: undefined,
  238. subareaSn: undefined,
  239. subareaAreaSn: undefined
  240. }
  241. if (this.pageType != 'viewDealers') {
  242. this.$refs.subarea.clearData()
  243. } else {
  244. this.$refs.areaList.clearData()
  245. }
  246. this.$refs.table.clearSelected()
  247. this.$refs.table.refresh(true)
  248. this.pageFlag = false
  249. },
  250. // 清除表格内容
  251. clearTable () {
  252. this.rowSelectionInfo = null
  253. this.$refs.table.clearTable()
  254. },
  255. // 批量添加
  256. handleBatchAudit () {
  257. const _this = this
  258. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  259. _this.$message.warning('请在列表勾选后再进行批量操作!')
  260. return
  261. }
  262. const dealerSnList = _this.rowSelectionInfo.selectedRowKeys
  263. this.spinning = false
  264. this.$emit('plAdd', dealerSnList)
  265. },
  266. // 添加
  267. handleAdd (row) {
  268. if (row.subareaArea) {
  269. const _this = this
  270. this.$confirm({
  271. title: '提示',
  272. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  273. centered: true,
  274. onOk () {
  275. _this.spinning = true
  276. _this.$emit('add', row)
  277. }
  278. })
  279. } else {
  280. this.spinning = true
  281. this.$emit('add', row)
  282. }
  283. },
  284. // 初始化
  285. pageInit (data) {
  286. const _this = this
  287. this.$nextTick(() => { // 页面渲染完成后的回调
  288. _this.setTableH()
  289. })
  290. this.chooseInfo = data.list ? data.list : []
  291. this.userSn = data.sn
  292. this.resetSearchForm()
  293. },
  294. // 计算表格数据
  295. setTableH () {
  296. const tableSearchH = this.$refs.tableSearch.offsetHeight
  297. this.tableHeight = window.innerHeight - tableSearchH - 285
  298. }
  299. },
  300. watch: {
  301. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  302. this.setTableH()
  303. }
  304. }
  305. }
  306. </script>