mlchen 3 days ago
parent
commit
594242e73c

+ 8 - 10
src/BIZComponents/inventoryTable.vue

@@ -1008,7 +1008,11 @@
   import fileUpload from '@/components/upload/fileUpload';
   import headList from '@/BIZComponents/user-select/user-select.vue';
   import ProductionVersion from '@/components/ProductionVersion2/index.vue';
-  import { getInventoryTotalAPI } from '@/api/wms';
+  import {
+    getInventoryTotalAPI,
+    buildInventoryTotalQueryKey,
+    matchInventoryTotal
+  } from '@/api/wms';
   import { pricingWayList, lbjtList } from '@/enum/dict.js';
   import {
     changeCount,
@@ -2339,21 +2343,15 @@
 
           let codeList = this.form.datasource
             .filter((item) => item.productCode)
-            .map((item) =>
-              item.batchNo
-                ? [item.productCode, item.batchNo].join(',')
-                : item.productCode
-            );
+            .map((item) => buildInventoryTotalQueryKey(item));
           //获取仓库库存
           let inventoryTotalList = await getInventoryTotalAPI(codeList);
           this.form.datasource
             .filter((item) => item.productCode)
             .forEach((item, index) => {
               let find =
-                inventoryTotalList.find(
-                  (key) =>
-                    key.code + ',' + key.batchNo ==
-                    item.productCode + ',' + item.batchNo
+                inventoryTotalList.find((key) =>
+                  matchInventoryTotal(item, key)
                 ) || {};
               this.form.datasource;
               if (this.showStockCount) {

+ 27 - 10
src/BIZComponents/inventoryTableDetails.vue

@@ -132,7 +132,11 @@
   import timeDialog from '@/components/timeDialog/index.vue';
   import tabMixins from '@/mixins/tableColumnsMixin';
   import { levelList, pricingWayList, quoteTypeOp } from '@/enum/dict.js';
-  import { getInventoryTotalAPI } from '@/api/wms';
+  import {
+    getInventoryTotalAPI,
+    buildInventoryTotalQueryKey,
+    matchInventoryTotal
+  } from '@/api/wms';
   import { getSummaries } from '@/utils/util.js';
   import { getAllQuantity } from '@/BIZComponents/setProduct.js';
 
@@ -540,10 +544,18 @@
           },
           {
             minWidth: 160,
-            prop: 'availableCountBase',
+            prop: 'stockCountBase',
             label: '库存数量',
             showOverflowTooltip: true,
             align: 'center',
+            isNone: !this.isWms
+          },
+          {
+            minWidth: 160,
+            prop: 'availableCountBase',
+            label: this.isWms ? '可用数量' : '库存数量',
+            showOverflowTooltip: true,
+            align: 'center',
           },
           {
             minWidth: 140,
@@ -1077,22 +1089,27 @@
           }
           if (this.isWms) {
             let codeList = this.form.datasource
-            .filter((item) => item.productCode)
-            .map((item) => item.batchNo ? [item.productCode, item.batchNo].join(',') : item.productCode);
+              .filter((item) => item.productCode)
+              .map((item) => buildInventoryTotalQueryKey(item));
             //获取仓库库存
             let inventoryTotalList = await getInventoryTotalAPI(codeList);
             this.form.datasource
               .filter((item) => item.productCode)
-              .forEach((item, index) => {
+              .forEach((item) => {
                 let find =
-                  inventoryTotalList.find(
-                                    (key) => (key.code + ',' + key.batchNo == item.productCode+','+item.batchNo)
-                                  ) || {};
+                  inventoryTotalList.find((key) =>
+                    matchInventoryTotal(item, key)
+                  ) || {};
                 this.form.datasource;
                 this.$set(
-                  this.form.datasource[index],
+                  item,
+                  'stockCountBase',
+                  find.stockCountBase == null ? 0 : find.stockCountBase
+                );
+                this.$set(
+                  item,
                   'availableCountBase',
-                  find.availableCountBase
+                  find.availableCountBase == null ? 0 : find.availableCountBase
                 );
               });
           }

+ 60 - 1
src/api/wms/index.js

@@ -14,6 +14,65 @@ export async function getInventoryTotalAPI(data) {
   return Promise.reject(new Error(res.data.message));
 }
 
+/**
+ * 生成库存统计查询键;传入字符串时保持旧格式原样透传。
+ */
+export function buildInventoryTotalQueryKey(value, batchNo, systemBatchNo) {
+  if (typeof value === 'string') {
+    return value;
+  }
+  const item = value || {};
+  const code = item.productCode || item.code || '';
+  const resolvedBatchNo = batchNo !== undefined ? batchNo : item.batchNo;
+  const resolvedSystemBatchNo =
+    systemBatchNo !== undefined ? systemBatchNo : item.systemBatchNo;
+  if (!code) {
+    return '';
+  }
+  const keyParts = [code];
+  if (
+    resolvedBatchNo !== undefined &&
+    resolvedBatchNo !== null &&
+    resolvedBatchNo !== ''
+  ) {
+    keyParts.push(resolvedBatchNo);
+    if (
+      resolvedSystemBatchNo !== undefined &&
+      resolvedSystemBatchNo !== null &&
+      resolvedSystemBatchNo !== ''
+    ) {
+      keyParts.push(resolvedSystemBatchNo);
+    }
+  }
+  return keyParts.join(',');
+}
+
+/**
+ * 按物品编码、业务批次和系统批次匹配库存统计结果。
+ */
+export function matchInventoryTotal(item, result) {
+  if (!item || !result) {
+    return false;
+  }
+  const code = item.productCode || item.code;
+  if (!code || String(result.code) !== String(code)) {
+    return false;
+  }
+  const itemBatchNo = item.batchNo == null ? '' : String(item.batchNo);
+  const resultBatchNo = result.batchNo == null ? '' : String(result.batchNo);
+  if (resultBatchNo !== itemBatchNo) {
+    return false;
+  }
+  const itemSystemBatchNo =
+    item.systemBatchNo == null ? '' : String(item.systemBatchNo);
+  const resultSystemBatchNo =
+    result.systemBatchNo == null ? '' : String(result.systemBatchNo);
+  if (resultSystemBatchNo !== itemSystemBatchNo) {
+    return false;
+  }
+  return true;
+}
+
 export async function getSubPage(data) {
   const res = await request.get('/main/categoryLevel/getSubPage', {
     params: data
@@ -278,4 +337,4 @@ export async function getCategoryPackageDisposition (data){
       return res.data.data;
     }
     return Promise.reject(new Error(res.data.message));
-  }
+  }