settingsIndex.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="categorySet-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <div ref="headerBar">
  5. <a-page-header :ghost="false" :backIcon="false" class="header-bar">
  6. <!-- 自定义的二级文字标题 -->
  7. <template slot="subTitle">
  8. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  9. <span class="subTitle-word text-overflow" style="max-width:300px;margin-left:15px;">用户姓名:{{ infoObj.userName?infoObj.userName:'--' }}</span>
  10. </template>
  11. </a-page-header>
  12. </div>
  13. <a-card size="small" :bordered="false" class="categorySet-cont">
  14. <div>
  15. <a-tabs v-model="activeKeyVal" @change="handleTabs">
  16. <a-tab-pane key="1" tab="设置管辖区域" v-if="infoObj.allDealerFlag && infoObj.allDealerFlag!=1">
  17. <div class="areaSet-wrap">
  18. <div class="table-page-search-wrapper newTableSearchName" >
  19. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  20. <a-row :gutter="15">
  21. <a-col :md="6" :sm="24">
  22. <a-form-model-item label="所在区域/分区">
  23. <subarea id="chooseDealer-subarea" ref="subarea" @change="subareaChange"></subarea>
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :md="6" :sm="24">
  27. <a-form-item label="经销商名称">
  28. <a-input id="areaSet-dealerName" v-model.trim="queryParam.dealerName" allowClear placeholder="请输入经销商名称"/>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="areaSet-refresh">查询</a-button>
  33. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="areaSet-reset">重置</a-button>
  34. </a-col>
  35. </a-row>
  36. </a-form>
  37. <div class="areaSet-btnGroup" style="margin-bottom:10px;">
  38. <a-button type="primary" class="button-info" @click="openAreaModal">选择区域</a-button>
  39. <a-button type="primary" class="button-error" @click="openDealerModal">选择经销商</a-button>
  40. </div>
  41. </div>
  42. <a-spin :spinning="spinning" tip="Loading...">
  43. <!-- 列表 -->
  44. <s-table
  45. class="sTable fixPagination"
  46. ref="table"
  47. size="small"
  48. :rowKey="(record) => record.no"
  49. rowKeyName="no"
  50. :columns="columns"
  51. :data="loadData"
  52. :defaultLoadData="false"
  53. :style="{ height: tableHeight+70+'px' }"
  54. :scroll="{ y: tableHeight }"
  55. bordered>
  56. <!-- 操作 -->
  57. <template slot="action" slot-scope="text, record">
  58. <a-button
  59. size="small"
  60. type="link"
  61. class="button-error"
  62. @click="handleDel(record)"
  63. >
  64. 删除
  65. </a-button>
  66. </template>
  67. </s-table>
  68. </a-spin>
  69. </div>
  70. </a-tab-pane>
  71. <a-tab-pane key="2" tab="设置管辖品类" force-render v-if="infoObj.allProductFlag&&infoObj.allProductFlag!=1">
  72. <categorySet ref="setCategory" :bizUserSn="infoObj.bizUserSn"></categorySet>
  73. </a-tab-pane>
  74. <a-tab-pane key="3" tab="设置供应商" force-render v-if="infoObj.allSupplierFlag&&infoObj.allSupplierFlag!=1">
  75. <supplierSet ref="setSupplier" :bizUserSn="infoObj.bizUserSn"></supplierSet>
  76. </a-tab-pane>
  77. </a-tabs>
  78. </div>
  79. </a-card>
  80. <!-- 选择区域 -->
  81. <chooseAreaModal
  82. ref="partQuery"
  83. :showModal="openChooseArea"
  84. :chooseData="newChooseData"
  85. @ok="handleArea"
  86. @close="openChooseArea=false">
  87. </chooseAreaModal>
  88. <!-- 选择经销商 -->
  89. <a-drawer
  90. title="选择经销商"
  91. width="80%"
  92. :zIndex="100"
  93. :visible="openChooseDealer"
  94. :get-container="false"
  95. :wrap-style="{ position: 'absolute' }"
  96. @close="openChooseDealer = false">
  97. <div class="dealerModalCon">
  98. <chooseDealer ref="dealerChoose" @plAdd="handleAddDealer"></chooseDealer>
  99. </div>
  100. </a-drawer>
  101. </a-spin>
  102. </div>
  103. </template>
  104. <script>
  105. import { commonMixin } from '@/utils/mixin'
  106. import { STable } from '@/components'
  107. import categorySet from './categorySet'
  108. import supplierSet from './supplierSet'
  109. import chooseAreaModal from './chooseAreaModal'
  110. import chooseDealer from './chooseDealer.vue'
  111. import { queryDealerScopePage, bizuserScopeDelete, findById, queryAreaScope, queryDealerScope, saveAreaScope, saveDealerScope } from '@/api/bizuser'
  112. import subarea from '@/views/common/subarea.js'
  113. export default {
  114. name: 'SettingsIndex',
  115. mixins: [commonMixin],
  116. components: { STable, categorySet, chooseAreaModal, chooseDealer, subarea, supplierSet },
  117. data () {
  118. return {
  119. openChooseArea: false,
  120. openChooseDealer: false,
  121. spinning: false,
  122. tableHeight: 0,
  123. queryParam: {
  124. hasDetail: 0,
  125. bizType: undefined,
  126. bizSn: undefined,
  127. dealerName: ''
  128. },
  129. activeKeyVal: '1',
  130. infoObj: {},
  131. newChooseData: {// 区域分区回显
  132. checked: [],
  133. halfChecked: []
  134. },
  135. columns: [
  136. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  137. { title: '添加时间', dataIndex: 'createDate', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  138. { title: '区域', dataIndex: 'subareaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  139. { title: '分区', dataIndex: 'subareaAreaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  140. { title: '经销商', dataIndex: 'dealerName', width: '16%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  141. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  142. ],
  143. disabled: false, // 查询、重置按钮是否可操作
  144. chooseInfo: [], // 回显选中经销商信息
  145. loadData: parameter => {
  146. this.disabled = true
  147. this.spinning = true
  148. this.queryParam.userSn = this.$route.query.sn
  149. return queryDealerScopePage(Object.assign(parameter, this.queryParam)).then(res => {
  150. let data
  151. if (res.status == 200) {
  152. data = res.data
  153. const no = (data.pageNo - 1) * data.pageSize
  154. this.total = data.count || 0
  155. for (var i = 0; i < data.list.length; i++) {
  156. data.list[i].no = no + i + 1
  157. }
  158. }
  159. this.disabled = false
  160. this.spinning = false
  161. return data
  162. })
  163. }
  164. }
  165. },
  166. methods: {
  167. // 获取用户基本信息
  168. getBaseInfo () {
  169. const _this = this
  170. findById({ id: _this.$route.query.id }).then(res => {
  171. if (res.status == 200) {
  172. _this.infoObj = res.data
  173. if (res.data.allDealerFlag != 1) {
  174. _this.activeKeyVal = '1'
  175. _this.$nextTick(() => {
  176. _this.$refs.table.refresh()
  177. })
  178. } else if (res.data.allDealerFlag == 1 && res.data.allProductFlag != 1) {
  179. _this.activeKeyVal = '2'
  180. _this.$nextTick(() => {
  181. this.$refs.setCategory.pageInit()
  182. })
  183. } else if (res.data.allDealerFlag == 1 && res.data.allProductFlag == 1 && res.data.allSupplierFlag != 1) {
  184. _this.activeKeyVal = '3'
  185. _this.$nextTick(() => {
  186. this.$refs.setSupplier.pageInit()
  187. })
  188. }
  189. }
  190. })
  191. },
  192. // 选择区域>分区
  193. handleArea (con) {
  194. const chooseData = con.checked
  195. const newData = []
  196. chooseData.forEach(item => {
  197. const obj = {}
  198. obj.userSn = this.$route.query.sn
  199. obj.bizUserSn = this.infoObj.bizUserSn
  200. if (item.indexOf('_') != -1) { // 分区获取数据带_ 区域不带下划线
  201. obj.bizType = 'subarea_area'
  202. obj.bizSn = item.replace('_', '')
  203. newData.push(obj)
  204. } else {
  205. obj.bizType = 'subarea'
  206. obj.bizSn = item
  207. newData.push(obj)
  208. }
  209. })
  210. this.saveChooseArea(newData)
  211. },
  212. saveChooseArea (list) {
  213. const _this = this
  214. const newAjaxData = {}
  215. newAjaxData.userSn = _this.$route.query.sn
  216. newAjaxData.bizUserScopeList = list
  217. saveAreaScope(newAjaxData).then(res => {
  218. if (res.status == 200) {
  219. _this.openChooseArea = false
  220. _this.resetSearchForm()
  221. }
  222. })
  223. },
  224. handleTabs (val) {
  225. this.activeKeyVal = val
  226. if (val == 2) {
  227. this.$refs.setCategory.pageInit()
  228. } else if (val == 3) {
  229. this.$refs.setSupplier.pageInit()
  230. }
  231. },
  232. // 所在区域分区查询
  233. subareaChange (val) {
  234. if (val.length == 1) {
  235. this.queryParam.bizSn = val[0]
  236. this.queryParam.bizType = 'subarea'
  237. } else if (val.length == 2) {
  238. this.queryParam.bizSn = val[1]
  239. this.queryParam.bizType = 'subarea_area'
  240. } else {
  241. this.queryParam.bizSn = undefined
  242. this.queryParam.bizType = undefined
  243. }
  244. },
  245. resetSearchForm () {
  246. this.queryParam = {
  247. bizSn: undefined,
  248. bizType: undefined,
  249. dealerName: '',
  250. hasDetail: 0
  251. }
  252. if (this.infoObj && this.infoObj.allDealerFlag != 1) {
  253. this.$refs.subarea.clearData()
  254. this.$refs.table.refresh(true)
  255. }
  256. },
  257. // 选择区域
  258. async openAreaModal () {
  259. const _this = this
  260. const checkedArr = []
  261. const dataList = await queryAreaScope({ userSn: this.$route.query.sn, hasDetail: 0 })
  262. if (dataList.data && dataList.data.length > 0) {
  263. dataList.data.forEach(item => {
  264. if (item.bizType == 'subarea_area') {
  265. item.bizSn = item.bizSn + '_'
  266. }
  267. checkedArr.push(item.bizSn)
  268. })
  269. const newCheckedArr = [...new Set(checkedArr)]
  270. console.log('end choose:', newCheckedArr)
  271. this.newChooseData.checked = newCheckedArr
  272. } else {
  273. this.newChooseData.checked = []
  274. }
  275. this.$refs.partQuery.pageInit()
  276. _this.$nextTick(() => {
  277. _this.openChooseArea = true
  278. })
  279. },
  280. // 打开经销商弹窗
  281. async openDealerModal (params = {}) {
  282. const _this = this
  283. const arr = []
  284. const dataList = await queryDealerScope({ userSn: this.$route.query.sn, hasDetail: 0 })
  285. if (dataList.data && dataList.data.length > 0) {
  286. dataList.data.forEach(con => {
  287. arr.push(con.bizSn)
  288. })
  289. _this.chooseInfo = [...new Set(arr)]
  290. } else {
  291. _this.chooseInfo = []
  292. }
  293. const dataInfo = {
  294. list: _this.chooseInfo,
  295. sn: _this.$route.query.sn
  296. }
  297. _this.openChooseDealer = true
  298. if (_this.openChooseDealer) {
  299. _this.$refs.dealerChoose.pageInit(dataInfo)
  300. }
  301. },
  302. // 经销商
  303. handleAddDealer (list) { const newData = [] list.forEach(con => { const obj = {}
  304. obj.userSn = this.$route.query.sn
  305. obj.bizUserSn = this.infoObj.bizUserSn obj.bizType = 'dealer' obj.bizSn = con newData.push(obj) }) this.saveChooseDealer(newData) },
  306. // 保存所选区域或经销商
  307. saveChooseDealer (list) {
  308. const _this = this
  309. const ajaxData = {}
  310. ajaxData.userSn = _this.$route.query.sn
  311. ajaxData.bizUserScopeList = list
  312. saveDealerScope(ajaxData).then(res => {
  313. if (res.status == 200) {
  314. _this.openChooseDealer = false
  315. _this.resetSearchForm()
  316. }
  317. })
  318. },
  319. // 删除
  320. handleDel (row) {
  321. const _this = this
  322. this.$confirm({
  323. title: '提示',
  324. content: '确认要删除吗?删除后当前用户权限以最新权限为准',
  325. centered: true,
  326. onOk () {
  327. bizuserScopeDelete({ id: row.bizUserScopeSn }).then(res => {
  328. if (res.status == 200) {
  329. _this.resetSearchForm()
  330. }
  331. })
  332. }
  333. })
  334. },
  335. // 返回
  336. handleBack () {
  337. this.$router.push({ name: 'businessOwnerSettings' })
  338. },
  339. pageInit () {
  340. const _this = this
  341. this.$nextTick(() => { // 页面渲染完成后的回调
  342. _this.setTableH()
  343. })
  344. _this.getBaseInfo()
  345. },
  346. setTableH () {
  347. const headHeight = this.$refs.headerBar.offsetHeight
  348. this.tableHeight = window.innerHeight - headHeight - 340
  349. }
  350. },
  351. watch: {
  352. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  353. this.setTableH()
  354. }
  355. },
  356. activated () {
  357. this.pageInit()
  358. },
  359. beforeRouteEnter (to, from, next) {
  360. next(vm => {})
  361. }
  362. }
  363. </script>
  364. <style lang="less" scoped>
  365. .categorySet-wrap{
  366. .table-operator{
  367. text-align:right;
  368. }
  369. }
  370. </style>