695593266@qq.com 5 сар өмнө
parent
commit
ba78268ad2

+ 79 - 83
src/views/produce/components/picking/index.vue

@@ -522,105 +522,101 @@
         // }
       },
 
-      changeInput(item, index) {
-        if (Number(item.demandQuantity) >= Number(item.availableCountBase)) {
-          this.$set(
-            this.workList[0].pickList[index],
-            'demandQuantity',
-            Number(item.availableCountBase)
-          );
-          const idsList = [];
-          item.warehouseList.forEach((it) => {
-            idsList.push(it.warehouse_id);
-          });
-          this.$set(
-            this.workList[0].pickList[index],
-            'warehouseIdList',
-            idsList
-          );
-        } else if (!Number(item.demandQuantity)) {
-          this.$set(this.workList[0].pickList[index], 'warehouseIdList', []);
-        } else {
-          const idsList = [];
-          let totalNum = 0;
-
-          for (let i = 0; i < item.warehouseList.length; i++) {
-            totalNum += Number(item.warehouseList[i].availableCountBase);
-
-            if (Number(item.demandQuantity) > totalNum) {
-              idsList.push(item.warehouseList[i].warehouse_id);
-            } else {
-              idsList.push(item.warehouseList[i].warehouse_id);
-              break;
-            }
-          }
-
-          this.$set(
-            this.workList[0].pickList[index],
-            'warehouseIdList',
-            idsList
-          );
-        }
-      },
-
       // changeInput(item, index) {
-      //   const pickItem = this.workList[0].pickList[index];
+      //   if (Number(item.demandQuantity) >= Number(item.availableCountBase)) {
+      //     this.$set(
+      //       this.workList[0].pickList[index],
+      //       'demandQuantity',
+      //       Number(item.availableCountBase)
+      //     );
+      //     const idsList = [];
+      //     item.warehouseList.forEach((it) => {
+      //       idsList.push(it.warehouse_id);
+      //     });
+      //     this.$set(
+      //       this.workList[0].pickList[index],
+      //       'warehouseIdList',
+      //       idsList
+      //     );
+      //   } else if (!Number(item.demandQuantity)) {
+      //     this.$set(this.workList[0].pickList[index], 'warehouseIdList', []);
+      //   } else {
+      //     const idsList = [];
+      //     let totalNum = 0;
+
+      //     for (let i = 0; i < item.warehouseList.length; i++) {
+      //       totalNum += Number(item.warehouseList[i].availableCountBase);
+
+      //       if (Number(item.demandQuantity) > totalNum) {
+      //         idsList.push(item.warehouseList[i].warehouse_id);
+      //       } else {
+      //         idsList.push(item.warehouseList[i].warehouse_id);
+      //         break;
+      //       }
+      //     }
 
-      //   let value = String(item.demandQuantity ?? '');
+      //     this.$set(
+      //       this.workList[0].pickList[index],
+      //       'warehouseIdList',
+      //       idsList
+      //     );
+      //   }
+      // },
 
-      //   value = value.replace(/[^\d.]/g, '');
+      changeInput(item, index) {
+        const pickItem = this.workList[0].pickList[index];
 
-      //   value = value
-      //     .replace(/\.{2,}/g, '.')
-      //     .replace('.', '$#$')
-      //     .replace(/\./g, '')
-      //     .replace('$#$', '.');
+        let value = String(item.demandQuantity ?? '');
 
-      //   if (value.includes('.')) {
-      //     const [intPart, decPart] = value.split('.');
-      //     value = `${intPart}.${decPart.slice(0, 4)}`;
-      //   }
+        value = value.replace(/[^\d.]/g, '');
 
-      //   console.log(value, 'value');
+        value = value
+          .replace(/\.{2,}/g, '.')
+          .replace('.', '$#$')
+          .replace(/\./g, '')
+          .replace('$#$', '.');
 
-      //   this.$set(pickItem, 'demandQuantity', value);
+        if (value.includes('.')) {
+          const [intPart, decPart] = value.split('.');
+          value = `${intPart}.${decPart.slice(0, 4)}`;
+        }
 
-      //   console.log(pickItem, 'pickItem');
+        this.$set(pickItem, 'demandQuantity', value);
 
-      //   const demandQty = Number(value);
-      //   console.log(demandQty, 'demandQty');
-      //   const maxQty = Number(item.availableCountBase) || 0;
-      //   console.log(item, 'item');
-      //   console.log(maxQty, 'maxQty');
+        const demandQty = Number(value);
+        const maxQty = item.warehouseList.reduce((sum, cur) => {
+          return sum + Number(cur.availableCountBase || 0);
+        }, 0);
+        // const maxQty = Number(item.availableCountBase) || 0;
 
-      //   if (!demandQty) {
-      //     this.$set(pickItem, 'warehouseIdList', []);
-      //     return;
-      //   }
+        if (!demandQty) {
+          this.$set(pickItem, 'warehouseIdList', []);
+          return;
+        }
 
-      //   if (demandQty >= maxQty) {
-      //     this.$set(pickItem, 'demandQuantity', maxQty);
+        if (demandQty >= maxQty) {
+          this.$set(pickItem, 'demandQuantity', maxQty);
 
-      //     this.$set(
-      //       pickItem,
-      //       'warehouseIdList',
-      //       item.warehouseList.map((w) => w.warehouse_id)
-      //     );
-      //     return;
-      //   }
+          this.$set(
+            pickItem,
+            'warehouseIdList',
+            item.warehouseList.map((w) => w.warehouse_id)
+          );
+          return;
+        }
 
-      //   let total = 0;
-      //   const idsList = [];
+        let total = 0;
+        const idsList = [];
 
-      //   for (const w of item.warehouseList) {
-      //     total += Number(w.availableCountBase) || 0;
-      //     idsList.push(w.warehouse_id);
+        for (const w of item.warehouseList) {
+          total += Number(w.availableCountBase) || 0;
+          idsList.push(w.warehouse_id);
 
-      //     if (total >= demandQty) break;
-      //   }
+          if (total >= demandQty) break;
+        }
 
-      //   this.$set(pickItem, 'warehouseIdList', idsList);
-      // },
+        this.$set(pickItem, 'warehouseIdList', idsList);
+      },
 
       detailData(data, dimension, index) {
         const itemData = [];