Browse Source

分类回显

chenrui 1 year ago
parent
commit
dceb3dc387

+ 30 - 7
src/views/common/chooseTypeModal.vue

@@ -78,7 +78,8 @@ export default {
         title: 'productTypeName',
         key: 'productTypeSn'
       },
-      productTypeList: []
+      productTypeList: [],
+      chooseList: []
     }
   },
   methods: {
@@ -95,6 +96,12 @@ export default {
       } else {
         productTypeQuery({}).then(res => {
           if (res.status == 200) {
+            if (!this.linkageStatus && this.chooseData.length > 0) {
+              this.handleDisabled(res.data, this.chooseData)
+            }
+            if (!this.linkageStatus && this.chooseList.length > 0) {
+              this.handleDisabled(res.data, this.chooseList)
+            }
             this.productTypeList = res.data
           } else {
             this.productTypeList = []
@@ -135,10 +142,27 @@ export default {
         })
       }
     },
+    handleAllDisabled (list) {
+      this.chooseList = list
+    },
+    // 禁用递归
+    handleDisabled (data, selectData) {
+      if (data) {
+        data.map(item => {
+          const posNum = selectData.findIndex(con => con.goodsSn == item.productTypeSn)
+          if (posNum != -1) {
+            item = Object.assign(item, selectData[posNum])
+          }
+          if (item.children && item.children.length > 0) {
+            this.handleDisabled(item.children, selectData)
+          }
+        })
+      }
+    },
     onCheck (checkedKeys, info) {
-      // console.log('onCheck', checkedKeys, info)
+      console.log('onCheck', checkedKeys, info)
       // this.checkedData = [...checkedKeys, ...info.halfCheckedKeys]
-      this.checkedKeys = checkedKeys
+      // this.checkedKeys = checkedKeys
       this.checkedRows = []
       info.checkedNodes.map((item, index) => {
         this.checkedRows.push(item.data.props)
@@ -156,17 +180,16 @@ export default {
         this.$emit('close')
         this.checkAll = false
       } else {
+        this.getProductType()
         const _this = this
         this.checkedRows = this.chooseData
         this.checkedKeys = []
-        this.chooseData.map(item => {
+        this.chooseData.forEach(item => {
           _this.checkedKeys.push(item.goodsSn)
         })
-        if (this.productTypeList.length == 0) {
-          this.getProductType()
-        }
       }
     }
+
   }
 }
 </script>

+ 7 - 5
src/views/promotionRulesManagement/dealerPromotions/chooseProductsModal.vue

@@ -176,8 +176,10 @@ export default {
     //  重置
     resetSearchForm () {
       this.resetData()
-      this.$refs.table.refresh()
-      this.$refs.table.clearTable()
+      this.$nextTick(() => {
+        this.$refs.table.refresh()
+        this.$refs.table.clearTable()
+      })
     },
     // 保存
     handleSave () {
@@ -210,10 +212,10 @@ export default {
       } else {
         const _this = this
         _this.resetSearchForm()
-        const selectedRows = []
+        let selectedRows = []
         const selectedRowKeys = []
-        selectedRows = this.chooseData
-        this.chooseData.map(item => {
+        selectedRows = _this.chooseData
+        _this.chooseData.map(item => {
           selectedRowKeys.push(item.goodsSn)
         })
         this.$nextTick(() => { // 页面渲染完成后的回调

+ 51 - 3
src/views/promotionRulesManagement/dealerPromotions/tableType1.vue

@@ -128,7 +128,13 @@
     <!-- 选择产品品牌 -->
     <chooseBrandModal ref="brandBox" :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
     <!-- 选择产品分类 -->
-    <chooseTypeModal :openModal="openTypeModal" :linkageStatus="false" :chooseData="chooseType" @close="openTypeModal=false" @ok="handleTypeOk" />
+    <chooseTypeModal
+      ref="typeBox"
+      :openModal="openTypeModal"
+      :linkageStatus="false"
+      :chooseData="chooseType"
+      @close="openTypeModal=false"
+      @ok="handleTypeOk" />
     <!-- 选择产品 -->
     <chooseProductsModal
       type="dealership"
@@ -203,6 +209,9 @@ export default {
     addClassifyTag (pos, row) {
       this.classifyTagIndex = pos
       this.openTypeModal = true
+      this.chooseType = this.handleRowData(row)
+      const getArr = this.setTypeShowData()
+      this.$refs.typeBox.handleAllDisabled(getArr)
     },
     handleTypeOk (mainArr) {
       const classifyArr = []
@@ -273,13 +282,12 @@ export default {
     },
     // 添加产品
     addProductTag (pos, row) {
-      debugger
       this.productTagIndex = pos
+      this.openProductsModal = true
       const dataList = this.setShowData('This')
       const echoData = this.handleEchoData('This', row.productThisList)
       this.chooseProducts = echoData
       this.$refs.productBox.handleDisabled(dataList)
-      this.openProductsModal = true
     },
     handleProductsOk (arr) {
       const newArr = []
@@ -317,6 +325,46 @@ export default {
       })
       return conArr
     },
+    handleRowData (row) {
+      const echoData = []
+      row.productTypeList.forEach(item => {
+        for (const i in item) {
+          const newObj = {
+            goodsSn: item[i]
+          }
+          if (i === 'productTypeSn1') {
+            newObj.disabled = true
+          } else {
+            newObj.disableCheckbox = true
+          }
+          echoData.push(newObj)
+        }
+      })
+      return echoData
+    },
+    setTypeShowData () {
+      const _this = this
+      const snArr = []
+      _this.dataSource.forEach(item => {
+        if (item.productTypeList && item.productTypeList.length > 0) {
+          item.productTypeList.forEach(con => {
+            for (const i in con) {
+              const newObj = {
+                goodsSn: con[i]
+              }
+              if (i === 'productTypeSn1') {
+                newObj.disabled = true
+              } else {
+                newObj.disableCheckbox = true
+              }
+              snArr.push(newObj)
+            }
+          })
+        }
+      })
+      return snArr
+    },
+    // 获取表格数据
     getResultVal () {
       const resultObj = JSON.parse(JSON.stringify(this.dataSource))
       resultObj.map(item => {

+ 89 - 4
src/views/promotionRulesManagement/dealerPromotions/tableType2.vue

@@ -98,11 +98,18 @@
       <a-button id="tableType1-add" type="primary" class="button-gray" @click="handleAddRow">+新增一行</a-button>
     </div>
     <!-- 选择产品品牌 -->
-    <chooseBrandModal :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
+    <chooseBrandModal ref="brandBox" :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
     <!-- 选择产品分类 -->
-    <chooseTypeModal :openModal="openTypeModal" :linkageStatus="false" :chooseData="chooseType" @close="openTypeModal=false" @ok="handleTypeOk" />
+    <chooseTypeModal
+      ref="typeBox"
+      :openModal="openTypeModal"
+      :linkageStatus="false"
+      :chooseData="chooseType"
+      @close="openTypeModal=false"
+      @ok="handleTypeOk" />
     <!-- 选择产品 -->
     <chooseProductsModal
+      ref="productBox"
       type="dealership"
       :openModal="openProductsModal"
       :chooseData="chooseProducts"
@@ -173,6 +180,9 @@ export default {
     addClassifyTag (pos, row) {
       this.classifyTagIndex = pos
       this.openTypeModal = true
+      this.chooseType = this.handleRowData(row)
+      const getArr = this.setTypeShowData()
+      this.$refs.typeBox.handleAllDisabled(getArr)
     },
     handleTypeOk (mainArr) {
       const classifyArr = []
@@ -220,8 +230,14 @@ export default {
     },
     // 添加产品品牌
     addBrandTag (pos, row) {
-      this.brandTagIndex = pos
-      this.openBrandModal = true
+      const _this = this
+      _this.brandTagIndex = pos
+      // 每行品牌都是唯一滴
+      const dataList = _this.setShowData('Brand')
+      _this.openBrandModal = true
+      const echoData = _this.handleEchoData('Brand', row.productBrandList)
+      _this.chooseBrand = echoData
+      _this.$refs.brandBox.handleDisabled(dataList)
     },
     handleBrandOk (conList) {
       const newConList = conList.map(con => {
@@ -236,6 +252,10 @@ export default {
     addProductTag (pos, row) {
       this.productTagIndex = pos
       this.openProductsModal = true
+      const dataList = this.setShowData('This')
+      const echoData = this.handleEchoData('This', row.productThisList)
+      this.chooseProducts = echoData
+      this.$refs.productBox.handleDisabled(dataList)
     },
     handleProductsOk (arr) {
       const newArr = []
@@ -248,6 +268,71 @@ export default {
       })
       this.dataSource[this.productTagIndex].productThisList = newArr
     },
+    // 获取回显禁用数据
+    setShowData (name) {
+      const _this = this
+      const snArr = []
+      _this.dataSource.forEach(item => {
+        if (item['product' + name + 'List'] && item['product' + name + 'List'].length > 0) {
+          item['product' + name + 'List'].forEach(con => {
+            const newName = name === 'This' ? '' : name
+            snArr.push(con['product' + newName + 'Sn'])
+          })
+        }
+      })
+      return snArr
+    },
+    handleEchoData (name, conArr) {
+      conArr.map(item => {
+        if (name === 'This') {
+          item.code = item.productCode
+          item.goodsSn = item.productSn
+        } else {
+          item.goodsSn = item['product' + name + 'Sn']
+        }
+      })
+      return conArr
+    },
+    handleRowData (row) {
+      const echoData = []
+      row.productTypeList.forEach(item => {
+        for (const i in item) {
+          const newObj = {
+            goodsSn: item[i]
+          }
+          if (i === 'productTypeSn1') {
+            newObj.disabled = true
+          } else {
+            newObj.disableCheckbox = true
+          }
+          echoData.push(newObj)
+        }
+      })
+      return echoData
+    },
+    setTypeShowData () {
+      const _this = this
+      const snArr = []
+      _this.dataSource.forEach(item => {
+        if (item.productTypeList && item.productTypeList.length > 0) {
+          item.productTypeList.forEach(con => {
+            for (const i in con) {
+              const newObj = {
+                goodsSn: con[i]
+              }
+              if (i === 'productTypeSn1') {
+                newObj.disabled = true
+              } else {
+                newObj.disableCheckbox = true
+              }
+              snArr.push(newObj)
+            }
+          })
+        }
+      })
+      return snArr
+    },
+    // 获取表格数据
     getResultVal () {
       const resultObj = JSON.parse(JSON.stringify(this.dataSource))
       resultObj.map(item => {

+ 98 - 19
src/views/promotionRulesManagement/dealerPromotions/tableType3.vue

@@ -99,7 +99,7 @@
       </template>
       <!-- 市价特价 -->
       <template slot="cityPrice" slot-scope="text, record">
-        <div  v-if="record.dataSourceOrigin=='1'">
+        <div v-if="record.dataSourceOrigin=='1'">
           <a-input-number
             size="small"
             style="width:75%;"
@@ -129,18 +129,18 @@
       </template>
       <!-- 特约特价 -->
       <template slot="specialPrice" slot-scope="text, record">
-       <div  v-if="record.dataSourceOrigin=='1'">
-         <a-input-number
-           size="small"
-           style="width:75%;"
-           v-model="record.specialDiscountPrice"
-           :min="0"
-           :step="1"
-           :precision="2"
-           placeholder="请输入"
-           :max="record.specialPrice"
-           @blur="e=>calculatePrice(e.target.value,record.productScopeSn,'special')"/>
-       </div>
+        <div v-if="record.dataSourceOrigin=='1'">
+          <a-input-number
+            size="small"
+            style="width:75%;"
+            v-model="record.specialDiscountPrice"
+            :min="0"
+            :step="1"
+            :precision="2"
+            placeholder="请输入"
+            :max="record.specialPrice"
+            @blur="e=>calculatePrice(e.target.value,record.productScopeSn,'special')"/>
+        </div>
         <span v-else>--</span>
       </template>
       <!-- 特约折扣 -->
@@ -193,9 +193,15 @@
       <a-button id="tableType1-add" type="primary" class="button-gray" @click="handleAddRow">+新增一行</a-button>
     </div>
     <!-- 选择产品品牌 -->
-    <chooseBrandModal :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
+    <chooseBrandModal ref="brandBox" :openModal="openBrandModal" :chooseData="chooseBrand" @close="openBrandModal=false" @ok="handleBrandOk" />
     <!-- 选择产品分类 -->
-    <chooseTypeModal :openModal="openTypeModal" :linkageStatus="false" :chooseData="chooseType" @close="openTypeModal=false" @ok="handleTypeOk" />
+    <chooseTypeModal
+      ref="typeBox"
+      :openModal="openTypeModal"
+      :linkageStatus="false"
+      :chooseData="chooseType"
+      @close="openTypeModal=false"
+      @ok="handleTypeOk" />
   </div>
 </template>
 
@@ -258,7 +264,7 @@ export default {
     },
     // 新增产品 数据
     setSourceData (list) {
-      this.dataSource=this.dataSource.concat(list)
+      this.dataSource = this.dataSource.concat(list)
     },
     // 新增一行
     handleAddRow () {
@@ -268,7 +274,7 @@ export default {
         if (res.status == 200) {
           const newData = {
             productScopeSn: res.data,
-            dataSourceOrigin:'0',
+            dataSourceOrigin: '0',
             productTypeArr: [],
             productTypeList: [],
             productBrandArr: [],
@@ -289,6 +295,9 @@ export default {
     addClassifyTag (pos, row) {
       this.classifyTagIndex = pos
       this.openTypeModal = true
+      this.chooseType = this.handleRowData(row)
+      const getArr = this.setTypeShowData()
+      this.$refs.typeBox.handleAllDisabled(getArr)
     },
     handleTypeOk (mainArr) {
       const classifyArr = []
@@ -336,8 +345,14 @@ export default {
     },
     // 添加产品品牌
     addBrandTag (pos, row) {
-      this.brandTagIndex = pos
-      this.openBrandModal = true
+      const _this = this
+      _this.brandTagIndex = pos
+      // 每行品牌都是唯一滴
+      const dataList = _this.setShowData('Brand')
+      _this.openBrandModal = true
+      const echoData = _this.handleEchoData('Brand', row.productBrandList)
+      _this.chooseBrand = echoData
+      _this.$refs.brandBox.handleDisabled(dataList)
     },
     handleBrandOk (conList) {
       const newConList = conList.map(con => {
@@ -348,6 +363,70 @@ export default {
       this.dataSource[this.brandTagIndex].productBrandArr = conList
       this.dataSource[this.brandTagIndex].productBrandList = newConList
     },
+    // 获取回显禁用数据
+    setShowData (name) {
+      const _this = this
+      const snArr = []
+      _this.dataSource.forEach(item => {
+        if (item['product' + name + 'List'] && item['product' + name + 'List'].length > 0) {
+          item['product' + name + 'List'].forEach(con => {
+            const newName = name === 'This' ? '' : name
+            snArr.push(con['product' + newName + 'Sn'])
+          })
+        }
+      })
+      return snArr
+    },
+    handleEchoData (name, conArr) {
+      conArr.map(item => {
+        if (name === 'This') {
+          item.code = item.productCode
+          item.goodsSn = item.productSn
+        } else {
+          item.goodsSn = item['product' + name + 'Sn']
+        }
+      })
+      return conArr
+    },
+    handleRowData (row) {
+      const echoData = []
+      row.productTypeList.forEach(item => {
+        for (const i in item) {
+          const newObj = {
+            goodsSn: item[i]
+          }
+          if (i === 'productTypeSn1') {
+            newObj.disabled = true
+          } else {
+            newObj.disableCheckbox = true
+          }
+          echoData.push(newObj)
+        }
+      })
+      return echoData
+    },
+    setTypeShowData () {
+      const _this = this
+      const snArr = []
+      _this.dataSource.forEach(item => {
+        if (item.productTypeList && item.productTypeList.length > 0) {
+          item.productTypeList.forEach(con => {
+            for (const i in con) {
+              const newObj = {
+                goodsSn: con[i]
+              }
+              if (i === 'productTypeSn1') {
+                newObj.disabled = true
+              } else {
+                newObj.disableCheckbox = true
+              }
+              snArr.push(newObj)
+            }
+          })
+        }
+      })
+      return snArr
+    },
     getResultVal () {
       const resultObj = JSON.parse(JSON.stringify(this.dataSource))
       resultObj.map(item => {