categorySet.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="categorySet-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-card size="small" :bordered="false" class="categorySet-cont">
  5. <!-- 操作按钮 -->
  6. <div class="table-operator" ref="categorySetAddBtn">
  7. <a-button type="primary" id="categorySet-add" @click="addCategory" :disabled="disabled">新增管辖品类</a-button>
  8. </div>
  9. <s-table
  10. class="sTable fixPagination"
  11. ref="table"
  12. :style="{ height: tableHeight+70+'px' }"
  13. size="small"
  14. :rowKey="(record) => record.bizUserScopeSn"
  15. rowKeyName="bizUserScopeSn"
  16. :columns="columns"
  17. :data="loadData"
  18. :scroll="{ y: tableHeight }"
  19. :defaultLoadData="false"
  20. bordered>
  21. <!-- 产品分类 -->
  22. <template slot="classify" slot-scope="text,record,index">
  23. <div style="max-height:64px;overflow-y:scroll;">
  24. <a-row v-if="record.productTypeList && record.productTypeList.length>0">
  25. <a-col :span="20">
  26. <a-tag
  27. :id="'categorySet-chooseType'+record.bizUserScopeSn"
  28. closable
  29. @close.prevent="delLabel(record.bizUserScopeSn,con,'typeList')"
  30. v-for="(con,i) in record.productTypeList"
  31. :key="i">
  32. {{ con.dataName }}
  33. </a-tag>
  34. </a-col>
  35. <a-col :span="4" style="text-align:right;">
  36. <a-tag style="background: #fff; borderStyle: dashed;" :id="'categorySet-chooseType-btn'+record.bizUserScopeSn" @click="addClassifyTag(index, record)" color="blue">
  37. <a-icon type="plus" /> 选择
  38. </a-tag>
  39. </a-col>
  40. </a-row>
  41. <a-row v-else>
  42. <a-col :span="24">
  43. <a-tag style="background: #fff; borderStyle: dashed;" :id="'categorySet-chooseType-btn1'+record.bizUserScopeSn" @click="addClassifyTag(index, record)" color="blue">
  44. <a-icon type="plus" /> 选择
  45. </a-tag>
  46. </a-col>
  47. </a-row>
  48. </div>
  49. </template>
  50. <!-- 产品品牌 -->
  51. <template slot="brand" slot-scope="text,record,index">
  52. <div style="max-height:64px;overflow-y:scroll;">
  53. <a-row v-if="record.productBrandList && record.productBrandList.length>0">
  54. <a-col :span="20">
  55. <a-tag
  56. :id="'categorySet-chooseBrand'+record.bizUserScopeSn"
  57. closable
  58. @close.prevent="delLabel(record.bizUserScopeSn,item,'brandList')"
  59. v-for="(item,j) in record.productBrandList"
  60. :key="j">
  61. {{ item.dataName }}
  62. </a-tag>
  63. </a-col>
  64. <a-col :span="4" style="text-align:right;">
  65. <a-tag style="background: #fff; borderStyle: dashed;" :id="'categorySet-chooseBrand-btn'+record.bizUserScopeSn" @click="addBrandTag(index, record)" color="blue">
  66. <a-icon type="plus" /> 选择
  67. </a-tag>
  68. </a-col>
  69. </a-row>
  70. <a-row v-else>
  71. <a-col :span="24">
  72. <a-tag style="background: #fff; borderStyle: dashed;" :id="'categorySet-chooseBrand-btn1'+record.bizUserScopeSn" @click="addBrandTag(index, record)" color="blue">
  73. <a-icon type="plus" /> 选择
  74. </a-tag>
  75. </a-col>
  76. </a-row>
  77. </div>
  78. </template>
  79. <span slot="action" slot-scope="text,record">
  80. <a-button
  81. size="small"
  82. type="link"
  83. class="button-error"
  84. :id="'categorySet-delete-btn'+record.bizUserScopeSn"
  85. @click="handleDel(record)"
  86. >
  87. 删除
  88. </a-button>
  89. </span>
  90. </s-table>
  91. </a-card>
  92. </a-spin>
  93. <!-- 选择产品品牌 -->
  94. <chooseBrandModal :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
  95. <!-- 选择产品分类 -->
  96. <chooseTypeModal :openModal="openTypeModal" :chooseData="chooseType" @close="openTypeModal=false" @ok="handleTypeOk" />
  97. </div>
  98. </template>
  99. <script>
  100. import { commonMixin } from '@/utils/mixin'
  101. // 组件
  102. import { STable } from '@/components'
  103. import ChooseBrandModal from './chooseBrandModal.vue'
  104. import ChooseTypeModal from './chooseTypeModal.vue'
  105. // 接口
  106. import { getNewScopeSn, queryProductScopePage, saveProductBrandList, saveProductTypeList, bizuserScopeDelete, deleteProductBrand, deleteProductType } from '@/api/bizuser'
  107. export default {
  108. name: 'CategorySet',
  109. mixins: [commonMixin],
  110. components: { ChooseBrandModal, ChooseTypeModal, STable },
  111. props: {
  112. bizUserSn: {
  113. type: String,
  114. default: ''
  115. }
  116. },
  117. data () {
  118. return {
  119. spinning: false,
  120. tableHeight: 0, // 表格高度
  121. disabled: false, // 查询、重置按钮是否可操作
  122. columns: [
  123. { title: '分类', dataIndex: 'no', width: '42%', align: 'center', scopedSlots: { customRender: 'classify' } },
  124. { title: '品牌', dataIndex: 'name', width: '42%', align: 'center', scopedSlots: { customRender: 'brand' } },
  125. { title: '操作', scopedSlots: { customRender: 'action' }, width: '16%', align: 'center' }
  126. ],
  127. // 查询参数
  128. queryParam: {
  129. hasDetail: 1
  130. },
  131. dataSource: [], // 列表数据
  132. openModal: false, // 新增编辑产品品牌 弹框
  133. itemSn: '', // 当前sn
  134. nowData: null, // 当前记录数据
  135. openBrandModal: false, // 打开品牌弹窗
  136. openTypeModal: false, // 打开分类弹窗
  137. chooseBrand: [], // 选择品牌数据
  138. chooseType: [], // 选择分类数据
  139. chooseObj: null, // 选择品牌 内容
  140. // 加载数据方法 必须为 Promise 对象
  141. loadData: parameter => {
  142. this.disabled = true
  143. this.spinning = true
  144. this.queryParam.userSn = this.$route.query.sn
  145. this.queryParam.bizUserSn = this.bizUserSn
  146. // 获取列表数据 有分页
  147. return queryProductScopePage(Object.assign(parameter, this.queryParam)).then(res => {
  148. const data = res.data
  149. // 计算列表序号
  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. this.dataSource = data.list
  156. this.disabled = false
  157. this.spinning = false
  158. return data
  159. })
  160. }
  161. }
  162. },
  163. methods: {
  164. // 返回
  165. handleBack () {
  166. this.$router.push({ name: 'powerUserList' })
  167. },
  168. // 新增管辖品类
  169. addCategory () {
  170. const _this = this
  171. _this.spinning = true
  172. _this.disabled = true
  173. getNewScopeSn({}).then(res => {
  174. if (res.status == 200) {
  175. const newData = {
  176. bizUserScopeSn: res.data,
  177. productTypeList: [],
  178. productBrandList: []
  179. }
  180. _this.dataSource.unshift(newData)
  181. }
  182. _this.spinning = false
  183. _this.disabled = false
  184. })
  185. },
  186. // 删除分类、品牌标签
  187. delLabel (bigRow, row, type) {
  188. const _this = this
  189. const bigPos = _this.dataSource.findIndex(con => { return bigRow == con.bizUserScopeSn })
  190. if (type == 'typeList') {
  191. const typePos = _this.dataSource[bigPos].productTypeList.findIndex(item => { return item.id == row.id })
  192. deleteProductType({ id: _this.dataSource[bigPos].productTypeList[typePos].id }).then(res => {
  193. if (res.status == 200) {
  194. _this.dataSource[bigPos].productTypeList.splice(typePos, 1)
  195. }
  196. })
  197. } else {
  198. const brandPos = _this.dataSource[bigPos].productBrandList.findIndex(obj => { return obj.id == row.id })
  199. deleteProductBrand({ id: _this.dataSource[bigPos].productBrandList[brandPos].id }).then(res => {
  200. if (res.status == 200) {
  201. _this.dataSource[bigPos].productBrandList.splice(brandPos, 1)
  202. }
  203. })
  204. }
  205. },
  206. // 添加分类标签
  207. addClassifyTag (pos, row) {
  208. const newData = []
  209. row.productTypeList.forEach(item => {
  210. const obj = {}
  211. obj.productTypeSn = item.dataSn
  212. obj.goodsSn = item.dataSn
  213. obj.productTypeName = item.dataName
  214. newData.push(obj)
  215. })
  216. this.chooseType = newData
  217. this.chooseObj = row
  218. this.openTypeModal = true
  219. },
  220. // 打开分类弹窗
  221. handleClassifyModal (con) {
  222. const chooseList = con
  223. this.openTypeModal = false
  224. this.dataSource[this.ChooseClassifyPos].productTypeList = [...this.dataSource[this.ChooseClassifyPos].productTypeList, ...chooseList]
  225. },
  226. // 分类
  227. handleTypeOk (obj) {
  228. this.chooseType = obj
  229. this.saveChangeData('CATEGORY')
  230. },
  231. // 添加品牌标签
  232. addBrandTag (pos, row) {
  233. this.chooseBrand = row.productBrandList
  234. this.chooseObj = row
  235. this.openBrandModal = true
  236. },
  237. // 品牌
  238. handleBrandOk (obj) {
  239. this.chooseBrand = obj
  240. this.saveChangeData('BRAND')
  241. },
  242. // 保存时重组数据
  243. saveChangeData (type) {
  244. const _this = this
  245. if (type == 'BRAND') { // 选择品牌
  246. if (_this.chooseBrand.length > 0) {
  247. const snList = []
  248. _this.chooseBrand.map(item => {
  249. const newObj = {}
  250. newObj.dataSn = item.brandSn
  251. snList.push(newObj)
  252. })
  253. this.save(snList, type)
  254. }
  255. } else if (type == 'CATEGORY') { // 选择分类
  256. if (_this.chooseType.length > 0) {
  257. const snList = []
  258. _this.chooseType.map(item => {
  259. const newObj = {}
  260. newObj.dataSn = item.productTypeSn
  261. snList.push(newObj)
  262. })
  263. this.save(snList, type)
  264. }
  265. }
  266. },
  267. // 保存
  268. save (list, type) {
  269. const ajaxdata = { userSn: this.$route.query.sn, bizUserScopeSn: this.chooseObj.bizUserScopeSn, bizUserSn: this.bizUserSn }
  270. if (type == 'BRAND') {
  271. ajaxdata.productBrandList = list
  272. saveProductBrandList(ajaxdata).then(res => {
  273. if (res.status == 200) {
  274. this.openBrandModal = false
  275. this.$refs.table.refresh()
  276. }
  277. })
  278. } else if (type == 'CATEGORY') {
  279. ajaxdata.productTypeList = list
  280. saveProductTypeList(ajaxdata).then(res => {
  281. if (res.status == 200) {
  282. this.openTypeModal = false
  283. this.$refs.table.refresh()
  284. }
  285. })
  286. }
  287. },
  288. // 整行删除 删除
  289. handleDel (row) {
  290. const _this = this
  291. this.$confirm({
  292. title: '提示',
  293. content: '确认要删除吗?删除后当前用户权限以最新权限为准',
  294. centered: true,
  295. onOk () {
  296. bizuserScopeDelete({ id: row.bizUserScopeSn }).then(res => {
  297. if (res.status == 200) {
  298. const pos = _this.dataSource.findIndex(item => { return item.bizUserScopeSn == row.bizUserScopeSn })
  299. _this.dataSource.splice(pos, 1)
  300. }
  301. })
  302. }
  303. })
  304. },
  305. // 初始化
  306. pageInit () {
  307. const _this = this
  308. this.$nextTick(() => { // 页面渲染完成后的回调
  309. _this.setTableH()
  310. })
  311. this.$refs.table.refresh()
  312. },
  313. // 计算表格高度
  314. setTableH () {
  315. const addBtnHeight = this.$refs.categorySetAddBtn.offsetHeight
  316. this.tableHeight = window.innerHeight - addBtnHeight - 325
  317. }
  318. },
  319. watch: {
  320. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  321. this.setTableH()
  322. }
  323. },
  324. beforeRouteEnter (to, from, next) {
  325. next(vm => {})
  326. }
  327. }
  328. </script>