浏览代码

feat: 优化关联订单逻辑

cuiyalong 3 月之前
父节点
当前提交
10723211a0

+ 3 - 3
src/utils/mixins/selector-v-model.js

@@ -1,15 +1,15 @@
 export const selectorVModelMixin = {
 export const selectorVModelMixin = {
   props: {
   props: {
-    state: {
+    value: {
       type: [Object, Array]
       type: [Object, Array]
     }
     }
   },
   },
   model: {
   model: {
-    prop: 'state',
+    prop: 'value',
     event: 'change'
     event: 'change'
   },
   },
   watch: {
   watch: {
-    state: {
+    value: {
       immediate: true,
       immediate: true,
       handler(n) {
       handler(n) {
         this.setState(n)
         this.setState(n)

+ 3 - 1
src/views/create-order/components/product-info-submodule/ContractAmount.vue

@@ -121,7 +121,9 @@ export default {
 
 
   .sub-info-container {
   .sub-info-container {
     .sub-info-item {
     .sub-info-item {
-      margin-left: 60px;
+      &:not(:first-of-type) {
+        margin-left: 60px;
+      }
     }
     }
   }
   }
 
 

+ 0 - 21
src/views/create-order/components/product-info-submodule/RelatedOrderTable.vue

@@ -84,10 +84,6 @@ export default {
       type: String,
       type: String,
       default: '_verId'
       default: '_verId'
     },
     },
-    defaultSelected: {
-      type: Boolean,
-      default: false,
-    },
     required: {
     required: {
       type: Boolean,
       type: Boolean,
       default: false,
       default: false,
@@ -109,16 +105,6 @@ export default {
       }
       }
     }
     }
   },
   },
-  watch: {
-    tableData: {
-      immediate: true,
-      handler() {
-        if (this.defaultSelected) {
-          this.initSelected()
-        }
-      }
-    }
-  },
   methods: {
   methods: {
     onInput(e) {
     onInput(e) {
       this.$emit('input', e)
       this.$emit('input', e)
@@ -126,13 +112,6 @@ export default {
     getRowKey(row) {
     getRowKey(row) {
       return row[this.defaultKey] || row[this.defaultKey2]
       return row[this.defaultKey] || row[this.defaultKey2]
     },
     },
-    initSelected() {
-      if (this.tableData.length === 1) {
-        // 默认勾选
-        const id = this.tableData[0][this.defaultKey] || this.tableData[0][this.defaultKey2]
-        this.onInput([id])
-      }
-    },
     handleRowClick(row) {
     handleRowClick(row) {
       this.handleRadioChange(row)
       this.handleRadioChange(row)
     },
     },

+ 24 - 3
src/views/create-order/components/product-info-submodule/RelatedOrders.vue

@@ -18,7 +18,6 @@
         selection
         selection
         v-model="cacheLinkedOrderArr"
         v-model="cacheLinkedOrderArr"
         :tableData="tableData"
         :tableData="tableData"
-        :defaultSelected="required"
         :required="required"
         :required="required"
       ></RelatedOrderTable>
       ></RelatedOrderTable>
       <span slot="footer" class="dialog-footer">
       <span slot="footer" class="dialog-footer">
@@ -157,6 +156,16 @@ export default {
       cacheLinkedOrderArr: [],
       cacheLinkedOrderArr: [],
     }
     }
   },
   },
+  watch: {
+    required: {
+      immediate: true,
+      handler(n) {
+        if (this.tableData.length > 0) {
+          this.initSelected(n)
+        }
+      }
+    },
+  },
   computed: {
   computed: {
     // 对options展开
     // 对options展开
     tableData() {
     tableData() {
@@ -183,7 +192,7 @@ export default {
       })
       })
     },
     },
     selectedTableData() {
     selectedTableData() {
-      return this.tableData.filter(r => this.linkedOrderArr.includes(r.linkedOrder))
+      return this.tableData.filter(r => this.linkedOrderArr.includes(r.linkedOrder || r._verId))
     },
     },
     linkedIdText() {
     linkedIdText() {
       return this.selectedTableData.map(r => r.linkedOrder || '-').join(',') || ''
       return this.selectedTableData.map(r => r.linkedOrder || '-').join(',') || ''
@@ -243,7 +252,19 @@ export default {
         selected: JSON.parse(JSON.stringify(this.selectedTableData)),
         selected: JSON.parse(JSON.stringify(this.selectedTableData)),
       }
       }
       this.$emit('confirm', payload)
       this.$emit('confirm', payload)
-    }
+    },
+    initSelected(n) {
+      if (n) {
+        if (this.tableData.length === 1) {
+          // 默认勾选
+          const id = this.tableData[0].linkedOrder || this.tableData[0]._verId
+          this.cacheLinkedOrderArr = [id]
+        }
+      } else {
+        this.cacheLinkedOrderArr = []
+      }
+      this.onDialogConfirm()
+    },
   }
   }
 }
 }
 </script>
 </script>

+ 11 - 4
src/views/create-order/components/product-info-submodule/ServiceList.vue

@@ -19,7 +19,11 @@
                   {{ sc.label }}
                   {{ sc.label }}
                 </template>
                 </template>
                 <template v-else>
                 <template v-else>
-                  <el-checkbox-group class="service-list-checkbox-group" v-model="service.childrenValue" @change="handleChildrenCheckedChange($event, service)">
+                  <el-checkbox-group
+                    class="service-list-checkbox-group"
+                    v-model="service.childrenValue"
+                    @change="handleChildrenCheckedChange($event, service)"
+                  >
                     <el-checkbox :label="sc.value" :value="sc.checked" @change="onScCheckboxChange(sc, $event)" :disabled="sc.disabled || disabled">
                     <el-checkbox :label="sc.value" :value="sc.checked" @change="onScCheckboxChange(sc, $event)" :disabled="sc.disabled || disabled">
                       {{ sc.label }}
                       {{ sc.label }}
                       <el-select
                       <el-select
@@ -451,17 +455,20 @@ export default {
       this.onChange()
       this.onChange()
     },
     },
     handleChildrenCheckedChange(value, service) {
     handleChildrenCheckedChange(value, service) {
+      this.checkIndeterminate(value, service)
+      this.onChange()
+    },
+    checkIndeterminate(value, service) {
       const checkedCount = value.length
       const checkedCount = value.length
       const checkAll = checkedCount === service.children.length
       const checkAll = checkedCount === service.children.length
       service.checked = checkAll
       service.checked = checkAll
       service.indeterminate = checkedCount > 0 && checkedCount < service.children.length
       service.indeterminate = checkedCount > 0 && checkedCount < service.children.length
-      this.onChange()
     },
     },
     // 检查一级checkbox是否需要全选半选
     // 检查一级checkbox是否需要全选半选
     checkAllFirstCheckboxChecked() {
     checkAllFirstCheckboxChecked() {
       this.serviceList.forEach(service => {
       this.serviceList.forEach(service => {
         if (service.id === 1) return
         if (service.id === 1) return
-        this.handleChildrenCheckedChange(service.childrenValue, service)
+        this.checkIndeterminate(service.childrenValue, service)
       })
       })
     },
     },
     onScCheckboxChange(sc, e) {
     onScCheckboxChange(sc, e) {
@@ -611,7 +618,7 @@ export default {
         })
         })
         service.childrenValue = [...new Set(childrenValue)]
         service.childrenValue = [...new Set(childrenValue)]
         // 检查是否全选
         // 检查是否全选
-        this.handleChildrenCheckedChange(service.childrenValue, service)
+        this.checkIndeterminate(service.childrenValue, service)
       })
       })
     },
     },
     setDisabledService(disabledIds = []) {
     setDisabledService(disabledIds = []) {

+ 69 - 29
src/views/create-order/components/schema-form/schema-form.vue

@@ -1,5 +1,6 @@
 <template>
 <template>
   <div class="order-schema-form-container">
   <div class="order-schema-form-container">
+    <!-- schema-form中用到的组件,禁止在created时候立即返回一个值,会出现其他选项默认值为空的情况。应该等createSchema的默认值赋值后再进行emit -->
     <SchemaFormRenderer
     <SchemaFormRenderer
       ref="schemaForm"
       ref="schemaForm"
       :key="productType"
       :key="productType"
@@ -98,6 +99,12 @@ export default {
     },
     },
   },
   },
   watch: {
   watch: {
+    value: {
+      deep: true,
+      handler(n) {
+        this.onValueChange(n) // 用于监听哪些字段做了变动,然后进行一些操作
+      }
+    },
     productType: {
     productType: {
       immediate: true,
       immediate: true,
       handler(n) {
       handler(n) {
@@ -132,7 +139,6 @@ export default {
     },
     },
     onInput(e) {
     onInput(e) {
       this.emitInput(e)
       this.emitInput(e)
-      this.afterInput() // 用于监听哪些字段做了变动,然后进行一些操作
     },
     },
     onInitSchema() {
     onInitSchema() {
       this.$emit('initd')
       this.$emit('initd')
@@ -172,7 +178,7 @@ export default {
       this.onInput(newValue)
       this.onInput(newValue)
       this.onInitSchema()
       this.onInitSchema()
       // 更新完规则后,刷新规则相关判断
       // 更新完规则后,刷新规则相关判断
-      this.dynamicChangeSchema()
+      this.dynamicChangeSchema(this.value)
 
 
       this.$nextTick(() => {
       this.$nextTick(() => {
         this.beforeGetUserPower()
         this.beforeGetUserPower()
@@ -187,7 +193,7 @@ export default {
       } finally {
       } finally {
         this.changeLoading(false)
         this.changeLoading(false)
         this.$nextTick(() => {
         this.$nextTick(() => {
-          this.dynamicChangeSchema()
+          this.dynamicChangeSchema(this.value)
         })
         })
       }
       }
     },
     },
@@ -232,11 +238,11 @@ export default {
       }
       }
       return r
       return r
     },
     },
-    getChangedFields() {
-      return deepCompareObjects(this.value, cloneDeep(this.cacheValue))
+    getChangedFields(value) {
+      return deepCompareObjects(value, cloneDeep(this.cacheValue))
     },
     },
-    needChangeSchema() {
-      const changedFieldsArr = this.getChangedFields()
+    needChangeSchema(value) {
+      const changedFieldsArr = this.getChangedFields(value)
       const changedFields = changedFieldsArr.join(',')
       const changedFields = changedFieldsArr.join(',')
       const res = {
       const res = {
         needChange: true,
         needChange: true,
@@ -252,7 +258,7 @@ export default {
       // 求交集
       // 求交集
       const needChange = needChangedArr.length !== 0
       const needChange = needChangedArr.length !== 0
       // 此处规则log不要注释!!!需要通过此log判断在产品类型变更后是否产生了递归调用
       // 此处规则log不要注释!!!需要通过此log判断在产品类型变更后是否产生了递归调用
-      // <主要是应对this.value字段少 -> this.value 字段多时的情况>
+      // <主要是应对value字段少 变到 value 字段多时的情况>
       console.log('是否需要更新schema规则: ', needChange, needChangedArr) // 禁止移除
       console.log('是否需要更新schema规则: ', needChange, needChangedArr) // 禁止移除
       return Object.assign(res, {
       return Object.assign(res, {
         needChange
         needChange
@@ -274,14 +280,15 @@ export default {
       return this.schema.find(item => item.key === key)
       return this.schema.find(item => item.key === key)
     },
     },
     // 处理并分发各个产品卡片操作的限制
     // 处理并分发各个产品卡片操作的限制
-    afterInput: debounce(function() {
+    onValueChange: debounce(function(value) {
       // 修改某些字段时候才会更新schema
       // 修改某些字段时候才会更新schema
-      const { needChange, changedFieldsArr } = this.needChangeSchema()
+      const { needChange, changedFieldsArr } = this.needChangeSchema(value)
       this.onChangedFields(changedFieldsArr)
       this.onChangedFields(changedFieldsArr)
       if (!needChange) return
       if (!needChange) return
-      this.dynamicChangeSchema()
-    }, 50),
+      this.dynamicChangeSchema(value)
+    }, 100),
     getPriceRequest: debounce(async function getPrice(p) {
     getPriceRequest: debounce(async function getPrice(p) {
+      console.log('准备获取价格...')
       const commonP = {
       const commonP = {
         productInfo: cloneDeep(this.thisProductInfoListItem),
         productInfo: cloneDeep(this.thisProductInfoListItem),
         type: this.productType,
         type: this.productType,
@@ -414,7 +421,12 @@ export default {
 
 
       this.$set(relatedOrders.hooks, 'confirm', async (p) => {
       this.$set(relatedOrders.hooks, 'confirm', async (p) => {
         if (p.selected[0]) {
         if (p.selected[0]) {
-          this.selectedRelatedOrder = p.selected[0]
+          const t = p.selected[0]
+          this.selectedRelatedOrder = t
+          // 更新serviceList
+          if (Array.isArray(t.serviceList)) {
+            this.refreshValue({ serviceList: [...new Set(t.serviceList)] })
+          }
         }
         }
         // 企业下,根据选中的权益判断是否可以进行续费和升级
         // 企业下,根据选中的权益判断是否可以进行续费和升级
         if (buySubject === 2) {
         if (buySubject === 2) {
@@ -562,35 +574,29 @@ export default {
         // 不展示合同金额
         // 不展示合同金额
         this.$set(m.props, 'showContractMoney', false)
         this.$set(m.props, 'showContractMoney', false)
       }
       }
-
-      if (this.utilCheckIsVipService()) {
-        this.getPriceRequest()
-      } else {
-        // 无法计算商品价格
-      }
     },
     },
-    dynamicChangeSchema() {
+    dynamicChangeSchema(value) {
       // 注意:此处函数不允许异步动态修改props。可能会造成递归循环调用
       // 注意:此处函数不允许异步动态修改props。可能会造成递归循环调用
       this.$nextTick(() => {
       this.$nextTick(() => {
         const type = this.productType
         const type = this.productType
         if (type === productKeyMap.cjdy) {
         if (type === productKeyMap.cjdy) {
-          this.groupCjdySchema()
+          this.groupCjdySchema(value)
         } else if (type === productKeyMap.dhy) {
         } else if (type === productKeyMap.dhy) {
-          this.changeDhySchema()
+          this.changeDhySchema(value)
         } else if (productGroupKeyMap.oneSpecProduct.includes(type)) {
         } else if (productGroupKeyMap.oneSpecProduct.includes(type)) {
-          this.changeOneSpecSchema()
+          this.changeOneSpecSchema(value)
         } else if (productGroupKeyMap.dataCountProduct.includes(type)) {
         } else if (productGroupKeyMap.dataCountProduct.includes(type)) {
-          this.changeDataPackSchema()
+          this.changeDataPackSchema(value)
         } else if (
         } else if (
           productGroupKeyMap.marketingProduct.includes(type) || 
           productGroupKeyMap.marketingProduct.includes(type) || 
           productGroupKeyMap.ggProduct.includes(type) || 
           productGroupKeyMap.ggProduct.includes(type) || 
           productGroupKeyMap.entityProduct.includes(type)
           productGroupKeyMap.entityProduct.includes(type)
         ) {
         ) {
-          this.changeMarketingSchema()
+          this.changeMarketingSchema(value)
         } else {
         } else {
           console.log('未配置更新规则')
           console.log('未配置更新规则')
         }
         }
-        this.checkSchemaRule()
+        this.checkSchemaRule(value)
       })
       })
     },
     },
     commonGroupChangeSchema() {
     commonGroupChangeSchema() {
@@ -655,6 +661,18 @@ export default {
       // 1付费类型为“续费”,默认为关联订单的产品规格,不支持修改;
       // 1付费类型为“续费”,默认为关联订单的产品规格,不支持修改;
       // 2付费类型为“升级”且“升级内容”仅为“增购子账号”,默认为关联订单的产品规格,其他产品规格不展示;
       // 2付费类型为“升级”且“升级内容”仅为“增购子账号”,默认为关联订单的产品规格,其他产品规格不展示;
       // 3付费类型为“升级”且“升级内容”有“补充服务”或为空,仅可选择不低于关联订单的产品规格(注:特殊处理,大会员自定义版默认展示),其他产品规格不展示。
       // 3付费类型为“升级”且“升级内容”有“补充服务”或为空,仅可选择不低于关联订单的产品规格(注:特殊处理,大会员自定义版默认展示),其他产品规格不展示。
+      if (payment === 2) {
+        // 续费,默认为关联订单的产品规格,不支持修改;
+        // 1. 恢复规格
+        // 2. 如果有已选中关联订单,禁用规格
+
+
+      } else if (payment === 3) {
+        // 2付费类型为“升级”且“升级内容”仅为“增购子账号”,默认为关联订单的产品规格,其他产品规格不展示;
+      // 3付费类型为“升级”且“升级内容”有“补充服务”或为空,仅可选择不低于关联订单的产品规格(注:特殊处理,大会员自定义版默认展示),其他产品规格不展示。
+      }
+
+
       ma.show = ma.props.options.length > 1
       ma.show = ma.props.options.length > 1
     },
     },
     cjdyChangeSpecificationSchema() {
     cjdyChangeSpecificationSchema() {
@@ -663,10 +681,32 @@ export default {
       // const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
       // const ma = this.getSchemaItemWithKey(schemaKeyMap.payment)
     },
     },
     onChangedFields(changedArr) {
     onChangedFields(changedArr) {
-      // 付费类型
-      if (changedArr.includes(schemaKeyMap.payment)) {}
+      if (this.checkNeedRefreshPrice(changedArr)) {
+        this.getPriceRequest()
+      }
+      if (changedArr.includes('saleGifts')) {
+        // 销售策略变更,清空有效周期(通用规则)
+        this.refreshValue({ validityPeriod: {} })
+      }
       console.log('以下字段变更了:', changedArr)
       console.log('以下字段变更了:', changedArr)
-    }
+    },
+    checkNeedRefreshPrice(changedArr) {
+      const commonPassField = [
+        'saleGifts',
+        schemaKeyMap.payment,
+        schemaKeyMap.specification,
+        'validityPeriod',
+      ]
+
+      const type = this.productType
+      if (type === productKeyMap.dhy) {
+        commonPassField.push(schemaKeyMap.serviceList)
+      } else if (productGroupKeyMap.dataCountProduct.includes(type)) {
+        commonPassField.push(schemaKeyMap.validityCount)
+      }
+      const ins = this.getIntersection(commonPassField, changedArr)
+      return ins.length > 0
+    },
   }
   }
 }
 }
 </script>
 </script>