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

feat(采购订单): 添加根据产品id获取供应商功能并优化产品选择回调

liujt 2 сар өмнө
parent
commit
ad79f55aca

+ 11 - 0
src/api/purchasingManage/purchaseOrder.js

@@ -136,6 +136,17 @@ export async function applyoutsource(id) {
   return Promise.reject(new Error(res.data.message));
 }
 
+/**
+ * 通过物品编码获取供应商
+ */
+export async function getSupplierInfo(productId) {
+  const res = await request.get(`/eom/contact/getContactByProductId/${productId}`);
+  if (res.data.code == 0) {
+    return res.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
+
 /**
  * 获取采购物品清单历史单价
  */

+ 12 - 1
src/views/purchasingManage/purchaseOrder/components/addDialogNew.vue

@@ -513,6 +513,7 @@
             :isContractId="
               !!form.contractId && !OutValidate.includes(form.sourceType)
             "
+            @getProductData="getSupplierData"
           >
           </inventoryTable>
         </el-tab-pane>
@@ -733,7 +734,8 @@
     getPurchaseinquiryAPI,
     getpurchaseorderDetail,
     getPurchasePlanByContractIdAPI,
-    UpdateInformation
+    UpdateInformation,
+    getSupplierInfo
   } from '@/api/purchasingManage/purchaseOrder';
   import { getplanDetail } from '@/api/purchasingManage/purchasePlanManage';
   import { getpurchaseinquiry } from '@/api/purchasingManage/inquiryManage';
@@ -1031,6 +1033,15 @@
       });
     },
     methods: {
+      getSupplierData(data) {
+        console.log('data~~~', data);
+        if(!this.form.partbName) {
+          getSupplierInfo(data[data.length - 1].productId).then((res) => {
+            console.log('res~~~', res);
+            this.changeParent(res.data);
+          })
+        }
+      },
       //选择退货单
       handleReturnBtn(e) {
         // this.$refs.returnListRef.open();

+ 11 - 2
src/views/purchasingManage/purchaseOrder/components/inventoryTableNew.vue

@@ -1487,8 +1487,9 @@
         });
       },
       //选择产品回调
-      changeParent(obj = [], idx) {
-        obj.forEach(async (item, index) => {
+      async changeParent(obj = [], idx) {
+        console.log('选择产品回调', obj);
+        const promises = obj.map(async (item, index) => {
           let i = idx == -1 ? index : idx;
           let row = JSON.parse(JSON.stringify(this.defaultForm));
           row.key = this.form.datasource.length + 1;
@@ -1556,6 +1557,14 @@
             this.form.datasource.push(row);
           }
         });
+
+        // 等待所有异步操作完成
+        await Promise.all(promises);
+        
+        // 只有当idx == -1时才emit数据给父组件
+        if (idx == -1) {
+          this.$emit('getProductData', this.form.datasource);
+        }
       },
       remove(row, index) {
         this.form.datasource.splice(index, 1);