Преглед изворни кода

fix:5393【销售订单-发货单】创建发货单,点击批次号,界面很多重复的

mlchen пре 4 недеља
родитељ
комит
ad75712bd0

+ 50 - 1
src/BIZComponents/inventoryTable.vue

@@ -2040,6 +2040,19 @@
         let comitDatasource = copyObj(this.form.datasource);
         if (comitDatasource.length === 0) return [];
         comitDatasource.forEach((v) => {
+          // 计量数量在后端是非空字段,库存台账多选等入口只带回销售数量,
+          // 未触发数量换算时会留空,提交前统一用销售数量兜底,避免提交报 SQL 错误
+          const saleCount = v[this.countObj.countKey];
+          if (
+            (v.totalCount === undefined ||
+              v.totalCount === null ||
+              v.totalCount === '') &&
+            saleCount !== undefined &&
+            saleCount !== null &&
+            saleCount !== ''
+          ) {
+            v.totalCount = saleCount;
+          }
           if (v.guaranteePeriodUnitCode) {
             v.guaranteePeriodUnitName = this.getDictValue(
               '保质期单位',
@@ -2589,6 +2602,8 @@
       },
       async replaceTable(obj, idx) {
         console.log('replaceTable', obj, idx);
+        // 先按物品ID去重并并行查询商品信息,避免逐行串行请求,物品较多时明显加快回显
+        const goodsMap = await this.loadGoodsByCategoryIds(obj);
         for (let index = 0; index < obj.length; index++) {
           const item = obj[index];
           let i = idx == -1 ? index : idx;
@@ -2639,7 +2654,7 @@
               ? this.defTaxRate
               : undefined
           );
-          let goodsData = await getGoodsByCategoryId(item.productId);
+          let goodsData = goodsMap.get(item.productId) || [];
           goodsData = goodsData.filter((item) => item.approvalStatus == 2);
           if (goodsData?.length) {
             let goodsPriceList = goodsData[0]?.goodsPriceList[0];
@@ -2716,10 +2731,44 @@
           }
         }
         // console.log(this.form.datasource);
+        // 计量数量为后端非空字段:只补齐留空的行,避免覆盖已按计量单位换算好的数据
+        this.form.datasource.forEach((item) => {
+          const count = item[this.countObj.countKey];
+          if (
+            (item.totalCount === undefined ||
+              item.totalCount === null ||
+              item.totalCount === '') &&
+            count !== undefined &&
+            count !== null &&
+            count !== ''
+          ) {
+            this.$set(item, 'totalCount', count);
+          }
+        });
         if (this.showSaleCount) {
           this.changeCount();
         }
       },
+      /**
+       * 批量查询物品对应的商品信息。
+       * 按物品ID去重后并行请求,替代逐行 await 的串行查询,
+       * 同一物品选中多行(多批次)时只请求一次。
+       */
+      async loadGoodsByCategoryIds(list) {
+        const goodsMap = new Map();
+        const productIds = [
+          ...new Set(
+            (list || []).map((item) => item.productId).filter((id) => id)
+          )
+        ];
+        await Promise.all(
+          productIds.map(async (productId) => {
+            const goodsList = await getGoodsByCategoryId(productId);
+            goodsMap.set(productId, goodsList || []);
+          })
+        );
+        return goodsMap;
+      },
       remove(index) {
         this.form.datasource.splice(index, 1);
         this.setSort();

+ 22 - 7
src/views/saleManage/saleOrder/invoice/components/inventoryTable.vue

@@ -107,8 +107,8 @@
               @change="batchNoChange(scope.$index, scope.row)"
             >
               <el-option
-                v-for="(item, optIndex) in scope.row.batchNoList || []"
-                :key="`${item.id}_${optIndex}`"
+                v-for="item in scope.row.batchNoList || []"
+                :key="item.id"
                 :label="item.batchNo"
                 :value="item.id"
               >
@@ -1093,6 +1093,16 @@
     },
     methods: {
       formatPrice,
+      dedupeBatchNoList(list) {
+        const seen = new Set();
+        return (list || []).filter((item) => {
+          if (seen.has(item.id)) {
+            return false;
+          }
+          seen.add(item.id);
+          return true;
+        });
+      },
       getSummaries(param) {
 
 
@@ -1205,7 +1215,7 @@
         this.$set(
           this.form.datasource[index],
           'batchNoList',
-          tempBatchNoList?.list || []
+          this.dedupeBatchNoList(tempBatchNoList?.list)
         );
 
         if (isReset) {
@@ -1500,7 +1510,11 @@
             size: -1
           });
 
-          this.$set(parasm, 'batchNoList', templist?.list);
+          this.$set(
+            parasm,
+            'batchNoList',
+            this.dedupeBatchNoList(templist?.list)
+          );
 
           console.log('parasm~~~~333', parasm);
 
@@ -1694,7 +1708,7 @@
               this.$set(
                 this.form.datasource[index],
                 'batchNoList',
-                templist?.list || []
+                this.dedupeBatchNoList(templist?.list)
               );
               // console.log(this.form.datasource[index]);
             } else {
@@ -1736,7 +1750,7 @@
             size: -1
           });
 
-          let tempBatchNoList = templist1?.list || [];
+          let tempBatchNoList = this.dedupeBatchNoList(templist1?.list);
           console.log('888~~~~', index, item.batchNo);
 
           // 优先按批次明细ID匹配,无ID时按系统批次和业务批次兼容匹配
@@ -1771,6 +1785,7 @@
               id: 999,
               measureQuantity: 0
             });
+            tempBatchNoList = this.dedupeBatchNoList(tempBatchNoList);
             // 设置为不存在的批次ID
             this.$set(this.form.datasource[index], 'batchStockId', 999);
             this.$set(this.form.datasource[index], 'warehouseNum', '');
@@ -1783,7 +1798,7 @@
           this.$set(
             this.form.datasource[index],
             'batchNoList',
-            tempBatchNoList
+            this.dedupeBatchNoList(tempBatchNoList)
           );
         } else {
           if (item.batchNo) {