浏览代码

feat: 产品信息数据源迁移到store

cuiyalong 4 月之前
父节点
当前提交
be9e302ac2

+ 10 - 0
src/store/order.js

@@ -317,6 +317,16 @@ export default {
         s[key] = data
       }
     },
+    // 更新productCardInfo.form/.result/.info
+    refreshOrderProductItemCardForm(state, payload = {}) {
+      const { index, data, key } = payload
+      if (index === undefined || index === null) return
+      if (!data) return
+      const s = state.orderInfo.productInfoList[index]
+      if (s) {
+        s.productCardInfo[key] = data
+      }
+    },
   },
   actions: {
     // 获取产品备选项信息

+ 48 - 24
src/views/create-order/components/ProductInfoCard.vue

@@ -4,18 +4,19 @@
       <el-row :gutter="2">
         <el-col :span="24">
           <ProductTypeSelector
-            v-model="productTypeResult"
             :productTypeOptions="productTypeOptions"
+            :value="productTypeResult"
+            @input="onProductionInput"
             @change="onProductionChange"
           />
         </el-col>
       </el-row>
-      <el-row :gutter="2" v-if="productTypeResult.productCode">
+      <el-row :gutter="2" v-if="productTypeResult && productTypeResult.productCode">
         <el-col :span="24">
           <ProductSchemaForm
             :productType="productTypeResult.productCode"
             :productInfo="productTypeInfo"
-            v-model="form"
+            :value="productForm"
             :index="index"
             @input="onSchemaFormChange"
           />
@@ -49,25 +50,61 @@ export default {
   },
   data() {
     return {
-      productTypeResult: {
-        productCode: '',
-        activityCode: '',
-      },
-      productTypeInfo: {},
-      form: {}
+      // productTypeResult: {
+      //   productCode: '',
+      //   activityCode: '',
+      // },
+      // productTypeInfo: {},
+      // form: {}
     }
   },
   computed: {
     ...mapState({
       productTypeOptions: state => state.order.productList,
+      productInfoList: state => state.order.orderInfo.productInfoList,
     }),
+    productInfoListItem() {
+      return this.productInfoList[this.index]?.productCardInfo || {}
+    },
+    productTypeInfo(){
+      return this.productInfoListItem.info || {}
+    },
+    productForm() {
+      return this.productInfoListItem.form || {}
+    },
+    productTypeResult() {
+      return this.productInfoListItem.result || {
+        productCode: '',
+        activityCode: '',
+      }
+    },
   },
   methods: {
     onProductionChange(e) {
-      this.productTypeInfo = e.info
+      // this.productTypeInfo = e.info
+      const p = {
+        key: 'info',
+        data: e.info,
+        index: this.index,
+      }
+      this.$store.commit('order/refreshOrderProductItemCardForm', p)
       this.onChange()
     },
-    onSchemaFormChange() {
+    onProductionInput(e) {
+      const p = {
+        key: 'result',
+        data: e,
+        index: this.index,
+      }
+      this.$store.commit('order/refreshOrderProductItemCardForm', p)
+    },
+    onSchemaFormChange(e) {
+      const p = {
+        key: 'form',
+        data: e,
+        index: this.index,
+      }
+      this.$store.commit('order/refreshOrderProductItemCardForm', p)
       this.onChange()
     },
     getState() {
@@ -78,19 +115,6 @@ export default {
       }
       return JSON.parse(JSON.stringify(p))
     },
-    setState(t) {
-      if (!t) return
-      const { result: e, info, form } = t
-      if (e) {
-        this.productTypeResult = e
-      }
-      if (info) {
-        this.productTypeInfo = info
-      }
-      if (form) {
-        this.form = form
-      }
-    },
     onChange() {
       const payload = this.getState()
       this.$emit('change', payload)

+ 0 - 9
src/views/create-order/components/ProductInfoCardList.vue

@@ -18,7 +18,6 @@
         <ProductInfoCard
           ref="productInfoCard"
           :index="index"
-          @change="onProductInfoCardChange($event, index)"
           @power="onProductInfoCardPowerCheck($event, index)"
         />
       </template>
@@ -107,14 +106,6 @@ export default {
       const t = this.productCardList[index]
       return t.activityCode
     },
-    onProductInfoCardChange(e, index) {
-      const p = {
-        key: 'productCardInfo',
-        data: e,
-        index,
-      }
-      this.$store.commit('order/refreshOrderProductItemCard', p)
-    },
     onProductInfoCardPowerCheck(e, index) {
       const p = {
         key: 'userService',