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/calculator/index.vue |  162 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 149 insertions(+), 13 deletions(-)

diff --git a/src/views/calculator/index.vue b/src/views/calculator/index.vue
index 9e6fe8c..c20d714 100644
--- a/src/views/calculator/index.vue
+++ b/src/views/calculator/index.vue
@@ -68,7 +68,8 @@
                   style="margin-bottom: 15px"
                 >
                   <el-row :gutter="16">
-                    <el-col :span="6">                      <el-form-item label="鐓ょ绫诲瀷">
+                    <el-col :span="6">
+                      <el-form-item label="鐓ょ绫诲瀷">
                         <el-select
                           v-model="item.type"
                           placeholder="璇烽�夋嫨"
@@ -79,7 +80,8 @@
                           <el-option label="鏈煡鐓�" value="鏈煡鐓�" />
                         </el-select>
                       </el-form-item>
-                    </el-col>                    <el-col :span="6">
+                    </el-col>
+                    <el-col :span="6">
                       <el-form-item :label="'鐓ょ' + (index + 1)">
                         <div class="input-wrapper">
                           <el-input
@@ -88,14 +90,20 @@
                             placeholder="璇疯緭鍏�"
                             style="width: 100%"
                           />
+
                           <el-select
                             v-model="item.name"
                             v-show="item.type === '宸叉湁鐓�'"
                             placeholder="璇烽�夋嫨"
                             style="width: 100%"
                           >
-                            <el-option label="宸叉湁鐓�" value="宸叉湁鐓�" />
-                            <el-option label="鏈煡鐓�" value="鏈煡鐓�" />
+                            <el-option
+                              v-for="ele in coalInfoList"
+                              :key="ele.key"
+                              :label="ele.value"
+                              :value="ele.key"
+                              >{{ ele.value }}
+                            </el-option>
                           </el-select>
                         </div>
                       </el-form-item>
@@ -247,8 +255,8 @@
         </div>
         <div class="footer">
           <el-button @click="cancel">閲嶇疆</el-button>
-          <el-button type="primary" @click="submitForm" plain>
-            鏌ョ湅璁$畻缁撴灉
+          <el-button type="primary" @click="addWarehoused" plain>
+            娣诲姞鑷冲緟鍏ュ簱
           </el-button>
           <el-button type="primary" @click="submitForm">璁$畻鏈�浼橀厤姣�</el-button>
         </div>
@@ -281,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>
@@ -331,6 +343,20 @@
                   <span class="prop-value cost"
                     >{{ result.optimal.props.cost.toFixed(2) }} 鍏�/鍚�</span
                   >
+                </div>
+                <div class="prop-item">
+                  <span class="prop-label">鐢熸垚:</span>
+                  <el-autocomplete
+                    v-model="result.optimal.props.createCoal"
+                    :fetch-suggestions="querySearch"
+                    clearable
+                    size="small"
+                    class="inline-input red-border"
+                    style="width: 180px; min-height: 24px !important"
+                    placeholder="璇疯緭鍏ョ敓鎴愮叅绉�"
+                    @blur="handleSelect($event)"
+                    @select="handleSelect($event)"
+                  />
                 </div>
               </div>
             </div>
@@ -397,8 +423,9 @@
 </template>
 
 <script setup>
-import { reactive, toRefs, nextTick } from "vue";
+import { reactive, toRefs, nextTick, onMounted } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
+import { getCoalInfoList } from "@/api/procureMent"; // 鍋囪鏈変竴涓狝PI鑾峰彇鐓ょ淇℃伅
 
 const data = reactive({
   formInline: {
@@ -448,9 +475,65 @@
     optimal: null,
     alternatives: [],
     error: null,
+    createCoal: null,
   },
 });
-
+const coalInfoList = ref([]);
+// onMounted
+const getCoalInfo = async () => {
+  let result = await getCoalInfoList();
+  if (result.code === 200) {
+    result.data.forEach((item) => {
+      let obj = {
+        value: item.coal,
+        key: item.id,
+      };
+      coalInfoList.value.push(obj);
+    });
+  } else {
+    ElMessage.error("鑾峰彇鐓ょ淇℃伅澶辫触锛岃绋嶅悗閲嶈瘯");
+  }
+};
+// 琛ㄦ牸灞曠ず鐢細浼樺厛鐢� 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;
+  cb(res);
+};
+// 閫夋嫨/澶辩劍鏃讹紝浼樺厛瀛� key锛屾壘涓嶅埌鍒欏瓨鍘熷��
+const handleSelect = (item) => {
+  const val = item.value || (item.target && item.target.value) || "";
+  const found = coalInfoList.value.find(
+    (c) => c.value === val || c.key === val
+  );
+  result.value.optimal.props.createCoal = found ? found.key : val;
+  // 鏂板锛氬鏋滃尮閰嶆垚鍔燂紝鐣欎竴涓猧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;
+  }
+};
+onMounted(async () => {
+  getCoalInfo();
+});
 // 绾挎�ц鍒掓眰瑙e嚱鏁�
 const solveBlend = (coals, constraints) => {
   // 鏁版嵁楠岃瘉
@@ -592,7 +675,52 @@
   };
   ElMessage.success("琛ㄥ崟宸查噸缃�");
 };
-
+const addWarehoused = () => {
+  console.log(coalInfoList.value);
+  if (!result.value) {
+    ElMessage.error("璇峰厛璁$畻鏈�浼橀厤姣斿悗鍐嶆坊鍔犺嚦寰呭叆搴�");
+    return;
+  }
+  if (result.value.optimal === null) {
+    ElMessage.error("璇峰厛璁$畻鏈�浼橀厤姣�");
+    return;
+  }
+  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 = () => {
   // 鏁版嵁楠岃瘉
   let validCoals = coalForms.value.filter(
@@ -724,17 +852,18 @@
       sulfur: "",
       ash: "",
       moisture: "",
-    });  }
+    });
+  }
 };
 
 // 澶勭悊鐓ょ绫诲瀷鍙樺寲
 const handleCoalTypeChange = (index) => {
   // 褰撶叅绉嶇被鍨嬫敼鍙樻椂锛屾竻绌虹叅绉嶅悕绉帮紝閬垮厤鏁版嵁娣蜂贡
-  coalForms.value[index].name = '';
+  coalForms.value[index].name = "";
 };
 </script>
 
-<style scoped>
+<style scoped lang="scss">
 .view {
   display: flex;
   gap: 10px;
@@ -966,6 +1095,7 @@
   background: #f5f7fa;
   border-radius: 4px;
   font-size: 13px;
+  align-items: center;
 }
 
 .prop-label {
@@ -1124,4 +1254,10 @@
     padding: 4px 8px;
   }
 }
+:deep(.el-input__wrapper) {
+  min-height: 24px !important;
+}
+:deep(.el-input__inner) {
+  min-height: 24px !important;
+}
 </style>

--
Gitblit v1.9.3