Explorar o código

feat(batchProductsBom): 增加选择项确认状态的监视器,优化数据过滤逻辑

xieyong hai 1 mes
pai
achega
c0c1c542ce

+ 14 - 0
src/views/produce/components/feeding/components/batchProductsBom.vue

@@ -214,6 +214,20 @@
       }
     },
 
+    watch: {
+      selection: {
+        handler(newSelection) {
+          this.list.forEach((item) => {
+            if (newSelection.includes(item)) {
+              this.$set(item, 'confirm', 1);
+            } else {
+              this.$set(item, 'confirm', 0);
+            }
+          });
+        }
+      }
+    },
+
     computed: {
       columns() {
         let action = {};

+ 29 - 11
src/views/produce/components/feeding/index.vue

@@ -996,28 +996,46 @@
         if (!isCache) {
           return false;
         }
-        this.loading = this.$loading({
-          lock: true,
-          text: '加载中',
-          background: 'rgba(0, 0, 0, 0.7)'
+
+        // 不修改 this.List,新建一个 filterList,内部 product 只保留 confirm === 1
+        const filterList = this.List.map((item) => {
+          return {
+            ...item,
+            product: Array.isArray(item.product)
+              ? item.product.filter((p) => p.confirm === 1)
+              : item.product
+          };
+        }).filter((item) => {
+          return Array.isArray(item.product) && item.product.length > 0;
         });
 
+        if(!filterList.length) return;
         let newList = [];
-        for (let item of this.List) {
+
+        for (let item of filterList) {
           newList.push({
             currentTaskDiagram: item.currentTaskDiagram,
             workOrderId: item.workOrderId
           });
         }
 
+        console.log("newList",newList);
+
+        this.loading = this.$loading({
+          lock: true,
+          text: '加载中',
+          background: 'rgba(0, 0, 0, 0.7)'
+        });
+       
+
         await checkRepeatFeed(newList).then((res) => {
           if (res.data.length != 0) {
-            this.checkFeed(res.data);
+            this.checkFeed(res.data, filterList);
           }
         });
       },
 
-      checkFeed(list) {
+      checkFeed(list, filterList) {
         let wordCodeList = [];
         for (let item of list) {
           if (item.feedFormed != '0') {
@@ -1037,18 +1055,18 @@
             }
           )
             .then(() => {
-              this.feedReport();
+              this.feedReport(filterList);
             })
             .catch(() => {
               this.loading.close();
             });
         } else {
-          this.feedReport();
+          this.feedReport(filterList);
         }
       },
 
-      feedReport() {
-        batchSave(this.List)
+      feedReport(filterList) {
+        batchSave(filterList)
           .then((res) => {
             this.loading.close();
             this.$message.success('投料成功');