From aaf943ada13005f2b22d01e3d7080b8740d9aa96 Mon Sep 17 00:00:00 2001
From: zhang_12370 <z2864490065@outlook.com>
Date: 星期二, 15 七月 2025 15:09:49 +0800
Subject: [PATCH] 添加待入库功能及优化配煤计算器

---
 src/views/calculator/index.vue |  380 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 346 insertions(+), 34 deletions(-)

diff --git a/src/views/calculator/index.vue b/src/views/calculator/index.vue
index 9e6fe8c..fa71e86 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,23 +80,31 @@
                           <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
-                            v-model="item.name"
+                            v-model="item.coalId"
                             v-show="item.type !== '宸叉湁鐓�'"
                             placeholder="璇疯緭鍏�"
                             style="width: 100%"
                           />
+
                           <el-select
-                            v-model="item.name"
+                            v-model="item.coalId"
                             v-show="item.type === '宸叉湁鐓�'"
                             placeholder="璇烽�夋嫨"
                             style="width: 100%"
+                            @change="handleCoalSelectChange(index, item.coalId)"
                           >
-                            <el-option label="宸叉湁鐓�" value="宸叉湁鐓�" />
-                            <el-option label="鏈煡鐓�" value="鏈煡鐓�" />
+                            <el-option
+                              v-for="ele in infoCoals"
+                              :key="ele.key"
+                              :label="ele.value"
+                              :value="ele.key"
+                              >{{ ele.value }}
+                            </el-option>
                           </el-select>
                         </div>
                       </el-form-item>
@@ -103,12 +112,28 @@
                     <el-col :span="6">
                       <el-form-item label="鍙戠儹閲�">
                         <el-input
+                          v-if="item.type !== '鏈煡鐓�'"
+                          :value="
+                            infoCoals.find((coal) => coal.key === item.coalId)
+                              ?.item.coalValues.find((value) => value.fieldName === '鍙戠儹閲�')?.coalValue || '0'
+                          "
+                          type="number"
+                          style="width: 100%"
+                          :disabled="true"
+                        >
+                          <template v-slot:suffix>
+                            <i style="font-style: normal">kcal</i>
+                          </template>
+                        </el-input>
+                        <el-input
+                          v-else
                           v-model="item.cv"
                           type="number"
+                          placeholder="璇疯緭鍏ュ彂鐑噺"
                           style="width: 100%"
                         >
                           <template v-slot:suffix>
-                            <i style="font-style: normal">kcal/kg</i>
+                            <i style="font-style: normal">kcal</i>
                           </template>
                         </el-input>
                       </el-form-item>
@@ -116,7 +141,24 @@
                     <el-col :span="6">
                       <el-form-item label="浠锋牸">
                         <el-input
+                        v-if="item.type !== '鏈煡鐓�'"
+                        
+                          :value="
+                            infoCoals.find((coal) => coal.key === item.coalId)
+                              ?.item.priceExcludingTax || 0
+                          "
+                          type="number"
+                          style="width: 100%"
+                          :disabled="item.type === '宸叉湁鐓�'"
+                        >
+                          <template v-slot:suffix>
+                            <i style="font-style: normal">鍏�/鍚�</i>
+                          </template>
+                        </el-input>
+                        <el-input
+                        v-else
                           v-model="item.price"
+                          placeholder="璇疯緭鍏ヤ环鏍�"
                           type="number"
                           style="width: 100%"
                         >
@@ -131,6 +173,23 @@
                     <el-col :span="6">
                       <el-form-item label="纭垎">
                         <el-input
+                          v-if="item.type !== '鏈煡鐓�'"
+                          :disabled="item.type === '宸叉湁鐓�'"
+                          v-model="item.sulfur"
+                          :value="
+                            infoCoals.find((coal) => coal.key === item.coalId)
+                              ?.item.coalValues.find((value) => value.fieldName === '纭垎')?.coalValue || '0'
+                          "
+                          type="number"
+                          placeholder="鍙��"
+                          style="width: 100%"
+                        >
+                          <template v-slot:suffix>
+                            <i style="font-style: normal">%</i>
+                          </template>
+                        </el-input>
+                        <el-input
+                          v-else
                           v-model="item.sulfur"
                           type="number"
                           placeholder="鍙��"
@@ -145,6 +204,23 @@
                     <el-col :span="6">
                       <el-form-item label="鐏板垎">
                         <el-input
+                          v-if="item.type !== '鏈煡鐓�'"
+                          :disabled="item.type === '宸叉湁鐓�'"
+                          v-model="item.ash"
+                          :value="
+                            infoCoals.find((coal) => coal.key === item.coalId)
+                              ?.item.coalValues.find((value) => value.fieldName === '鐏板垎')?.coalValue || '0'
+                          "
+                          type="number"
+                          placeholder="鍙��"
+                          style="width: 100%"
+                        >
+                          <template v-slot:suffix>
+                            <i style="font-style: normal">%</i>
+                          </template>
+                        </el-input>
+                        <el-input
+                          v-else
                           v-model="item.ash"
                           type="number"
                           placeholder="鍙��"
@@ -159,6 +235,23 @@
                     <el-col :span="6">
                       <el-form-item label="姘村垎">
                         <el-input
+                        v-if="item.type !== '鏈煡鐓�'"
+                        :disabled="item.type === '宸叉湁鐓�'"
+                        v-model="item.moisture"
+                        :value="
+                            infoCoals.find((coal) => coal.key === item.coalId)
+                              ?.item.coalValues.find((value) => value.fieldName === '姘村垎')?.coalValue || '0'
+                          "
+                          type="number"
+                          placeholder="鍙��"
+                          style="width: 100%"
+                        >
+                          <template v-slot:suffix>
+                            <i style="font-style: normal">%</i>
+                          </template>
+                        </el-input>
+                        <el-input
+                        v-else
                           v-model="item.moisture"
                           type="number"
                           placeholder="鍙��"
@@ -194,7 +287,7 @@
                       style="width: 100%"
                     >
                       <template v-slot:suffix>
-                        <i style="font-style: normal">kcal/kg</i>
+                        <i style="font-style: normal">kcal</i>
                       </template>
                     </el-input>
                   </el-form-item>
@@ -247,8 +340,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,13 +374,22 @@
                 class="result-table"
                 style="width: 100%"
               >
-                <el-table-column prop="name" label="鐓ょ" min-width="80" />
+                <el-table-column prop="coalId" label="鐓ょ" min-width="80">
+                  <template #default="scope">
+                    {{
+                      infoCoals.find((coal) => coal.key === scope.row.coalId)
+                        ?.value ||
+                      "" ||
+                      matchCoalName(scope.row.coalId)
+                    }}
+                  </template>
+                </el-table-column>
                 <el-table-column prop="ratio" label="閰嶆瘮" min-width="80">
                   <template #default="scope"> {{ scope.row.ratio }}% </template>
                 </el-table-column>
-                <el-table-column prop="tonnage" label="鍚ㄦ暟" min-width="80">
+                <el-table-column prop="quantity" label="鍚ㄦ暟" min-width="80">
                   <template #default="scope">
-                    {{ scope.row.tonnage }}鍚�
+                    {{ scope.row.quantity }}鍚�
                   </template>
                 </el-table-column>
                 <el-table-column prop="scoops" label="閾叉暟" min-width="80">
@@ -305,7 +407,7 @@
                 <div class="prop-item">
                   <span class="prop-label">鍙戠儹閲�:</span>
                   <span class="prop-value"
-                    >{{ result.optimal.props.cv.toFixed(2) }} kcal/kg</span
+                    >{{ result.optimal.props.cv.toFixed(2) }} kcal</span
                   >
                 </div>
                 <div class="prop-item">
@@ -332,6 +434,20 @@
                     >{{ 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>
           </div>
@@ -356,15 +472,24 @@
                   class="alt-table"
                   style="width: 100%"
                 >
-                  <el-table-column prop="name" label="鐓ょ" min-width="80" />
+                  <el-table-column prop="coalId" label="鐓ょ" min-width="80">
+                    <template #default="scope">
+                      {{
+                        infoCoals.find((coal) => coal.key === scope.row.coalId)
+                          ?.value ||
+                        "" ||
+                        matchCoalName(scope.row.coalId)
+                      }}
+                    </template>
+                  </el-table-column>
                   <el-table-column prop="ratio" label="閰嶆瘮" min-width="80">
                     <template #default="scope">
                       {{ scope.row.ratio }}%
                     </template>
                   </el-table-column>
-                  <el-table-column prop="tonnage" label="鍚ㄦ暟" min-width="80">
+                  <el-table-column prop="quantity" label="鍚ㄦ暟" min-width="80">
                     <template #default="scope">
-                      {{ scope.row.tonnage }}鍚�
+                      {{ scope.row.quantity }}鍚�
                     </template>
                   </el-table-column>
                   <el-table-column prop="scoops" label="閾叉暟" min-width="80">
@@ -376,7 +501,7 @@
               </div>
 
               <div class="alt-props">
-                <span>鍙戠儹閲�: {{ alt.props.cv.toFixed(2) }} kcal/kg锛�</span>
+                <span>鍙戠儹閲�: {{ alt.props.cv.toFixed(2) }} kcal锛�</span>
                 <span>纭垎: {{ alt.props.sulfur.toFixed(2) }}%锛�</span>
                 <span>鐏板垎: {{ alt.props.ash.toFixed(2) }}%锛�</span>
                 <span>姘村垎: {{ alt.props.moisture.toFixed(2) }}%锛�</span>
@@ -397,8 +522,10 @@
 </template>
 
 <script setup>
-import { reactive, toRefs, nextTick } from "vue";
+import { reactive, toRefs, nextTick, onMounted, ref } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
+import { getCoalInfoList } from "@/api/procureMent"; // 鍋囪鏈変竴涓狝PI鑾峰彇鐓ょ淇℃伅
+import { getCoalBlendingList,addPendingInventory } from "@/api/calculator/index.js";
 
 const data = reactive({
   formInline: {
@@ -416,7 +543,7 @@
   coalForms: [
     {
       type: "鏈煡鐓�",
-      name: "鐓",
+      coalId: "鐓",
       cv: 6200, // 鍙戠儹閲�
       price: 450, // 浠锋牸
       sulfur: 0.6, // 纭垎
@@ -425,7 +552,7 @@
     },
     {
       type: "鏈煡鐓�",
-      name: "鐓",
+      coalId: "鐓",
       cv: 5800,
       price: 380,
       sulfur: 1.0,
@@ -434,7 +561,7 @@
     },
     {
       type: "鏈煡鐓�",
-      name: "鐓",
+      coalId: "鐓",
       cv: 5400,
       price: 320,
       sulfur: 1.4,
@@ -448,9 +575,119 @@
     optimal: null,
     alternatives: [],
     error: null,
+    createCoal: null,
   },
 });
+const handleCoalSelectChange = (index, coalId) => {
+  const selectedCoal = infoCoals.value.find(item => item.key === coalId);
+  
+  if (selectedCoal && selectedCoal.item && selectedCoal.item.coalValues) {
+    console.log('閫変腑鐨勭叅绉�:', selectedCoal);
+    
+    // 瀹夊叏鍦拌幏鍙栧悇椤圭叅璐ㄥ弬鏁�
+    const getCoalValue = (fieldName) => {
+      const coalValue = selectedCoal.item.coalValues.find(
+        (value) => value.fieldName === fieldName
+      );
+      return coalValue ? coalValue.coalValue : '';
+    };
 
+    // 鏇存柊琛ㄥ崟鏁版嵁
+    data.coalForms[index].price = selectedCoal.item.priceExcludingTax || 0;
+    data.coalForms[index].cv = getCoalValue("鍙戠儹閲�") || 0;
+    data.coalForms[index].sulfur = getCoalValue("纭垎") || 0;
+    data.coalForms[index].ash = getCoalValue("鐏板垎") || 0;
+    data.coalForms[index].moisture = getCoalValue("姘村垎") || 0;
+    
+    // 璁剧疆浠锋牸锛堝鏋滄湁鐨勮瘽锛�
+    if (selectedCoal.item.priceExcludingTax) {
+      data.coalForms[index].price = selectedCoal.item.priceExcludingTax;
+    }
+    
+    console.log('鏇存柊鍚庣殑琛ㄥ崟鏁版嵁:', data.coalForms[index]);
+  } else {
+    console.warn('鏈壘鍒伴�変腑鐨勭叅绉嶆暟鎹垨鏁版嵁鏍煎紡涓嶆纭�');
+  }
+};
+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.coalId = found.key;
+  } else {
+    result.value.optimal.props.coalId = 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();
+  geInfoCoals();
+});
+const infoCoals = ref([]);
+// 鍒濆鍖栫叅绉嶅瓧娈�
+const geInfoCoals = async () => {
+  let res = await getCoalBlendingList();
+  if (res.code === 200) {
+    infoCoals.value = res.data.map((item) => ({
+      value: item.supplierCoal,
+      key: item.coalId,
+      item,
+    }));
+    console.log(infoCoals.value);
+  } else {
+    ElMessage.error("鑾峰彇鐓ょ淇℃伅澶辫触锛岃绋嶅悗閲嶈瘯");
+  }
+};
 // 绾挎�ц鍒掓眰瑙e嚱鏁�
 const solveBlend = (coals, constraints) => {
   // 鏁版嵁楠岃瘉
@@ -530,12 +767,12 @@
   return coals
     .map((coal, i) => {
       if (ratios[i] < 1e-6) return null;
-      let tonnage = ratios[i] * total;
-      let scoops = tonnage / scoop;
+      let quantity = ratios[i] * total;
+      let scoops = quantity / scoop;
       return {
-        name: coal.name,
+        coalId: coal.coalId,
         ratio: (ratios[i] * 100).toFixed(2),
-        tonnage: tonnage.toFixed(1),
+        quantity: quantity.toFixed(1),
         scoops: scoops.toFixed(1),
       };
     })
@@ -558,7 +795,7 @@
   data.coalForms = [
     {
       type: "鏈煡鐓�",
-      name: "鐓",
+      coalId: "鐓",
       cv: 6200,
       price: 450,
       sulfur: 0.6,
@@ -567,7 +804,7 @@
     },
     {
       type: "鏈煡鐓�",
-      name: "鐓",
+      coalId: "鐓",
       cv: 5800,
       price: 380,
       sulfur: 1.0,
@@ -576,7 +813,7 @@
     },
     {
       type: "鏈煡鐓�",
-      name: "鐓",
+      coalId: "鐓",
       cv: 5400,
       price: 320,
       sulfur: 1.4,
@@ -592,11 +829,78 @@
   };
   ElMessage.success("琛ㄥ崟宸查噸缃�");
 };
+const addWarehoused = () => {
 
+  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.coalId);
+  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.coalId) {
+      createCoalFound = true;
+      break;
+    }
+  }
+  if (!createCoalFound) {
+    ElMessage.warning("鐢熸垚鐓ょ鏄湭鐭ョ叅绉嶏紝鏃犳硶娣诲姞鑷冲緟鍏ュ簱");
+    return;
+  }
+  // result.value.optimal.props fieldsResultList
+  // result.value.optimal.instructions 琛ㄦ牸鏁版嵁coalResultList
+  console.log("娣诲姞鑷冲緟鍏ュ簱鏁版嵁锛�", result.value.optimal);
+  // cost淇濈暀涓や綅灏忔暟
+  result.value.optimal.props.totalTonnage = formInline.value.totalTonnage;
+  result.value.optimal.instructions.forEach((item) => {
+    item.officialId = item.coalId; // 娣诲姞瀹樻柟ID瀛楁
+  });
+  result.value.optimal.props.cost = parseFloat(
+    result.value.optimal.props.cost.toFixed(2)
+  );
+  result.value.optimal.props.totalTonnage = formInline.value.totalTonnage;
+  let arr = [result.value.optimal.props, [...result.value.optimal.instructions]];
+  let params = {
+    fieldsResultList: arr[0],
+    coalResultList: arr[1],
+  };
+ addPendingInventory(params).then((res)=>{
+   if(res.code === 200 && res.data== true){
+     ElMessage.success("娣诲姞鑷冲緟鍏ュ簱鎴愬姛");
+   }
+ })
+};
 const submitForm = () => {
+  console.log("鐓ょ淇℃伅锛�", coalForms.value);
   // 鏁版嵁楠岃瘉
   let validCoals = coalForms.value.filter(
-    (coal) => coal.name && coal.cv && coal.price
+    (coal) => coal.coalId && coal.cv && coal.price
   );
 
   if (validCoals.length < 2) {
@@ -718,23 +1022,24 @@
   while (coalForms.value.length < num) {
     coalForms.value.push({
       type: "鏈煡鐓�",
-      name: `鐓�${String.fromCharCode(65 + coalForms.value.length)}`,
+      coalId: `鐓�${String.fromCharCode(65 + coalForms.value.length)}`,
       cv: 0,
       price: 0,
       sulfur: "",
       ash: "",
       moisture: "",
-    });  }
+    });
+  }
 };
 
 // 澶勭悊鐓ょ绫诲瀷鍙樺寲
 const handleCoalTypeChange = (index) => {
   // 褰撶叅绉嶇被鍨嬫敼鍙樻椂锛屾竻绌虹叅绉嶅悕绉帮紝閬垮厤鏁版嵁娣蜂贡
-  coalForms.value[index].name = '';
+  coalForms.value[index].coalId = "";
 };
 </script>
 
-<style scoped>
+<style scoped lang="scss">
 .view {
   display: flex;
   gap: 10px;
@@ -966,6 +1271,7 @@
   background: #f5f7fa;
   border-radius: 4px;
   font-size: 13px;
+  align-items: center;
 }
 
 .prop-label {
@@ -1124,4 +1430,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