settingsIndex.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 default-active-key="1" @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 '@/views/common/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. subareaArea: {
  122. subareaSn: undefined,
  123. subareaAreaSn: undefined
  124. },
  125. dealerName: ''
  126. },
  127. infoObj: {},
  128. newChooseData: {// 区域分区回显
  129. checked: [],
  130. halfChecked: []
  131. },
  132. columns: [
  133. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  134. { title: '添加时间', dataIndex: 'createDate', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  135. { title: '区域', dataIndex: 'subareaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  136. { title: '分区', dataIndex: 'subareaAreaName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  137. { title: '经销商', dataIndex: 'dealerName', width: '16%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  138. { title: '操作', scopedSlots: { customRender: 'action' }, width: '8%', align: 'center' }
  139. ],
  140. disabled: false, // 查询、重置按钮是否可操作
  141. chooseInfo: [], // 回显选中经销商信息
  142. loadData: parameter => {
  143. this.disabled = true
  144. this.spinning = true
  145. this.queryParam.userSn = this.$route.query.sn
  146. return bizuserScopeQueryPage(Object.assign(parameter, this.queryParam)).then(res => {
  147. let data
  148. if (res.status == 200) {
  149. data = res.data
  150. const no = (data.pageNo - 1) * data.pageSize
  151. this.total = data.count || 0
  152. for (var i = 0; i < data.list.length; i++) {
  153. data.list[i].no = no + i + 1
  154. }
  155. }
  156. this.disabled = false
  157. this.spinning = false
  158. return data
  159. })
  160. }
  161. }
  162. },
  163. methods: {
  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.$nextTick(() => {
  170. _this.$refs.table.refresh()
  171. })
  172. }
  173. })
  174. },
  175. // 选择区域>分区
  176. handleArea (con) {
  177. const chooseData = con.checked
  178. const newData = []
  179. chooseData.forEach(item => {
  180. const obj = {}
  181. obj.userSn = this.$route.query.sn
  182. obj.bizUserSn = this.infoObj.bizUserSn
  183. if (item.indexOf('_') != -1) { // 分区获取数据带_ 区域不带下划线
  184. obj.bizType = 'subarea_area'
  185. obj.bizSn = item.replace('_', '')
  186. newData.push(obj)
  187. } else {
  188. obj.bizType = 'subarea'
  189. obj.bizSn = item
  190. newData.push(obj)
  191. }
  192. })
  193. this.saveChooseArea(newData)
  194. },
  195. saveChooseArea (list) {
  196. const _this = this
  197. const newAjaxData = {}
  198. newAjaxData.userSn = _this.$route.query.sn
  199. newAjaxData.bizUserScopeList = list
  200. saveAreaScope(newAjaxData).then(res => {
  201. if (res.status == 200) {
  202. _this.openChooseArea = false
  203. _this.resetSearchForm()
  204. }
  205. })
  206. },
  207. handleTabs (val) {
  208. if (val == 2) {
  209. this.$refs.setCategory.pageInit()
  210. }
  211. },
  212. // 所在区域分区查询
  213. subareaChange (val) {
  214. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : undefined
  215. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : undefined
  216. },
  217. resetSearchForm () {
  218. this.queryParam = {
  219. subareaArea: {
  220. subareaSn: undefined,
  221. subareaAreaSn: undefined
  222. },
  223. dealerName: ''
  224. }
  225. if (this.infoObj && this.infoObj.allDealerFlag != 1) {
  226. this.$refs.subarea.clearData()
  227. this.$refs.table.refresh(true)
  228. }
  229. },
  230. // 选择区域
  231. async openAreaModal () {
  232. this.$refs.partQuery.pageInit()
  233. const _this = this
  234. const checkedArr = []
  235. const dataList = await queryAreaScope({ userSn: this.$route.query.sn })
  236. if (dataList.data && dataList.data.length > 0) {
  237. dataList.data.forEach(item => {
  238. if (item.bizType == 'subarea_area') {
  239. item.bizSn = item.bizSn + '_'
  240. }
  241. checkedArr.push(item.bizSn)
  242. })
  243. const newCheckedArr = [...new Set(checkedArr)]
  244. console.log('end choose:', newCheckedArr)
  245. this.newChooseData.checked = newCheckedArr
  246. }
  247. _this.$nextTick(() => {
  248. _this.openChooseArea = true
  249. })
  250. },
  251. // 打开经销商弹窗
  252. async openDealerModal (params = {}) {
  253. const _this = this
  254. const arr = []
  255. const dataList = await queryDealerScope({ userSn: this.$route.query.sn })
  256. if (dataList.data && dataList.data.length > 0) {
  257. dataList.data.forEach(con => {
  258. arr.push(con.bizSn)
  259. })
  260. _this.chooseInfo = [...new Set(arr)]
  261. }
  262. _this.openChooseDealer = true
  263. if (_this.openChooseDealer) {
  264. _this.$refs.dealerChoose.pageInit(_this.chooseInfo)
  265. }
  266. },
  267. // 经销商
  268. handleAddDealer (list) { const newData = [] list.forEach(con => { const obj = {}
  269. obj.userSn = this.$route.query.sn
  270. obj.bizUserSn = this.infoObj.bizUserSn obj.bizType = 'dealer' obj.bizSn = con newData.push(obj) }) this.saveChooseDealer(newData) },
  271. // 保存所选区域或经销商
  272. saveChooseDealer (list) {
  273. const _this = this
  274. const ajaxData = {}
  275. ajaxData.userSn = _this.$route.query.sn
  276. ajaxData.bizUserScopeList = list
  277. saveDealerScope(ajaxData).then(res => {
  278. if (res.status == 200) {
  279. _this.openChooseDealer = false
  280. _this.resetSearchForm()
  281. }
  282. })
  283. },
  284. // 删除
  285. handleDel (row) {
  286. const _this = this
  287. this.$confirm({
  288. title: '提示',
  289. content: '删除后不可恢复,确定要进行删除吗?',
  290. centered: true,
  291. onOk () {
  292. bizuserScopeDelete({ id: row.bizUserScopeSn }).then(res => {
  293. if (res.status == 200) {
  294. _this.resetSearchForm()
  295. }
  296. })
  297. }
  298. })
  299. },
  300. // 返回
  301. handleBack () {
  302. this.$router.push({ name: 'businessOwnerSettings' })
  303. },
  304. pageInit () {
  305. const _this = this
  306. this.$nextTick(() => { // 页面渲染完成后的回调
  307. _this.setTableH()
  308. })
  309. _this.getBaseInfo()
  310. },
  311. setTableH () {
  312. const headHeight = this.$refs.headerBar.offsetHeight
  313. this.tableHeight = window.innerHeight - headHeight - 230
  314. }
  315. },
  316. watch: {
  317. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  318. this.setTableH()
  319. }
  320. },
  321. mounted () {
  322. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  323. this.pageInit()
  324. }
  325. },
  326. activated () {
  327. // 如果是新页签打开,则重置当前页面
  328. if (this.$store.state.app.isNewTab) {
  329. this.pageInit()
  330. }
  331. // 仅刷新列表,不重置页面
  332. if (this.$store.state.app.updateList) {
  333. this.pageInit()
  334. }
  335. },
  336. beforeRouteEnter (to, from, next) {
  337. next(vm => {})
  338. }
  339. }
  340. </script>
  341. <style lang="less" scoped>
  342. .categorySet-wrap{
  343. .table-operator{
  344. text-align:right;
  345. }
  346. }
  347. </style>