Эх сурвалжийг харах

fix: 委外发货单按采购计划明细行回显默认仓库,并合并字典并发请求

lihaiting 5 өдөр өмнө
parent
commit
58b4661064

+ 14 - 15
src/store/modules/dict.js

@@ -14,7 +14,7 @@ import { getByCode } from '@/api/system/dictionary-data';
 
 const state = {};
 
-// dedupe 模式下同一字典的并发请求合并使用,避免表格多实例重复打接口
+// 同一字典的并发请求合并使用,避免表格多实例重复打接口
 const inflightDicts = {};
 
 const mutations = {
@@ -26,16 +26,17 @@ const mutations = {
 
 const actions = {
   // 根据字典enumName请求字典 已获取的不做重复请求
-  // payload 支持两种形式:'字典名' 或 { enumName: '字典名', dedupe: true }
-  // dedupe 为 true 时,合并同一字典的并发请求(表格里同一个字典有 N 个实例时只发一次)
+  // 同一字典的并发请求统一合并(表格里同列多个下拉同时挂载时只发一次接口)
+  // payload 支持 '字典名' 或 { enumName: '字典名' },后者为兼容旧调用保留
   async requestDict({ commit, state }, payload) {
-    const { enumName, dedupe } =
+    const { enumName } =
       typeof payload === 'string' ? { enumName: payload } : payload || {};
 
     const code = dictEnum[enumName];
 
+    if (!code) return [];
     if (state[code]?.length) return state[code];
-    if (dedupe && inflightDicts[code]) return inflightDicts[code];
+    if (inflightDicts[code]) return inflightDicts[code];
     let res;
     // if (otherDictConfig[dictEnum[enumName]]) {
     //   const config = otherDictConfig[dictEnum[enumName]];
@@ -77,16 +78,14 @@ const actions = {
       return [];
     })();
 
-    if (dedupe) {
-      inflightDicts[code] = request;
-      request
-        .catch(() => {})
-        .finally(() => {
-          if (inflightDicts[code] === request) {
-            delete inflightDicts[code];
-          }
-        });
-    }
+    inflightDicts[code] = request;
+    request
+      .catch(() => {})
+      .finally(() => {
+        if (inflightDicts[code] === request) {
+          delete inflightDicts[code];
+        }
+      });
     return request;
   },
   // 更新字典

+ 6 - 1
src/views/purchasingManage/purchaseOrder/index.vue

@@ -812,7 +812,12 @@
           this.addOrEditDialogFlag = true;
 
           this.$nextTick(() => {
-            this.$refs.addOrEditDialogRef.open('add', {}, row.id);
+            this.$refs.addOrEditDialogRef.open(
+              'add',
+              {},
+              row.id,
+              row.purchasePlanId
+            );
           });
         }
         if (command === 'invoiceManage') {

+ 49 - 3
src/views/purchasingManage/purchaseOrder/outSourceSend/components/addOrEditDialog.vue

@@ -101,6 +101,7 @@
           ref="inventoryTableref"
           :orderId="form.orderId"
           :productType="1"
+          :planWarehouse="planWarehouse"
         ></inventoryTable>
       </el-tab-pane>
 
@@ -147,6 +148,7 @@
   import inventoryTable from './inventoryTable.vue';
   import orderListDialog from '../../invoice/components/orderListDialog.vue';
   import { getByIdCondition } from '@/api/purchasingManage/purchaseOrder';
+  import { getplanDetail } from '@/api/purchasingManage/purchasePlanManage';
   import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
   import { getWarehouseListByIds } from '@/api/purchasingManage/returnGoods';
   import taskInfoTable from '@/views/saleManage/saleOrder/invoice/components/taskInfoTable.vue';
@@ -213,16 +215,21 @@
         // 是否是修改
         isUpdate: false,
         processSubmitDialogFlag: false,
-        businessId: ''
+        businessId: '',
+        // 采购订单关联的采购计划 id / 计划回写的默认仓库映射(按产品匹配)
+        purchasePlanId: '',
+        planWarehouse: null
       };
     },
 
     methods: {
-      //打开新增编辑弹框
-      async open(type, row, orderId) {
+      //打开新增编辑弹框(purchasePlanId:采购订单关联的采购计划,用于带出默认仓库)
+      async open(type, row, orderId, purchasePlanId) {
         this.activeName = 'first';
         this.title = type === 'add' ? '新增委外发货单' : '修改';
         this.row = row;
+        this.purchasePlanId = purchasePlanId || '';
+        this.planWarehouse = null;
         if (orderId) {
           await this.getPurchaseOrderDetail(orderId);
         }
@@ -259,14 +266,53 @@
       },
       //选择订单回调
       changeOrder(obj) {
+        this.purchasePlanId = obj.purchasePlanId || '';
         this.getPurchaseOrderDetail(obj.id);
       },
+      //采购计划详情取回写的默认仓库,供物品清单预选仓库
+      // 仓库挂在 outputDetailList / detailList 的行上(warehouseId/warehouseName/warehouseCode),
+      // 不是计划顶层字段;按产品建立 产品id/类别id/产品编码 -> 仓库 的映射
+      async getPlanWarehouse(planId) {
+        if (!planId) return null;
+        try {
+          const plan = await getplanDetail(planId);
+          const list =
+            (plan?.outputDetailList?.length
+              ? plan.outputDetailList
+              : plan?.detailList) || [];
+          const warehouseMap = {};
+          list.forEach((item) => {
+            if (!item || !item.warehouseId) return;
+            const warehouse = {
+              warehouseId: item.warehouseId,
+              warehouseName: item.warehouseName || '',
+              warehouseCode: item.warehouseCode || ''
+            };
+            [item.productId, item.categoryId, item.productCode].forEach(
+              (key) => {
+                if (key) warehouseMap[String(key)] = warehouse;
+              }
+            );
+            // 计划行缺少产品标识时,整单共用一个默认仓库
+            if (!warehouseMap.__default) warehouseMap.__default = warehouse;
+          });
+          return Object.keys(warehouseMap).length ? warehouseMap : null;
+        } catch (error) {
+          console.warn('[outsourceSend] 采购计划仓库获取失败', error);
+          return null;
+        }
+      },
       //获取订单详情
       async getPurchaseOrderDetail(id) {
         this.loading = true;
         const data = await getByIdCondition(id, 1);
         this.loading = false;
         if (data) {
+          // 订单未直接带出仓库时,按关联采购计划回写的默认仓库预选明细行仓库
+          this.planWarehouse =
+            (await this.getPlanWarehouse(
+              this.purchasePlanId || data.purchasePlanId
+            )) || null;
           this.$nextTick(() => {
             let {
               partbId,

+ 58 - 8
src/views/purchasingManage/purchaseOrder/outSourceSend/components/inventoryTable.vue

@@ -268,7 +268,13 @@
         default: true
       },
       pricingWay: [Number, String],
-      productType: ''
+      productType: '',
+      // 采购计划回写的默认仓库映射(产品id/类别id/产品编码 -> warehouseId/warehouseName/warehouseCode):
+      // 委外发货单新增时优先按产品匹配预设明细行仓库,未命中时回退原有取第一个的逻辑
+      planWarehouse: {
+        type: Object,
+        default: null
+      }
     },
     components: {
       productList,
@@ -967,14 +973,58 @@
                 item.colorKey
               );
             }
+            const warehouseList =
+              (await getIdWarehouseList({ categoryId: item.productId })) || [];
+            // 采购计划回写的仓库(warehouseId/warehouseName/warehouseCode)优先回显,
+            // 不在该行可选仓库内时补到选项里,保证仓库名称按计划数据显示
+            // 按产品精确命中的计划仓库优先;整单默认仓库只在明细行自身没有仓库时使用
+            const specificWarehouse =
+              this.planWarehouse?.[String(item.productId)] ||
+              this.planWarehouse?.[String(item.categoryId)] ||
+              this.planWarehouse?.[String(item.productCode)];
+            const planWarehouse =
+              specificWarehouse ||
+              (item.warehouseId ? null : this.planWarehouse?.__default);
+            let planMatched = null;
+            if (planWarehouse?.warehouseId) {
+              planMatched =
+                warehouseList.find(
+                  (w) =>
+                    String(w.warehouseId) ===
+                    String(planWarehouse.warehouseId)
+                ) ||
+                // 列表里的仓库名带组织前缀,id 对不上时再按仓库编码匹配一次
+                warehouseList.find(
+                  (w) =>
+                    planWarehouse.warehouseCode &&
+                    String(w.warehouseCode) ===
+                      String(planWarehouse.warehouseCode)
+                ) || {
+                  warehouseId: planWarehouse.warehouseId,
+                  warehouseName: planWarehouse.warehouseName,
+                  warehouseCode: planWarehouse.warehouseCode
+                };
+              if (!warehouseList.includes(planMatched)) {
+                warehouseList.unshift(planMatched);
+              }
+            }
             this.$set(
               this.form.datasource[index],
               'warehouseList',
-              await getIdWarehouseList({
-                categoryId: item.productId
-              })
+              warehouseList
             );
-            if (item.warehouseId) {
+            if (planMatched) {
+              this.$set(
+                this.form.datasource[index],
+                'warehouseId',
+                planMatched.warehouseId
+              );
+              await this.warehouseChange(
+                index,
+                this.form.datasource[index],
+                planMatched
+              );
+            } else if (item.warehouseId) {
               this.$set(
                 this.form.datasource[index],
                 'warehouseNum',
@@ -983,16 +1033,16 @@
                   code: item.productCode
                 })
               );
-            } else if (this.form.datasource[index]?.warehouseList?.length) {
+            } else if (warehouseList.length) {
               this.$set(
                 this.form.datasource[index],
                 'warehouseId',
-                this.form.datasource[index]?.warehouseList[0].warehouseId
+                warehouseList[0].warehouseId
               );
               await this.warehouseChange(
                 index,
                 this.form.datasource[index],
-                this.form.datasource[index]?.warehouseList[0]
+                warehouseList[0]
               );
             }
             this.$set(