chooseDealer.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. <v-select code="DEALER_TYPE" id="chooseDealer-dealerType" v-model="queryParam.dealerType" allowClear placeholder="请选择商户类型"></v-select>
  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. export default {
  91. name: 'ChooseDealer',
  92. mixins: [commonMixin],
  93. components: { STable, VSelect, subarea, AreaList },
  94. props: {
  95. pageType: {
  96. type: String,
  97. default: ''
  98. },
  99. parentData: {
  100. type: Object,
  101. default: function () {
  102. return null
  103. }
  104. }
  105. },
  106. data () {
  107. return {
  108. spinning: false,
  109. queryParam: { // 查询条件
  110. nameLike: '',
  111. dealerType: null,
  112. dealerLevel: null,
  113. auditState: undefined,
  114. provinceSn: undefined,
  115. citySn: undefined,
  116. districtSn: undefined,
  117. subareaArea: {
  118. subareaSn: undefined,
  119. subareaAreaSn: undefined
  120. }
  121. },
  122. tableHeight: 0,
  123. disabled: false, // 查询、重置按钮是否可操作
  124. loading: false, // 批量添加loading
  125. // 加载数据方法 必须为 Promise 对象
  126. loadData: parameter => {
  127. this.spinning = true
  128. return queryDealerPageList(Object.assign(parameter, this.queryParam)).then(res => {
  129. let data
  130. const _this = this
  131. if (res.status == 200) {
  132. data = res.data
  133. const no = 0
  134. for (var i = 0; i < data.list.length; i++) {
  135. data.list[i].no = no + i + 1
  136. }
  137. }
  138. this.spinning = false
  139. return data
  140. })
  141. },
  142. rowSelectionInfo: null
  143. }
  144. },
  145. computed: {
  146. columns () {
  147. const _this = this
  148. const arr = [
  149. { title: '经销商名称', dataIndex: 'dealerName', width: '30%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  150. { title: '商户别名', dataIndex: 'dealerAlias', align: 'left', width: '30%', customRender: function (text) { return text || '--' }, ellipsis: true },
  151. { title: '商户类型', dataIndex: 'dealerTypeDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  152. { title: '商户级别', dataIndex: 'dealerLevelDictValue', width: '15%', align: 'center', customRender: function (text) { return text || '--' } }
  153. ]
  154. if (_this.pageType == 'viewDealers') {
  155. arr.splice(4, 0, { title: '审核状态', dataIndex: 'auditStateDictValue', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  156. arr.splice(5, 0, { title: '当前所属区域', scopedSlots: { customRender: 'areas' }, width: '30%', align: 'center' })
  157. arr.splice(6, 0, { title: '操作', scopedSlots: { customRender: 'action' }, width: '20%', align: 'center' })
  158. } else {
  159. arr.splice(4, 0, { title: '所在区域', dataIndex: 'subareaArea.subareaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  160. arr.splice(5, 0, { title: '所在分区', dataIndex: 'subareaArea.subareaAreaName', width: '20%', align: 'center', customRender: function (text) { return text || '--' } })
  161. }
  162. return arr
  163. },
  164. selectCount () {
  165. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  166. }
  167. },
  168. methods: {
  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 (flag) {
  179. this.$refs.table.refresh(flag)
  180. this.$refs.table.clearSelected()
  181. this.spinning = false
  182. },
  183. subareaChange (val) {
  184. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : undefined
  185. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : undefined
  186. },
  187. // 重置
  188. resetSearchForm () {
  189. this.queryParam = {
  190. nameLike: '',
  191. dealerType: null,
  192. dealerLevel: null,
  193. auditState: undefined,
  194. provinceSn: undefined,
  195. citySn: undefined,
  196. districtSn: undefined,
  197. subareaArea: {
  198. subareaSn: undefined,
  199. subareaAreaSn: undefined
  200. }
  201. }
  202. if (this.pageType != 'viewDealers') {
  203. this.$refs.subarea.clearData()
  204. } else {
  205. this.$refs.areaList.clearData()
  206. }
  207. this.$refs.table.refresh(true)
  208. this.$refs.table.clearSelected()
  209. },
  210. clearTable () {
  211. this.rowSelectionInfo = null
  212. this.$refs.table.clearTable()
  213. },
  214. // 批量添加
  215. handleBatchAudit () {
  216. const _this = this
  217. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  218. _this.$message.warning('请在列表勾选后再进行批量操作!')
  219. return
  220. }
  221. const dealerSnList = _this.rowSelectionInfo.selectedRowKeys
  222. this.spinning = false
  223. this.$emit('plAdd', dealerSnList)
  224. },
  225. handleAdd (row) {
  226. if (row.subareaArea) {
  227. const _this = this
  228. this.$confirm({
  229. title: '提示',
  230. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  231. centered: true,
  232. onOk () {
  233. _this.spinning = true
  234. _this.$emit('add', row)
  235. }
  236. })
  237. } else {
  238. this.spinning = true
  239. this.$emit('add', row)
  240. }
  241. },
  242. pageInit () {
  243. const _this = this
  244. this.$nextTick(() => { // 页面渲染完成后的回调
  245. _this.setTableH()
  246. })
  247. this.resetSearchForm()
  248. },
  249. setTableH () {
  250. const tableSearchH = this.$refs.tableSearch.offsetHeight
  251. this.tableHeight = window.innerHeight - tableSearchH - 285
  252. }
  253. },
  254. mounted () {
  255. this.pageInit()
  256. },
  257. activated () {
  258. this.pageInit()
  259. },
  260. watch: {
  261. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  262. this.setTableH()
  263. }
  264. }
  265. }
  266. </script>