permissionSetting.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="permissionSetting-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" @back="handleBack" class="permissionSetting-cont">
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="permissionSetting-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. </template>
  9. </a-page-header>
  10. <a-card size="small" :bordered="false" class="permissionSetting-main">
  11. <!-- 搜索条件 -->
  12. <div ref="tableSearch" class="table-page-search-wrapper">
  13. <a-form-model
  14. id="permissionSetting-form"
  15. ref="ruleForm"
  16. class="form-model-con"
  17. layout="inline"
  18. :model="queryParam"
  19. :rules="rules"
  20. @keyup.enter.native="handleSearch">
  21. <a-row :gutter="15">
  22. <a-col :md="6" :sm="24">
  23. <a-form-model-item label="类型" prop="goodsType">
  24. <v-select code="DEALER_GOODS_TYPE" id="permissionSetting-goodsType" v-model="queryParam.goodsType" allowClear placeholder="请选择类型"></v-select>
  25. </a-form-model-item>
  26. </a-col>
  27. <a-col :md="6" :sm="24">
  28. <a-form-model-item label="类型名称" prop="goodsName">
  29. <a-input id="permissionSetting-goodsName" v-model.trim="queryParam.goodsName" allowClear placeholder="请输入类型名称"/>
  30. </a-form-model-item>
  31. </a-col>
  32. <a-col :md="6" :sm="24">
  33. <a-form-model-item label="产品编码" prop="goodsCode">
  34. <a-input id="permissionSetting-goodsCode" v-model.trim="queryParam.goodsCode" allowClear placeholder="请输入产品编码"/>
  35. </a-form-model-item>
  36. </a-col>
  37. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  38. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="permissionSetting-refresh">查询</a-button>
  39. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="permissionSetting-reset">重置</a-button>
  40. </a-col>
  41. </a-row>
  42. </a-form-model>
  43. </div>
  44. <!-- 操作按钮 -->
  45. <div class="table-operator">
  46. <a-button id="permissionSetting-brand" type="primary" class="button-error" @click="choosePModal('BRAND')">选择产品品牌</a-button>
  47. <a-button id="permissionSetting-type" type="primary" class="button-info" @click="choosePModal('CATEGORY')">选择产品分类</a-button>
  48. <a-button id="permissionSetting-product" type="primary" class="button-success" @click="choosePModal('PRODUCT')">选择产品</a-button>
  49. </div>
  50. <!-- 列表 -->
  51. <s-table
  52. class="sTable fixPagination"
  53. ref="table"
  54. :style="{ height: tableHeight+84.5+'px' }"
  55. size="small"
  56. :rowKey="(record) => record.id"
  57. :columns="columns"
  58. :data="loadData"
  59. :scroll="{ y: tableHeight }"
  60. :defaultLoadData="false"
  61. bordered>
  62. <!-- 操作 -->
  63. <template slot="action" slot-scope="text, record">
  64. <a-button size="small" type="link" class="button-error" @click="handleDel(record)">删除</a-button>
  65. </template>
  66. </s-table>
  67. </a-card>
  68. </a-spin>
  69. <!-- 选择产品品牌 -->
  70. <chooseBrandModal :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
  71. <!-- 选择产品分类 -->
  72. <chooseTypeModal :openModal="openTypeModal" :chooseData="chooseType" @close="openTypeModal=false" @ok="handleTypeOk" />
  73. <!-- 选择产品 -->
  74. <chooseProductsModal
  75. type="dealership"
  76. :dealerSn="$route.params.sn"
  77. :openModal="openProductsModal"
  78. :chooseData="chooseProducts"
  79. @close="openProductsModal=false"
  80. @ok="handleProductsOk" />
  81. </div>
  82. </template>
  83. <script>
  84. import { STable, VSelect } from '@/components'
  85. import ChooseProductsModal from '@/views/common/chooseProductsModal.vue'
  86. import ChooseBrandModal from '@/views/common/chooseBrandModal.vue'
  87. import ChooseTypeModal from '@/views/common/chooseTypeModal.vue'
  88. import { dealerScopeList, dealerScopeSave, dealerScopeDel, dealerScopeQueryList } from '@/api/dealerScope'
  89. export default {
  90. components: { STable, VSelect, ChooseProductsModal, ChooseBrandModal, ChooseTypeModal },
  91. data () {
  92. return {
  93. spinning: false,
  94. tableHeight: 0,
  95. queryParam: { // 查询条件
  96. goodsType: undefined,
  97. goodsName: '',
  98. goodsCode: ''
  99. },
  100. rules: {
  101. goodsType: [ { required: true, message: '请选择类型', trigger: 'change' } ]
  102. },
  103. disabled: false, // 查询、重置按钮是否可操作
  104. loading: false, // 表格加载中
  105. columns: [
  106. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  107. { title: '添加时间', dataIndex: 'createDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  108. { title: '类型', dataIndex: 'type', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  109. { title: '类型名称', dataIndex: 'goodsName', align: 'center', width: '20%', customRender: function (text) { return text || '--' }, ellipsis: true },
  110. { title: '产品名称', dataIndex: 'product.name', align: 'center', width: '30%', customRender: function (text) { return text || '--' }, ellipsis: true },
  111. { title: '产品编码', dataIndex: 'product.code', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  112. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  113. ],
  114. // 加载数据方法 必须为 Promise 对象
  115. loadData: parameter => {
  116. this.disabled = true
  117. this.spinning = true
  118. return dealerScopeList(Object.assign(parameter, this.queryParam, { dealerSn: this.$route.params.sn })).then(res => {
  119. const data = res.data
  120. const no = (data.pageNo - 1) * data.pageSize
  121. for (var i = 0; i < data.list.length; i++) {
  122. data.list[i].no = no + i + 1
  123. const goodsType = data.list[i].goodsType
  124. data.list[i].type = goodsType == 'PRODUCT' ? '产品' : goodsType == 'BRAND' ? '品牌' : goodsType == 'CATEGORY' ? '分类' : '--'
  125. }
  126. this.disabled = false
  127. this.spinning = false
  128. return data
  129. })
  130. },
  131. openBrandModal: false, // 选择产品品牌
  132. openTypeModal: false, // 选择产品分类
  133. openProductsModal: false, // 选择产品
  134. chooseBrand: [], // 所选品牌
  135. chooseProducts: [], // 所选产品
  136. chooseType: [] // 所选分类
  137. }
  138. },
  139. methods: {
  140. // 查询
  141. handleSearch () {
  142. const _this = this
  143. this.$refs.ruleForm.validate(valid => {
  144. if (valid) {
  145. _this.$refs.table.refresh(true)
  146. } else {
  147. return false
  148. }
  149. })
  150. },
  151. // 选择产品
  152. choosePModal (type) {
  153. const productList = []
  154. const brandList = []
  155. const typeList = []
  156. dealerScopeQueryList({ dealerSn: this.$route.params.sn, goodsType: type }).then(res => {
  157. if (res.status == 200) {
  158. const data = res.data
  159. data.map(item => {
  160. if (item.goodsType == 'PRODUCT') {
  161. productList.push(item)
  162. } else if (item.goodsType == 'BRAND') {
  163. brandList.push(item)
  164. } else if (item.goodsType == 'CATEGORY') {
  165. typeList.push(item)
  166. }
  167. })
  168. if (type == 'PRODUCT') { // 选择产品
  169. // this.chooseProducts = productList // 包含先前所选产品
  170. this.chooseProducts = [] // 不包含先前所选产品
  171. this.openProductsModal = true
  172. } else if (type == 'BRAND') { // 选择品牌
  173. this.chooseBrand = brandList
  174. this.openBrandModal = true
  175. } else if (type == 'CATEGORY') { // 选择分类
  176. this.chooseType = typeList
  177. this.openTypeModal = true
  178. }
  179. }
  180. })
  181. },
  182. // 品牌
  183. handleBrandOk (obj) {
  184. this.chooseBrand = obj
  185. this.changeData('BRAND')
  186. },
  187. // 产品
  188. handleProductsOk (obj) {
  189. this.chooseProducts = obj
  190. this.changeData('PRODUCT')
  191. },
  192. // 分类
  193. handleTypeOk (obj) {
  194. this.chooseType = obj
  195. this.changeData('CATEGORY')
  196. },
  197. changeData (type) {
  198. const _this = this
  199. if (type == 'PRODUCT') { // 选择产品
  200. if (_this.chooseProducts.length > 0) {
  201. const snList = []
  202. _this.chooseProducts.map(item => {
  203. const productSn = item.productSn ? item.productSn : item.product.productSn ? item.product.productSn : ''
  204. snList.push(productSn)
  205. })
  206. this.setData(snList, type)
  207. }
  208. } else if (type == 'BRAND') { // 选择品牌
  209. if (_this.chooseBrand.length > 0) {
  210. const snList = []
  211. _this.chooseBrand.map(item => {
  212. snList.push(item.brandSn)
  213. })
  214. this.setData(snList, type)
  215. }
  216. } else if (type == 'CATEGORY') { // 选择分类
  217. if (_this.chooseType.length > 0) {
  218. const snList = []
  219. _this.chooseType.map(item => {
  220. snList.push(item.productTypeSn)
  221. })
  222. this.setData(snList, type)
  223. }
  224. }
  225. },
  226. // 添加经销权
  227. setData (snList, type) {
  228. const _this = this
  229. const params = {
  230. dealerSn: _this.$route.params.sn,
  231. goodsType: type,
  232. goodsSnList: snList
  233. }
  234. _this.spinning = true
  235. dealerScopeSave(params).then(res => {
  236. if (res.status == 200) {
  237. _this.$message.success(res.message)
  238. _this.$refs.table.refresh(true)
  239. _this.spinning = false
  240. } else {
  241. _this.spinning = false
  242. }
  243. })
  244. },
  245. // 删除
  246. handleDel (row) {
  247. const _this = this
  248. this.$confirm({
  249. title: '提示',
  250. content: '确认要删除吗?',
  251. centered: true,
  252. onOk () {
  253. _this.spinning = true
  254. dealerScopeDel({ sn: row.dealerScopeSn }).then(res => {
  255. if (res.status == 200) {
  256. _this.$message.success(res.message)
  257. _this.$refs.table.refresh()
  258. _this.spinning = false
  259. } else {
  260. _this.spinning = false
  261. }
  262. })
  263. }
  264. })
  265. },
  266. // 重置表单
  267. resetSearchForm () {
  268. this.queryParam.goodsType = undefined
  269. this.queryParam.goodsName = ''
  270. this.queryParam.goodsCode = ''
  271. this.$refs.table.refresh(true)
  272. },
  273. // 返回
  274. handleBack () {
  275. this.$router.push({ path: '/dealerManagement/merchantInfoManagement/list', query: { closeLastOldTab: true } })
  276. },
  277. filterOption (input, option) {
  278. return (
  279. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  280. )
  281. },
  282. pageInit () {
  283. const _this = this
  284. this.$nextTick(() => { // 页面渲染完成后的回调
  285. _this.setTableH()
  286. })
  287. },
  288. setTableH () {
  289. const tableSearchH = this.$refs.tableSearch.offsetHeight
  290. this.tableHeight = window.innerHeight - tableSearchH - 292
  291. }
  292. },
  293. watch: {
  294. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  295. this.setTableH()
  296. }
  297. },
  298. mounted () {
  299. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  300. this.$refs.table.refresh(true)
  301. this.pageInit()
  302. }
  303. },
  304. activated () {
  305. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  306. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  307. this.$refs.table.refresh(true)
  308. this.pageInit()
  309. }
  310. },
  311. beforeRouteEnter (to, from, next) {
  312. next(vm => {})
  313. }
  314. }
  315. </script>
  316. <style lang="less" scoped>
  317. .permissionSetting-wrap{
  318. .permissionSetting-cont{
  319. margin-bottom: 10px;
  320. }
  321. }
  322. </style>