settingsIndex.vue 14 KB

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