permissionSetting.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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="{ x: 930, y: tableHeight }"
  60. bordered>
  61. <!-- 操作 -->
  62. <template slot="action" slot-scope="text, record">
  63. <a-button size="small" type="link" class="button-error" @click="handleDel(record)">删除</a-button>
  64. </template>
  65. </s-table>
  66. </a-card>
  67. </a-spin>
  68. <!-- 选择产品品牌 -->
  69. <chooseBrandModal :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
  70. <!-- 选择产品分类 -->
  71. <chooseTypeModal :openModal="openTypeModal" :chooseData="chooseType" @close="openTypeModal=false" @ok="handleTypeOk" />
  72. <!-- 选择产品 -->
  73. <chooseProductsModal
  74. type="dealership"
  75. :dealerSn="$route.params.sn"
  76. :openModal="openProductsModal"
  77. :chooseData="chooseProducts"
  78. @close="openProductsModal=false"
  79. @ok="handleProductsOk" />
  80. </div>
  81. </template>
  82. <script>
  83. import { STable, VSelect } from '@/components'
  84. import ChooseProductsModal from '@/views/common/chooseProductsModal.vue'
  85. import ChooseBrandModal from '@/views/common/chooseBrandModal.vue'
  86. import ChooseTypeModal from '@/views/common/chooseTypeModal.vue'
  87. import { dealerScopeList, dealerScopeSave, dealerScopeDel, dealerScopeQueryList } from '@/api/dealerScope'
  88. export default {
  89. components: { STable, VSelect, ChooseProductsModal, ChooseBrandModal, ChooseTypeModal },
  90. data () {
  91. return {
  92. spinning: false,
  93. tableHeight: 0,
  94. queryParam: { // 查询条件
  95. goodsType: undefined,
  96. goodsName: '',
  97. goodsCode: ''
  98. },
  99. rules: {
  100. goodsType: [ { required: true, message: '请选择类型', trigger: 'change' } ]
  101. },
  102. disabled: false, // 查询、重置按钮是否可操作
  103. loading: false, // 表格加载中
  104. columns: [
  105. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  106. { title: '添加时间', dataIndex: 'createDate', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  107. { title: '类型', dataIndex: 'type', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  108. { title: '类型名称', dataIndex: 'goodsName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  109. { title: '产品名称', dataIndex: 'product.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  110. { title: '产品编码', dataIndex: 'product.code', width: 180, align: 'center', customRender: function (text) { return text || '--' } },
  111. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  112. ],
  113. // 加载数据方法 必须为 Promise 对象
  114. loadData: parameter => {
  115. this.disabled = true
  116. this.spinning = true
  117. return dealerScopeList(Object.assign(parameter, this.queryParam, { dealerSn: this.$route.params.sn })).then(res => {
  118. const data = res.data
  119. const no = (data.pageNo - 1) * data.pageSize
  120. for (var i = 0; i < data.list.length; i++) {
  121. data.list[i].no = no + i + 1
  122. const goodsType = data.list[i].goodsType
  123. data.list[i].type = goodsType == 'PRODUCT' ? '产品' : goodsType == 'BRAND' ? '品牌' : goodsType == 'CATEGORY' ? '分类' : '--'
  124. }
  125. this.disabled = false
  126. this.spinning = false
  127. return data
  128. })
  129. },
  130. openBrandModal: false, // 选择产品品牌
  131. openTypeModal: false, // 选择产品分类
  132. openProductsModal: false, // 选择产品
  133. chooseBrand: [], // 所选品牌
  134. chooseProducts: [], // 所选产品
  135. chooseType: [] // 所选分类
  136. }
  137. },
  138. methods: {
  139. // 查询
  140. handleSearch () {
  141. const _this = this
  142. this.$refs.ruleForm.validate(valid => {
  143. if (valid) {
  144. _this.$refs.table.refresh(true)
  145. } else {
  146. return false
  147. }
  148. })
  149. },
  150. // 选择产品
  151. choosePModal (type) {
  152. const productList = []
  153. const brandList = []
  154. const typeList = []
  155. dealerScopeQueryList({ dealerSn: this.$route.params.sn, goodsType: type }).then(res => {
  156. if (res.status == 200) {
  157. const data = res.data
  158. data.map(item => {
  159. if (item.goodsType == 'PRODUCT') {
  160. productList.push(item)
  161. } else if (item.goodsType == 'BRAND') {
  162. brandList.push(item)
  163. } else if (item.goodsType == 'CATEGORY') {
  164. typeList.push(item)
  165. }
  166. })
  167. if (type == 'PRODUCT') { // 选择产品
  168. // this.chooseProducts = productList // 包含先前所选产品
  169. this.chooseProducts = [] // 不包含先前所选产品
  170. this.openProductsModal = true
  171. } else if (type == 'BRAND') { // 选择品牌
  172. this.chooseBrand = brandList
  173. this.openBrandModal = true
  174. } else if (type == 'CATEGORY') { // 选择分类
  175. this.chooseType = typeList
  176. this.openTypeModal = true
  177. }
  178. }
  179. })
  180. },
  181. // 品牌
  182. handleBrandOk (obj) {
  183. this.chooseBrand = obj
  184. this.changeData('BRAND')
  185. },
  186. // 产品
  187. handleProductsOk (obj) {
  188. this.chooseProducts = obj
  189. this.changeData('PRODUCT')
  190. },
  191. // 分类
  192. handleTypeOk (obj) {
  193. this.chooseType = obj
  194. this.changeData('CATEGORY')
  195. },
  196. changeData (type) {
  197. const _this = this
  198. if (type == 'PRODUCT') { // 选择产品
  199. if (_this.chooseProducts.length > 0) {
  200. const snList = []
  201. _this.chooseProducts.map(item => {
  202. const productSn = item.productSn ? item.productSn : item.product.productSn ? item.product.productSn : ''
  203. snList.push(productSn)
  204. })
  205. this.setData(snList, type)
  206. }
  207. } else if (type == 'BRAND') { // 选择品牌
  208. if (_this.chooseBrand.length > 0) {
  209. const snList = []
  210. _this.chooseBrand.map(item => {
  211. snList.push(item.brandSn)
  212. })
  213. this.setData(snList, type)
  214. }
  215. } else if (type == 'CATEGORY') { // 选择分类
  216. if (_this.chooseType.length > 0) {
  217. const snList = []
  218. _this.chooseType.map(item => {
  219. snList.push(item.productTypeSn)
  220. })
  221. this.setData(snList, type)
  222. }
  223. }
  224. },
  225. // 添加经销权
  226. setData (snList, type) {
  227. const _this = this
  228. const params = {
  229. dealerSn: _this.$route.params.sn,
  230. goodsType: type,
  231. goodsSnList: snList
  232. }
  233. _this.spinning = true
  234. dealerScopeSave(params).then(res => {
  235. if (res.status == 200) {
  236. _this.$message.success(res.message)
  237. _this.$refs.table.refresh(true)
  238. _this.spinning = false
  239. } else {
  240. _this.spinning = false
  241. }
  242. })
  243. },
  244. // 删除
  245. handleDel (row) {
  246. const _this = this
  247. this.$confirm({
  248. title: '提示',
  249. content: '确认要删除吗?',
  250. centered: true,
  251. onOk () {
  252. _this.spinning = true
  253. dealerScopeDel({ sn: row.dealerScopeSn }).then(res => {
  254. if (res.status == 200) {
  255. _this.$message.success(res.message)
  256. _this.$refs.table.refresh()
  257. _this.spinning = false
  258. } else {
  259. _this.spinning = false
  260. }
  261. })
  262. }
  263. })
  264. },
  265. // 重置表单
  266. resetSearchForm () {
  267. this.queryParam.goodsType = undefined
  268. this.queryParam.goodsName = ''
  269. this.queryParam.goodsCode = ''
  270. this.$refs.table.refresh(true)
  271. },
  272. // 返回
  273. handleBack () {
  274. this.$router.push({ path: '/dealerManagement/merchantInfoManagement/list', query: { closeLastOldTab: true } })
  275. },
  276. filterOption (input, option) {
  277. return (
  278. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  279. )
  280. },
  281. setTableH () {
  282. const tableSearchH = this.$refs.tableSearch.offsetHeight
  283. this.tableHeight = window.innerHeight - tableSearchH - 295
  284. }
  285. },
  286. mounted () {
  287. const _this = this
  288. this.$nextTick(() => { // 页面渲染完成后的回调
  289. _this.setTableH()
  290. })
  291. },
  292. beforeRouteEnter (to, from, next) {
  293. next(vm => {
  294. if (!vm.disabled) {
  295. vm.$refs.table.refresh(true)
  296. }
  297. })
  298. }
  299. }
  300. </script>
  301. <style lang="less" scoped>
  302. .permissionSetting-wrap{
  303. .permissionSetting-cont{
  304. margin-bottom: 10px;
  305. }
  306. }
  307. </style>