From 3bd642ad4d805032ae43e1fd23e0c4e6b7dfa9f2 Mon Sep 17 00:00:00 2001
From: zhang_12370 <z2864490065@outlook.com>
Date: 星期六, 12 七月 2025 11:58:41 +0800
Subject: [PATCH] 1、修改采购管理的匹配逻辑 2、修改生产加工新增生产明细的总数居匹配问题 3、修改配煤计算器 4、修改设备管理领用记录的提交问题

---
 src/views/production/components/ProductionDetailsTable.vue          |    2 
 src/views/calculator/index.vue                                      |   84 ++++++++++++++++++++++++++++++++++-------
 src/views/procureMent/components/ProductionDialog.vue               |    6 +-
 src/views/equipment/management/mould/equipmentRequisitionDialog.vue |    4 +-
 4 files changed, 75 insertions(+), 21 deletions(-)

diff --git a/src/views/calculator/index.vue b/src/views/calculator/index.vue
index af09bb5..c20d714 100644
--- a/src/views/calculator/index.vue
+++ b/src/views/calculator/index.vue
@@ -289,7 +289,11 @@
                 class="result-table"
                 style="width: 100%"
               >
-                <el-table-column prop="name" label="鐓ょ" min-width="80" />
+                <el-table-column prop="name" label="鐓ょ" min-width="80">
+                  <template #default="scope">
+                    {{ matchCoalName(scope.row.name) }}
+                  </template>
+                </el-table-column>
                 <el-table-column prop="ratio" label="閰嶆瘮" min-width="80">
                   <template #default="scope"> {{ scope.row.ratio }}% </template>
                 </el-table-column>
@@ -471,6 +475,7 @@
     optimal: null,
     alternatives: [],
     error: null,
+    createCoal: null,
   },
 });
 const coalInfoList = ref([]);
@@ -489,25 +494,39 @@
     ElMessage.error("鑾峰彇鐓ょ淇℃伅澶辫触锛岃绋嶅悗閲嶈瘯");
   }
 };
-// 鏍规嵁 key 杩斿洖涓枃鍚嶏紝鍚﹀垯鍘熸牱杩斿洖
-const matchCoal = value => {
-  if (!value) return "";
-  const found = coalInfoList.value.find(c => c.key === value);
-  return found ? found.value : value;
+// 琛ㄦ牸灞曠ず鐢細浼樺厛鐢� key 鍖归厤涓枃鍚嶏紝鍐嶇敤 value 鍖归厤锛屾渶鍚庡師鏍疯繑鍥�
+const matchCoalName = (name) => {
+  if (!name || !Array.isArray(coalInfoList.value) || coalInfoList.value.length === 0) return name;
+  // key 鍖归厤
+  const byKey = coalInfoList.value.find(item => String(item.key) === String(name));
+  if (byKey) return byKey.value;
+  // value 鍖归厤
+  const byValue = coalInfoList.value.find(item => item.value === name);
+  if (byValue) return byValue.value;
+  // 鍘熸牱杩斿洖
+  return name;
 };
 // 鑷姩琛ュ叏鎼滅储
 const querySearch = (q, cb) => {
   const res = q
-    ? coalInfoList.value.filter(c => c.value.includes(q))
+    ? coalInfoList.value.filter((c) => c.value.includes(q))
     : coalInfoList.value;
   cb(res);
 };
 // 閫夋嫨/澶辩劍鏃讹紝浼樺厛瀛� key锛屾壘涓嶅埌鍒欏瓨鍘熷��
-const handleSelect = item => {
+const handleSelect = (item) => {
   const val = item.value || (item.target && item.target.value) || "";
-  const found = coalInfoList.value.find(c => c.value === val || c.key === val);
+  const found = coalInfoList.value.find(
+    (c) => c.value === val || c.key === val
+  );
   result.value.optimal.props.createCoal = found ? found.key : val;
-  let match = matchCoal(result.value.optimal.props.createCoal);
+  // 鏂板锛氬鏋滃尮閰嶆垚鍔燂紝鐣欎竴涓猧d瀛楁
+  if (found) {
+    result.value.optimal.props.createCoalId = found.key;
+  } else {
+    result.value.optimal.props.createCoalId = null;
+  }
+  let match = matchCoalName(result.value.optimal.props.createCoal);
   if (match && match !== result.value.optimal.props.createCoal) {
     result.value.optimal.props.createCoal = match;
   }
@@ -657,15 +676,50 @@
   ElMessage.success("琛ㄥ崟宸查噸缃�");
 };
 const addWarehoused = () => {
-  if(!result.value){
-    ElMessage.warning("璇峰厛璁$畻鏈�浼橀厤姣斿悗鍐嶆坊鍔犺嚦寰呭叆搴�");
+  console.log(coalInfoList.value);
+  if (!result.value) {
+    ElMessage.error("璇峰厛璁$畻鏈�浼橀厤姣斿悗鍐嶆坊鍔犺嚦寰呭叆搴�");
     return;
   }
-  if(result.value.optimal.props.createCoal === "") {
-    ElMessage.warning("璇峰厛閫夋嫨鐢熸垚鐓ょ");
+  if (result.value.optimal === null) {
+    ElMessage.error("璇峰厛璁$畻鏈�浼橀厤姣�");
     return;
   }
-  console.log(result.value)
+  if (!result.value.optimal.props.createCoal) {
+    ElMessage.error("璇峰厛閫夋嫨鐢熸垚鐓ょ");
+    return;
+  }
+  const coals = result.value.optimal.instructions.map((item) => item.name);
+  let allFound = true;
+  for (const element of coals) {
+    let found = false;
+    for (const item of coalInfoList.value) {
+      if (item.key === element) {
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      allFound = false;
+      break;
+    }
+  }
+  if (!allFound) {
+    ElMessage.error("閰嶆瘮涓寘鍚湭鐭ョ叅绉嶏紝璇峰厛娣诲姞鑷崇叅绉嶅垪琛�");
+    return;
+  }
+  let createCoalFound = false;
+  for (const item of coalInfoList.value) {
+    if (item.key === result.value.optimal.props.createCoalId) {
+      console.log("鐢熸垚鐓ょ宸插瓨鍦�");
+      createCoalFound = true;
+      break;
+    }
+  }
+  if (!createCoalFound) {
+    ElMessage.warning("鐢熸垚鐓ょ鏄湭鐭ョ叅绉嶏紝鏃犳硶娣诲姞鑷冲緟鍏ュ簱");
+    return;
+  }
 };
 const submitForm = () => {
   // 鏁版嵁楠岃瘉
diff --git a/src/views/equipment/management/mould/equipmentRequisitionDialog.vue b/src/views/equipment/management/mould/equipmentRequisitionDialog.vue
index b6382ef..8f58ee2 100644
--- a/src/views/equipment/management/mould/equipmentRequisitionDialog.vue
+++ b/src/views/equipment/management/mould/equipmentRequisitionDialog.vue
@@ -118,9 +118,9 @@
   },
 });
 const maxQuantity = computed(() => {
-  if (!props.formData.equipmentId) return 0;
+  if (!form.value.equipmentId) return 0;
   const eq = equipmentList.value.find(
-    (item) => item.id == props.formData.equipmentId
+    (item) => item.id == form.value.equipmentId
   );
   // 闃叉涓�0鎴栬礋鏁帮紝鏈�灏忎负1
   return eq && eq.quantity > 0 ? eq.quantity : 999;
diff --git a/src/views/procureMent/components/ProductionDialog.vue b/src/views/procureMent/components/ProductionDialog.vue
index 0c720bf..e92ddac 100644
--- a/src/views/procureMent/components/ProductionDialog.vue
+++ b/src/views/procureMent/components/ProductionDialog.vue
@@ -203,7 +203,7 @@
   // 1. 鏍规嵁鍚◣鍗曚环鍜岀◣鐜囪绠椾笉鍚◣鍗曚环
   // 涓嶅惈绋庡崟浠� = 鍚◣鍗曚环 / (1 + 绋庣巼/100)
   const priceExcludingTax = priceIncludingTax && taxRate 
-    ? toFixed(priceIncludingTax / (1 + taxRate / 100), 2)
+    ? parseFloat((priceIncludingTax / (1 + taxRate / 100)).toFixed(2))
     : 0;
 
   // 2. 璁$畻涓嶅惈绋庢�讳环 = 涓嶅惈绋庡崟浠� 脳 鏁伴噺
@@ -216,8 +216,8 @@
     ? toFixed(priceIncludingTax * quantity, 2)
     : 0;
 
-  // 鏇存柊琛ㄥ崟鏁版嵁
-  form.value.priceExcludingTax = priceExcludingTax;
+  // 淇濊瘉鏄剧ず涓轰袱浣嶅皬鏁帮紙濡�88.5鏄剧ず涓�88.50锛�
+  form.value.priceExcludingTax = priceExcludingTax.toFixed(2);
   form.value.totalPriceExcludingTax = totalPriceExcludingTax;
   form.value.totalPriceIncludingTax = totalPriceIncludingTax;
 };
diff --git a/src/views/production/components/ProductionDetailsTable.vue b/src/views/production/components/ProductionDetailsTable.vue
index 13cd614..48308f4 100644
--- a/src/views/production/components/ProductionDetailsTable.vue
+++ b/src/views/production/components/ProductionDetailsTable.vue
@@ -229,7 +229,7 @@
 // 璁$畻鎬绘垚鏈�
 const calculateTotalCost = (row) => {
   const laborCost = parseFloat(row.laborCost) || 0;
-  const energyCost = parseFloat(row.energyCost) || 0;
+  const energyCost = parseFloat(row.energyConsumptionCost) || 0;
   const equipmentDepreciation = parseFloat(row.equipmentDepreciation) || 0;
   const purchasePrice = parseFloat(row.purchasePrice) || 0;
 

--
Gitblit v1.9.3