From c6d13e58d85fbaaceb49d4c24401b50143050173 Mon Sep 17 00:00:00 2001
From: zhang_12370 <z2864490065@outlook.com>
Date: 星期四, 26 六月 2025 18:01:24 +0800
Subject: [PATCH] 调整 基础管理煤种生产人 更改采购数计算逻辑 处理供应商数据回显问题

---
 src/views/procureMent/components/ProductionDialog.vue |  284 ++++++++++++++++++++++++++------------------------------
 1 files changed, 131 insertions(+), 153 deletions(-)

diff --git a/src/views/procureMent/components/ProductionDialog.vue b/src/views/procureMent/components/ProductionDialog.vue
index e420fbe..3fc0c99 100644
--- a/src/views/procureMent/components/ProductionDialog.vue
+++ b/src/views/procureMent/components/ProductionDialog.vue
@@ -1,78 +1,72 @@
 <template>
   <div>
     <el-dialog
-      v-model="dialogFormVisible"
-      :title="title"
-      width="600"
-      :close-on-click-modal="false"
-      @close="handleClose"
+        v-model="dialogFormVisible"
+        :title="title"
+        width="600"
+        :close-on-click-modal="false"
+        @close="handleClose"
     >
       <el-form
-        ref="formRef"
-        :model="form"
-        :rules="rules"
-        label-width="auto"
-        class="production-form"
-        label-position="right"
-        style="max-width: 400px; margin: 0 auto"
+          ref="formRef"
+          :model="form"
+          :rules="rules"
+          label-width="auto"
+          class="production-form"
+          label-position="right"
+          style="max-width: 400px; margin: 0 auto"
       >
         <el-form-item label="渚涘簲鍟嗗悕绉�" prop="supplierId">
-          <el-select v-model="form.supplierId" placeholder="璇烽�夋嫨渚涘簲鍟�">
-            <el-option :label="item.label" v-for="item in supplyList" :key="item.value" :value="item.value" />
+          <el-select v-model="form.supplierId" placeholder="璇烽�夋嫨渚涘簲鍟�" :disabled="isViewMode">
+            <el-option :label="item.label" v-for="item in supplyList" :key="item.value" :value="item.value"/>
           </el-select>
         </el-form-item>
         <el-form-item label="鐓ょ" prop="coalId">
-          <el-select v-model="form.coalId" placeholder="璇烽�夋嫨鐓ょ">
-            <el-option :label="item.label" v-for="item in coalList" :key="item.value" :value="item.value" />
-          </el-select>
-        </el-form-item>
-        <el-form-item label="鍗曚綅" prop="unit">
-          <el-select
-            v-model="form.unit"
-            placeholder="璇烽�夋嫨鍗曚綅"
-            clearable
-            style="width: 100%"
-          >
-            <el-option label="鍚�" value="鍚�" />
-            <el-option label="鍗冨厠" value="鍗冨厠" />
+          <el-select v-model="form.coalId" placeholder="璇烽�夋嫨鐓ょ" :disabled="isViewMode">
+            <el-option :label="item.label" v-for="item in coalList" :key="item.value" :value="item.value"/>
           </el-select>
         </el-form-item>
         <el-form-item label="閲囪喘鏁伴噺" prop="purchaseQuantity">
           <el-input
-            v-model.number="form.purchaseQuantity"
-            placeholder="璇疯緭鍏�"
-            @blur="handleQuantityBlur"
+              v-model.number="form.purchaseQuantity"
+              placeholder="璇疯緭鍏�"
+              @blur="handleQuantityBlur"
+              :disabled="isViewMode"
           >
             <template v-slot:suffix>
-              <i style="font-style: normal">{{ form.unit ? form.unit : "" }}</i>
+              <i style="font-style: normal">鍚�</i>
             </template>
-          </el-input> </el-form-item
-        ><el-form-item label="绋庣巼" prop="taxRate">
+          </el-input>
+        </el-form-item>
+        <el-form-item label="绋庣巼" prop="taxRate">
           <el-input
-            v-model.number="form.taxRate"
-            placeholder="璇疯緭鍏ョ◣鐜�"
-            @blur="handleTaxRateBlur"
+              v-model.number="form.taxRate"
+              placeholder="璇疯緭鍏ョ◣鐜�"
+              @blur="handleTaxRateBlur"
+              :disabled="isViewMode"
           >
             <template v-slot:suffix>
               <i style="font-style: normal">%</i>
             </template>
           </el-input>
         </el-form-item>
-        <el-form-item label="鍗曚环(涓嶅惈绋�)" prop="priceExcludingTax">
+        <el-form-item label="鍗曚环(鍚◣)" prop="priceIncludingTax">
           <el-input
-            v-model.number="form.priceExcludingTax"
-            placeholder="璇疯緭鍏�"
-            @blur="handlePriceBlur"
+              v-model.number="form.priceIncludingTax"
+              placeholder="璇疯緭鍏ュ惈绋庡崟浠�"
+              @blur="handlePriceBlur"
+              :disabled="isViewMode"
           >
             <template v-slot:suffix>
               <i style="font-style: normal">鍏�</i>
             </template>
           </el-input>
         </el-form-item>
-        <el-form-item label="鍗曚环(鍚◣)" prop="priceIncludingTax">
+        <el-form-item label="鍗曚环(涓嶅惈绋�)" prop="priceExcludingTax">
           <el-input
-            v-model.number="form.priceIncludingTax"
-            placeholder="鑷姩璁$畻"
+              v-model.number="form.priceExcludingTax"
+              placeholder="鑷姩璁$畻"
+              disabled
           >
             <template v-slot:suffix>
               <i style="font-style: normal">鍏�</i>
@@ -81,8 +75,9 @@
         </el-form-item>
         <el-form-item label="鎬讳环(涓嶅惈绋�)" prop="totalPriceExcludingTax">
           <el-input
-            v-model.number="form.totalPriceExcludingTax"
-            placeholder="鑷姩璁$畻"
+              v-model.number="form.totalPriceExcludingTax"
+              placeholder="鑷姩璁$畻"
+              disabled
           >
             <template v-slot:suffix>
               <i style="font-style: normal">鍏�</i>
@@ -91,8 +86,9 @@
         </el-form-item>
         <el-form-item label="鎬讳环(鍚◣)" prop="totalPriceIncludingTax">
           <el-input
-            v-model.number="form.totalPriceIncludingTax"
-            placeholder="鑷姩璁$畻"
+              v-model.number="form.totalPriceIncludingTax"
+              placeholder="鑷姩璁$畻"
+              disabled
           >
             <template v-slot:suffix>
               <i style="font-style: normal">鍏�</i>
@@ -100,29 +96,31 @@
           </el-input>
         </el-form-item>
         <el-form-item label="鐧昏浜�" prop="registrantId">
-          <el-input v-model="form.registrantId" disabled placeholder="璇疯緭鍏�" />
+          <el-input :value="match(form.registrantId)" v-model.number="form.registrantId" disabled placeholder="璇疯緭鍏�"/>
         </el-form-item>
         <el-form-item label="鐧昏鏃ユ湡" prop="registrationDate">
           <el-date-picker
-            disabled
-            v-model="form.registrationDate"
-            type="date"
-            placeholder="YYYY-MM-DD"
-            style="width: 100%"
-            value-format="YYYY-MM-DD"
+              disabled
+              v-model="form.registrationDate"
+              type="date"
+              placeholder="YYYY-MM-DD"
+              style="width: 100%"
+              value-format="YYYY-MM-DD"
           />
         </el-form-item>
       </el-form>
       <template #footer>
         <div class="dialog-footer">
           <!-- 閲嶇疆鍜屽彇娑� -->
-          <el-button @click="handleClose" v-if="title.includes('鏂板')"
-            >鍙栨秷</el-button
+          <el-button @click="handleClose" v-if="title.includes('鏂板') || title.includes('鏌ョ湅')"
+          >鍙栨秷
+          </el-button
           >
           <el-button @click="handleReset" v-if="title.includes('缂栬緫')"
-            >閲嶇疆</el-button
+          >閲嶇疆
+          </el-button
           >
-          <el-button type="primary" @click="handleSubmit">纭</el-button>
+          <el-button type="primary" v-if="!isViewMode" @click="handleSubmit">纭</el-button>
         </div>
       </template>
     </el-dialog>
@@ -130,12 +128,11 @@
 </template>
 
 <script setup name="ProductionDialog">
-import { ref, defineProps, watch, onMounted, nextTick, computed } from "vue";
-import { ElMessage } from "element-plus";
+import {ref, defineProps, watch, onMounted, nextTick, computed} from "vue";
+import {ElMessage} from "element-plus";
 import useUserStore from "@/store/modules/user";
-import { addOrEditPR,getSupplyList, getCoalInfoList } from "@/api/procureMent";
-import { getSupply } from "@/api/basicInformation/supplier";
-import { getCoalInfo } from "@/api/basicInformation/coal";
+import {addOrEditPR, getSupplyList, getCoalInfoList} from "@/api/procureMent";
+
 const props = defineProps({
   title: {
     type: String,
@@ -157,6 +154,7 @@
 });
 const supplyList = ref([]);
 const coalList = ref([]);
+const isViewMode = computed(() => props.title.includes("鏌ョ湅"));
 // 鑾峰彇渚涘簲鍟嗕笅鎷夊拰鐓ょ涓嬫媺
 const getDropdownData = async () => {
   try {
@@ -164,7 +162,6 @@
       getSupplyList(),
       getCoalInfoList(),
     ]);
-    console.log(supplyRes, coalRes);
     let supplyData = supplyRes.data;
     let coalData = coalRes.data;
     supplyList.value = supplyData.map((item) => ({
@@ -183,140 +180,121 @@
 defineExpose({
   getDropdownData,
 });
+// 鏁板�兼牸寮忓寲宸ュ叿鍑芥暟
 const toFixed = (num, precision = 2) => {
   if (isNaN(num) || num === null || num === undefined || num === "") {
     return 0;
   }
-  return (
-    Math.floor(parseFloat(num) * Math.pow(10, precision)) /
-    Math.pow(10, precision)
-  );
+  return Number((Math.floor(parseFloat(num) * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision));
 };
-// 鍚◣鍗曚环璁$畻
-const unitPriceWithTax = computed(() => {
-  const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0;
-  const taxRate = parseFloat(form.value.taxRate) || 0;
-  if (!priceExcludingTax || !taxRate) {
-    return 0;
-  }
-  const result = priceExcludingTax * (1 + taxRate / 100);
-  return toFixed(result, 2);
-});
 
-// 鍚◣鎬讳环璁$畻
-const totalUnitPriceWithTax = computed(() => {
-  const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0;
-  const taxRate = parseFloat(form.value.taxRate) || 0;
-  const purchaseQuantity = parseFloat(form.value.purchaseQuantity) || 0;
+// 瀹夊叏鑾峰彇鏁板��
+const safeNumber = (value) => {
+  const num = parseFloat(value);
+  return isNaN(num) ? 0 : num;
+};
 
-  if (!priceExcludingTax || !taxRate || !purchaseQuantity) {
-    return 0;
-  }
+// 璁$畻閫昏緫 - 鍩轰簬鍚◣鍗曚环璁$畻涓嶅惈绋庝环鏍�
+const calculatePrices = () => {
+  const priceIncludingTax = safeNumber(form.value.priceIncludingTax); // 鍚◣鍗曚环
+  const taxRate = safeNumber(form.value.taxRate); // 绋庣巼
+  const quantity = safeNumber(form.value.purchaseQuantity); // 閲囪喘鏁伴噺
 
-  const unitPriceWithTaxValue = priceExcludingTax * (1 + taxRate / 100);
-  const result = unitPriceWithTaxValue * purchaseQuantity;
-  return toFixed(result, 2);
-});
+  // 1. 鏍规嵁鍚◣鍗曚环鍜岀◣鐜囪绠椾笉鍚◣鍗曚环
+  // 涓嶅惈绋庡崟浠� = 鍚◣鍗曚环 / (1 + 绋庣巼/100)
+  const priceExcludingTax = priceIncludingTax && taxRate 
+    ? toFixed(priceIncludingTax / (1 + taxRate / 100), 2)
+    : 0;
 
-// 涓嶅惈绋庢�讳环璁$畻
-const taxExclusiveTotalPrice = computed(() => {
-  const purchaseQuantity = parseFloat(form.value.purchaseQuantity) || 0;
-  const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0;
+  // 2. 璁$畻涓嶅惈绋庢�讳环 = 涓嶅惈绋庡崟浠� 脳 鏁伴噺
+  const totalPriceExcludingTax = priceExcludingTax && quantity
+    ? toFixed(priceExcludingTax * quantity, 2)
+    : 0;
 
-  if (!purchaseQuantity || !priceExcludingTax) {
-    return 0;
-  }
+  // 3. 璁$畻鍚◣鎬讳环 = 鍚◣鍗曚环 脳 鏁伴噺
+  const totalPriceIncludingTax = priceIncludingTax && quantity
+    ? toFixed(priceIncludingTax * quantity, 2)
+    : 0;
 
-  const result = purchaseQuantity * priceExcludingTax;
-  return toFixed(result, 2);
-});
+  // 鏇存柊琛ㄥ崟鏁版嵁
+  form.value.priceExcludingTax = priceExcludingTax;
+  form.value.totalPriceExcludingTax = totalPriceExcludingTax;
+  form.value.totalPriceIncludingTax = totalPriceIncludingTax;
+};
 
-// 鐩戝惉璁$畻鍊煎彉鍖栵紝鍚屾鍒� form 瀵硅薄涓�
-watch(unitPriceWithTax, (newValue) => {
-  form.value.priceIncludingTax = newValue;
-});
-
-watch(totalUnitPriceWithTax, (newValue) => {
-  form.value.totalPriceIncludingTax = newValue;
-});
-
-watch(taxExclusiveTotalPrice, (newValue) => {
-  form.value.totalPriceExcludingTax = newValue;
-});
+// 鐩戝惉琛ㄥ崟瀵硅薄鍙樺寲锛岀敤浜庡鐞嗙紪杈戞ā寮忎笅鐨勬暟鎹姞杞藉拰瀹炴椂璁$畻
+watch(
+  () => [form.value.priceIncludingTax, form.value.taxRate, form.value.purchaseQuantity],
+  () => {
+    // 闃叉姈澶勭悊锛岄伩鍏嶉绻佽绠�
+    nextTick(() => {
+      calculatePrices();
+    });
+  },
+  { deep: true }
+);
 
 const userStore = useUserStore();
 const userInfo = ref({});
-
-// 澶勭悊绋庣巼杈撳叆妗嗗け鐒︼紝纭繚绮惧害
+const match = () => {
+  return userInfo.value.nickName || "鏈煡鐢ㄦ埛";
+};
+// 澶勭悊绋庣巼杈撳叆妗嗗け鐒︿簨浠�
 const handleTaxRateBlur = () => {
-  if (
-    form.value.taxRate !== null &&
-    form.value.taxRate !== undefined &&
-    form.value.taxRate !== ""
-  ) {
+  if (form.value.taxRate !== null && form.value.taxRate !== undefined && form.value.taxRate !== "") {
     form.value.taxRate = toFixed(parseFloat(form.value.taxRate), 2);
+    // watch 浼氳嚜鍔ㄨЕ鍙� calculatePrices锛屼笉闇�瑕佹墜鍔ㄨ皟鐢�
   }
 };
 
-// 澶勭悊涓嶅惈绋庡崟浠疯緭鍏ユ澶辩劍锛岀‘淇濈簿搴�
+// 澶勭悊鍚◣鍗曚环杈撳叆妗嗗け鐒︿簨浠�
 const handlePriceBlur = () => {
-  if (
-    form.value.priceExcludingTax !== null &&
-    form.value.priceExcludingTax !== undefined &&
-    form.value.priceExcludingTax !== ""
-  ) {
-    form.value.priceExcludingTax = toFixed(
-      parseFloat(form.value.priceExcludingTax),
-      2
-    );
+  if (form.value.priceIncludingTax !== null && form.value.priceIncludingTax !== undefined && form.value.priceIncludingTax !== "") {
+    form.value.priceIncludingTax = toFixed(parseFloat(form.value.priceIncludingTax), 2);
+    // watch 浼氳嚜鍔ㄨЕ鍙� calculatePrices锛屼笉闇�瑕佹墜鍔ㄨ皟鐢�
   }
 };
 
-// 澶勭悊閲囪喘鏁伴噺杈撳叆妗嗗け鐒︼紝纭繚绮惧害
+// 澶勭悊閲囪喘鏁伴噺杈撳叆妗嗗け鐒︿簨浠�
 const handleQuantityBlur = () => {
-  if (
-    form.value.purchaseQuantity !== null &&
-    form.value.purchaseQuantity !== undefined &&
-    form.value.purchaseQuantity !== ""
-  ) {
-    form.value.purchaseQuantity = toFixed(
-      parseFloat(form.value.purchaseQuantity),
-      3
-    ); // 鏁伴噺淇濈暀3浣嶅皬鏁�
+  if (form.value.purchaseQuantity !== null && form.value.purchaseQuantity !== undefined && form.value.purchaseQuantity !== "") {
+    form.value.purchaseQuantity = toFixed(parseFloat(form.value.purchaseQuantity), 3); // 鏁伴噺淇濈暀3浣嶅皬鏁�
+    // watch 浼氳嚜鍔ㄨЕ鍙� calculatePrices锛屼笉闇�瑕佹墜鍔ㄨ皟鐢�
   }
 };
 
 onMounted(async () => {
   let res = await userStore.getInfo();
-  userInfo.value = res;
-  getDropdownData()
+  userInfo.value = res.user;
+  await getDropdownData();
+  // 缁勪欢鍔犺浇瀹屾垚鍚庤Е鍙戜竴娆¤绠�
+  calculatePrices();
 });
 const rules = {
   supplierName: [
-    { required: true, message: "璇疯緭鍏ヤ緵搴斿晢鍚嶇О", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ヤ緵搴斿晢鍚嶇О", trigger: "blur"},
   ],
-  coal: [{ required: true, message: "璇疯緭鍏ョ叅绉�", trigger: "blur" }],
-  unit: [{ required: true, message: "璇疯緭鍏ュ崟浣�", trigger: "blur" }],
+  coal: [{required: true, message: "璇疯緭鍏ョ叅绉�", trigger: "blur"}],
   purchaseQuantity: [
-    { required: true, message: "璇疯緭鍏ラ噰璐暟閲�", trigger: "blur" },
-    { type: "number", message: "閲囪喘鏁伴噺蹇呴』涓烘暟瀛�", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ラ噰璐暟閲�", trigger: "blur"},
+    {type: "number", message: "閲囪喘鏁伴噺蹇呴』涓烘暟瀛�", trigger: "blur"},
   ],
   priceExcludingTax: [
-    { required: true, message: "璇疯緭鍏ュ崟浠�", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ュ崟浠�", trigger: "blur"},
   ],
   totalPriceExcludingTax: [
-    { required: true, message: "璇疯緭鍏ユ�讳环", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ユ�讳环", trigger: "blur"},
   ],
   priceIncludingTax: [
-    { required: true, message: "璇疯緭鍏ュ惈绋庡崟浠�", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ュ惈绋庡崟浠�", trigger: "blur"},
   ],
   totalPriceIncludingTax: [
-    { required: true, message: "璇疯緭鍏ュ惈绋庢�讳环", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ュ惈绋庢�讳环", trigger: "blur"},
   ],
-  taxRate: [{ required: true, message: "璇疯緭鍏ョ◣鐜�", trigger: "blur" }],
-  registrantId: [{ required: true, message: "璇疯緭鍏ョ櫥璁颁汉", trigger: "blur" }],
+  taxRate: [{required: true, message: "璇疯緭鍏ョ◣鐜�", trigger: "blur"}],
+  registrantId: [{required: true, message: "璇疯緭鍏ョ櫥璁颁汉", trigger: "blur"}],
   registrationDate: [
-    { required: true, message: "璇烽�夋嫨鐧昏鏃ユ湡", trigger: "change" },
+    {required: true, message: "璇烽�夋嫨鐧昏鏃ユ湡", trigger: "change"},
   ],
 };
 // 鍏抽棴寮圭獥

--
Gitblit v1.9.3