Bladeren bron

fix:5464【销售订单-发货单】发货操作,库存台账跟替代料库存台账查询界面,库存数跟仓储库存台账不一致

mlchen 1 maand geleden
bovenliggende
commit
baf2a308d5
1 gewijzigde bestanden met toevoegingen van 34 en 33 verwijderingen
  1. 34 33
      src/BIZComponents/selectStockLedger/selectStockLedgerDialog.vue

+ 34 - 33
src/BIZComponents/selectStockLedger/selectStockLedgerDialog.vue

@@ -184,13 +184,7 @@
             align: 'center',
             reserveSelection: true,
             selectable: (row) => {
-              if (this.showStockCount) {
-                return this.getAvailableStockCount(row) != 0;
-              }
-              const measureQuantity = parseFloat(row.measureQuantity) || 0;
-              const lockQuantity = parseFloat(row.lockQuantity) || 0;
-              const available = measureQuantity - lockQuantity;
-              return available != 0;
+              return this.getAvailableStockCount(row) != 0;
             }
           };
         }
@@ -303,10 +297,7 @@
             showOverflowTooltip: true,
             align: 'center',
             minWidth: 90,
-            formatter: (row) =>
-              this.showStockCount
-                ? this.getStockCount(row)
-                : row.measureQuantity
+            formatter: (row) => this.getStockCount(row)
           },
           {
             prop: 'lockQuantity',
@@ -322,15 +313,7 @@
             align: 'center',
             minWidth: 90,
             formatter: (row) => {
-              if (this.showStockCount) {
-                return this.getAvailableStockCount(row);
-              }
-              // 使用toFixed处理浮点数精度问题,保留4位小数
-              const measureQuantity = parseFloat(row.measureQuantity) || 0;
-              const lockQuantity = parseFloat(row.lockQuantity) || 0;
-              const available = measureQuantity - lockQuantity;
-              // 使用toFixed避免精度丢失,然后去除末尾多余的0
-              return available.toFixed(4).replace(/\.?0+$/, '');
+              return this.getAvailableStockCount(row);
             }
           },
           {
@@ -412,14 +395,33 @@
           pageNum: page,
           size: limit
         });
-        // 库存接口在同一物品/批次存在多条台账时可能返回重复 id。
-        // id 仍作为业务主键保留,表格使用仅用于渲染的唯一 key,避免 Vue patch 冲突。
+        // 与 WMS 库存台账保持一致:库存取 stockCountBase,旧接口无该字段时回退 measureQuantity;
+        // 可用数量按库存减锁库数量计算,并统一将负数归零。
         if (data && Array.isArray(data.list)) {
-          data.list = data.list.map((item, index) => ({
-            ...item,
-            _tableRowKey: `${item.id || 'row'}_${page}_${index}`
-          }));
+          data.list = data.list.map((item, index) => {
+            const stockCountBase = Math.max(
+              Number(
+                item.stockCountBase !== undefined && item.stockCountBase !== null
+                  ? item.stockCountBase
+                  : item.measureQuantity
+              ) || 0,
+              0
+            );
+            const lockQuantity = Number(item.lockQuantity) || 0;
+            const availableCountBase = Math.max(
+              stockCountBase - lockQuantity,
+              0
+            );
+            return {
+              ...item,
+              stockCountBase,
+              availableCountBase,
+              _tableRowKey: `${item.id || 'row'}_${page}_${index}`
+            };
+          });
         }
+        // 库存接口在同一物品/批次存在多条台账时可能返回重复 id。
+        // id 仍作为业务主键保留,表格使用仅用于渲染的唯一 key,避免 Vue patch 冲突。
         this.getTabColumns();
         return data;
       },
@@ -476,16 +478,15 @@
         return Number(row.measureQuantity || 0);
       },
       getAvailableStockCount(row) {
-        const available =
-          this.getStockCount(row) - Number(row.lockQuantity || 0);
-        return Number(available.toFixed(4));
+        if (row.availableCountBase !== undefined && row.availableCountBase !== null) {
+          return Number(row.availableCountBase);
+        }
+        const available = this.getStockCount(row) - Number(row.lockQuantity || 0);
+        return Math.max(Number(available.toFixed(4)), 0);
       },
       // 限制订单数量不超过当前可用数量
       handleSaleCountInput(row) {
-        const available = this.showStockCount
-          ? this.getAvailableStockCount(row)
-          : (parseFloat(row.measureQuantity) || 0) -
-            (parseFloat(row.lockQuantity) || 0);
+        const available = this.getAvailableStockCount(row);
         const val = parseFloat(row.saleCount);
         if (!isNaN(val) && val > available) {
           this.$message.warning(`订单数量不能超过可用数量(${available})`);