From 4c9e1ba3c7f5c95a1789e88823ff262c26a53bce Mon Sep 17 00:00:00 2001
From: zhang_12370 <z2864490065@outlook.com>
Date: 星期二, 08 七月 2025 20:34:32 +0800
Subject: [PATCH] 解决 生产加工煤种字段匹配

---
 src/views/production/components/ProductionDialog.vue |   86 +++++++++++++++++++++++++++---------------
 1 files changed, 55 insertions(+), 31 deletions(-)

diff --git a/src/views/production/components/ProductionDialog.vue b/src/views/production/components/ProductionDialog.vue
index c14ca96..4a21fa4 100644
--- a/src/views/production/components/ProductionDialog.vue
+++ b/src/views/production/components/ProductionDialog.vue
@@ -200,10 +200,10 @@
 const currentRow = ref(null);
 const copyForm = ref(null);
 const coalList = ref([])
-const supplierList = ref({});
+const supplierList = ref([]);
 // 琛ㄦ牸鍒楅厤缃�
 const columns = [
-  {prop: "coalId", label: "鐓ょ", minwidth: 60,slot:false,
+  {prop: "coalId", label: "鐓ょ", minwidth: 60,
     formatter: (row) => {
       return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--";
     }
@@ -219,11 +219,6 @@
 ];
 
 const formalDatabaseColumns = ref([
-  {prop: "supplierId", label: "渚涘簲鍟嗗悕绉�", minwidth: 150
-  ,formatter: (row) => {
-      return supplierList.value.find(supplier => supplier.id === row.supplierId)?.supplierName || "--";
-    }
-  },
   {prop: "coalId", label: "鐓ょ", minwidth: 60,
     formatter: (row) => {
       return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--";
@@ -247,29 +242,51 @@
   currentRow.value = row;
 };
 
+// 鑾峰彇鍩虹鏁版嵁锛堢叅绉嶅拰渚涘簲鍟嗭級
+const loadBasicData = async () => {
+  try {
+    const [coalResponse, supplierResponse] = await Promise.all([
+      getCoalInfoList(),
+      getSupplyList()
+    ]);
+    
+    coalList.value = coalResponse.data || [];
+    supplierList.value = supplierResponse.data || [];
+  } catch (error) {
+    ElMessage.error("鑾峰彇鍩虹鏁版嵁澶辫触");
+  }
+};
+
 // 鑾峰彇閰嶇疆鏁版嵁
 const handlData = async () => {
   innerVisible.value = true;
-  let OfficialAll = await getOfficialAll();
-  let getSupplierList = await getSupplyList();
-  let getCoalName = await getCoalInfoList();
-  coalList.value = getCoalName.data || [];
-  supplierList.value = getSupplierList.data || [];
-  if (OfficialAll.code === 200) {
-    formalDatabaseData.value = OfficialAll.data;
-    const existingOfficialIds = tableData.value
-        .map((item) => item.officialId)
-        .filter((id) => id);
-    selectedIds.value = existingOfficialIds;
-    debugIdMatching();
-    nextTick(() => {
-      setTimeout(() => {
-        if (etableRef.value && existingOfficialIds.length > 0) {
-          etableRef.value.setDefaultSelection();
-        }
-      }, 100);
-    });
-  } else {
+  
+  // 纭繚鍩虹鏁版嵁宸插姞杞�
+  if (coalList.value.length === 0 || supplierList.value.length === 0) {
+    await loadBasicData();
+  }
+  
+  try {
+    const OfficialAll = await getOfficialAll();
+    
+    if (OfficialAll.code === 200) {
+      formalDatabaseData.value = OfficialAll.data;
+      const existingOfficialIds = tableData.value
+          .map((item) => item.officialId)
+          .filter((id) => id);
+      selectedIds.value = existingOfficialIds;
+      debugIdMatching();
+      nextTick(() => {
+        setTimeout(() => {
+          if (etableRef.value && existingOfficialIds.length > 0) {
+            etableRef.value.setDefaultSelection();
+          }
+        }, 100);
+      });
+    } else {
+      ElMessage.error("鑾峰彇閰嶇疆鏁版嵁澶辫触");
+    }
+  } catch (error) {
     ElMessage.error("鑾峰彇閰嶇疆鏁版嵁澶辫触");
   }
 };
@@ -296,14 +313,17 @@
 };
 
 // 鍒濆鍖栧拰缂栬緫鍒濆鍖�
-const Initialization = () => {
+const Initialization = async () => {
   tableData.value = [];
   detailsTableData.value = [];
   copyForm.value = null;
   dialogType.value = "add";
+  
+  // 鍔犺浇鍩虹鏁版嵁
+  await loadBasicData();
 };
 
-const editInitialization = (type,data) => {
+const editInitialization = async (type, data) => {
   copyForm.value = deepClone(data);
   tableData.value = data.productionInventoryList || [];
   detailsTableData.value = data.productionList || [];
@@ -312,6 +332,9 @@
       .map((item) => item.officialId)
       .filter((id) => id);
   selectedIds.value = existingOfficialIds;
+  
+  // 鍔犺浇鍩虹鏁版嵁
+  await loadBasicData();
 };
 // 鐩戝惉瀵硅瘽妗嗙姸鎬侊紝鍦ㄦ墦寮�鏃惰缃�変腑鐘舵��
 watch(innerVisible, (newVal) => {
@@ -457,12 +480,13 @@
   }
 };
 
-// 鑾峰彇鐢ㄦ埛淇℃伅
+// 鑾峰彇鐢ㄦ埛淇℃伅骞跺姞杞藉熀纭�鏁版嵁
 onMounted(async () => {
   try {
     userInfo = await userStore.getInfo();
+    await loadBasicData();
   } catch (error) {
-    ElMessage.error("鑾峰彇鐢ㄦ埛淇℃伅澶辫触锛岃閲嶈瘯");
+    ElMessage.error("鍒濆鍖栧け璐ワ紝璇烽噸璇�");
   }
 });
 

--
Gitblit v1.9.3