settingsIndex.vue 13 KB

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