Переглянути джерело

fix:如果没有仓库优先物品配置的默认仓库,兜底才是仓库定义里面配置的类型

mlchen 1 тиждень тому
батько
коміт
5880ffcc20

+ 11 - 0
src/api/main/index.js

@@ -90,3 +90,14 @@ export async function getGroupUserTree(params) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+/**
+ * 根据物品id获取物品主数据里配置的默认仓库id(未配置返回 null)
+ */
+export async function getDefaultWarehouseId(id) {
+  const res = await request.get(`/main/category/getDefaultWarehouseId/${id}`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 64 - 4
src/views/purchasingManage/purchaseOrder/invoice/components/inventoryTable.vue

@@ -420,7 +420,10 @@
   import outboundDetailsDialog from './outboundDetailsDialog.vue';
   import taskinstanceDialog from '@/BIZComponents/procedure/taskinstanceDialog.vue';
   import { lbjtList, orderSourceType, pricingWayList } from '@/enum/dict.js';
-  import { parameterGetByCode } from '@/api/main/index.js';
+  import {
+    getDefaultWarehouseId,
+    parameterGetByCode
+  } from '@/api/main/index.js';
   import tabMixins from '@/mixins/tableColumnsMixin';
   import productListMain from '@/BIZComponents/product-list.vue';
   import warehouseAll from '@/BIZComponents/warehouseAll.vue';
@@ -881,7 +884,9 @@
         ],
         isTotalCount: 0, //采购收货数量是否限制不能大于采购总数 //0否 1是
         isBatchNo: 0,
-        isWarehouseId: 0
+        isWarehouseId: 0,
+        // 物品默认仓库缓存(物品ID -> 默认仓库ID),避免同一物品多行重复请求
+        defaultWarehouseCache: {}
       };
     },
     created() {
@@ -918,9 +923,21 @@
         if (row.warehouseId) {
           data = this.warehouseList.find((item) => item.id == row.warehouseId);
         } else {
-          data = this.warehouseList.find(
-            (item) => item.inventoryType == row.categoryRootLevelId
+          // 优先取物品主数据中的默认仓库,未配置时按仓库定义中的物品类型兜底
+          const defaultWarehouseId = await this.loadDefaultWarehouseId(
+            row.productId
           );
+          if (defaultWarehouseId) {
+            data = this.warehouseList.find(
+              (item) =>
+                item.id == defaultWarehouseId && this.warehouseUsable(item)
+            );
+          }
+          if (!data) {
+            data = this.warehouseList.find((item) =>
+              this.warehouseMatchInventoryType(item, row.categoryRootLevelId)
+            );
+          }
         }
         if (data) {
           this.$set(this.form.datasource[index], 'warehouseName', data.name);
@@ -928,6 +945,49 @@
           this.$set(this.form.datasource[index], 'warehouseId', data.id);
         }
       },
+      // 取物品默认仓库(物品主数据-仓储配置),按物品缓存
+      async loadDefaultWarehouseId(productId) {
+        if (!productId) return null;
+        if (
+          Object.prototype.hasOwnProperty.call(
+            this.defaultWarehouseCache,
+            productId
+          )
+        ) {
+          return this.defaultWarehouseCache[productId];
+        }
+        let warehouseId = null;
+        try {
+          warehouseId = await getDefaultWarehouseId(productId);
+        } catch (e) {
+          warehouseId = null;
+        }
+        this.defaultWarehouseCache[productId] = warehouseId || null;
+        return this.defaultWarehouseCache[productId];
+      },
+      // 仓库可用:未返回状态视为可用;已停用的默认仓库不采用,回退到物品类型匹配
+      warehouseUsable(warehouse) {
+        if (!warehouse) return false;
+        if (warehouse.status === undefined || warehouse.status === null) {
+          return true;
+        }
+        return warehouse.status == 1;
+      },
+      // 仓库定义的物品类型(逗号分隔)是否包含该行根级分类
+      warehouseMatchInventoryType(warehouse, categoryRootLevelId) {
+        if (!warehouse || !warehouse.inventoryType) return false;
+        if (
+          categoryRootLevelId === undefined ||
+          categoryRootLevelId === null ||
+          categoryRootLevelId === ''
+        ) {
+          return false;
+        }
+        return String(warehouse.inventoryType)
+          .split(',')
+          .map((item) => String(item).trim())
+          .includes(String(categoryRootLevelId));
+      },
       warehouseAllChange(data) {
         console.log(this.selection, 'this.selection');
         let keyS = this.selection.map((item) => item.key - 1);

+ 64 - 4
src/views/saleManage/saleOrder/entrustedReceive/components/inventoryTable.vue

@@ -279,7 +279,10 @@
   import warehouseAll from '@/BIZComponents/warehouseAll.vue';
   import { pricingWayList } from '@/enum/dict';
   import tabMixins from '@/mixins/tableColumnsMixin';
-  import { parameterGetByCode } from '@/api/main/index.js';
+  import {
+    getDefaultWarehouseId,
+    parameterGetByCode
+  } from '@/api/main/index.js';
 
   export default {
     mixins: [dictMixins, tabMixins],
@@ -599,7 +602,9 @@
             showOverflowTooltip: true
           }
         ],
-        isBatchNo: 0
+        isBatchNo: 0,
+        // 物品默认仓库缓存(物品ID -> 默认仓库ID),避免同一物品多行重复请求
+        defaultWarehouseCache: {}
       };
     },
     created() {
@@ -627,9 +632,21 @@
         if (row.warehouseId) {
           data = this.warehouseList.find((item) => item.id == row.warehouseId);
         } else {
-          data = this.warehouseList.find(
-            (item) => item.inventoryType == row.categoryRootLevelId
+          // 优先取物品主数据中的默认仓库,未配置时按仓库定义中的物品类型兜底
+          const defaultWarehouseId = await this.loadDefaultWarehouseId(
+            row.productId
           );
+          if (defaultWarehouseId) {
+            data = this.warehouseList.find(
+              (item) =>
+                item.id == defaultWarehouseId && this.warehouseUsable(item)
+            );
+          }
+          if (!data) {
+            data = this.warehouseList.find((item) =>
+              this.warehouseMatchInventoryType(item, row.categoryRootLevelId)
+            );
+          }
         }
         if (data) {
           this.$set(this.form.datasource[index], 'warehouseName', data.name);
@@ -637,6 +654,49 @@
           this.$set(this.form.datasource[index], 'warehouseId', data.id);
         }
       },
+      // 取物品默认仓库(物品主数据-仓储配置),按物品缓存
+      async loadDefaultWarehouseId(productId) {
+        if (!productId) return null;
+        if (
+          Object.prototype.hasOwnProperty.call(
+            this.defaultWarehouseCache,
+            productId
+          )
+        ) {
+          return this.defaultWarehouseCache[productId];
+        }
+        let warehouseId = null;
+        try {
+          warehouseId = await getDefaultWarehouseId(productId);
+        } catch (e) {
+          warehouseId = null;
+        }
+        this.defaultWarehouseCache[productId] = warehouseId || null;
+        return this.defaultWarehouseCache[productId];
+      },
+      // 仓库可用:未返回状态视为可用;已停用的默认仓库不采用,回退到物品类型匹配
+      warehouseUsable(warehouse) {
+        if (!warehouse) return false;
+        if (warehouse.status === undefined || warehouse.status === null) {
+          return true;
+        }
+        return warehouse.status == 1;
+      },
+      // 仓库定义的物品类型(逗号分隔)是否包含该行根级分类
+      warehouseMatchInventoryType(warehouse, categoryRootLevelId) {
+        if (!warehouse || !warehouse.inventoryType) return false;
+        if (
+          categoryRootLevelId === undefined ||
+          categoryRootLevelId === null ||
+          categoryRootLevelId === ''
+        ) {
+          return false;
+        }
+        return String(warehouse.inventoryType)
+          .split(',')
+          .map((item) => String(item).trim())
+          .includes(String(categoryRootLevelId));
+      },
       warehouseAllChange(data) {
         let keyS = this.selection.map((item) => item.key - 1);
         keyS.forEach((key) => {

+ 3 - 3
vue.config.js

@@ -2,7 +2,7 @@
  * @Author: mlchen 374826075@qq.com
  * @Date: 2026-07-22 15:43:30
  * @LastEditors: mlchen 374826075@qq.com
- * @LastEditTime: 2026-11-05 10:43:30
+ * @LastEditTime: 2026-11-09 11:07:58
  * @FilePath: /kd-aiot-frontend-eom/vue.config.js
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
@@ -45,12 +45,12 @@ module.exports = {
       // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
       '/api': {
         // target: 'http://192.168.1.251:18086', //开发
-        // target: 'http://localhost:18086', //开发 // 本地联调临时指向本机后端(2026-11-05,联调后还原)
+        target: 'http://localhost:18086', //开发 // 本地联调临时指向本机后端(2026-11-05,联调后还原)
         // target: 'http://192.168.1.251:18186', //测试
         // target: 'http://192.168.1.15:18086',//罗
         // target: 'http://192.168.1.144:18086',//付
         // target: 'http://192.168.1.10:18086', //付
-        target: 'http://aiot.zoomwin.com.cn:51001/api',
+        // target: 'http://aiot.zoomwin.com.cn:51001/api',
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
         pathRewrite: {
           '^/api': ''