From 4d5c966e9ce603a6f920a889766eeb3f227b2199 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 25 三月 2026 14:30:03 +0800
Subject: [PATCH] fix: 检测化验提交后可以再编辑,还可以查看检验详情

---
 src/views/qualityManagement/rawMaterial/components/formDia.vue |  136 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 121 insertions(+), 15 deletions(-)

diff --git a/src/views/qualityManagement/rawMaterial/components/formDia.vue b/src/views/qualityManagement/rawMaterial/components/formDia.vue
index 5b333af..fdbc95c 100644
--- a/src/views/qualityManagement/rawMaterial/components/formDia.vue
+++ b/src/views/qualityManagement/rawMaterial/components/formDia.vue
@@ -2,11 +2,18 @@
   <div>
     <el-dialog
         v-model="dialogFormVisible"
-        :title="operationType === 'add' ? '鏂板鍘熸枡' : '缂栬緫鍘熸枡'"
+        :title="operationType === 'add' ? '鏂板鍘熸枡' : operationType === 'view' ? '鍘熸枡璇︽儏' : '缂栬緫鍘熸枡'"
         width="70%"
         @close="closeDia"
     >
-      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
+      <el-form
+          v-if="operationType !== 'view'"
+          :model="form"
+          label-width="140px"
+          label-position="top"
+          :rules="rules"
+          ref="formRef"
+      >
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="浜у搧鍚嶇О锛�" prop="productId">
@@ -18,7 +25,7 @@
                   @change="getModels"
                   :data="productOptions"
                   :render-after-expand="false"
-                  :disabled="operationType === 'edit'"
+                  :disabled="operationType === 'edit' || operationType === 'view'"
                   style="width: 100%"
               />
             </el-form-item>
@@ -26,7 +33,7 @@
           <el-col :span="12">
             <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productModelId">
               <el-select v-model="form.productModelId" placeholder="璇烽�夋嫨" clearable
-                         :disabled="operationType === 'edit'"
+                         :disabled="operationType === 'edit' || operationType === 'view'"
                          filterable readonly @change="handleChangeModel">
                 <el-option v-for="item in modelOptions" :key="item.id" :label="item.model" :value="item.id"/>
               </el-select>
@@ -41,14 +48,20 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="鎵瑰彿锛�" prop="batchNo">
-              <el-input style="width: 100%" v-model="form.batchNo" placeholder="璇疯緭鍏�" clearable/>
+              <el-input
+                  style="width: 100%"
+                  v-model="form.batchNo"
+                  placeholder="璇疯緭鍏�"
+                  clearable
+                  :disabled="operationType === 'view'"
+              />
             </el-form-item>
           </el-col>
         </el-row>
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="妫�楠岀被鍨嬶細" prop="checkType">
-              <el-select v-model="form.checkType">
+              <el-select v-model="form.checkType" :disabled="operationType === 'view'">
                 <el-option label="鍏ュ巶妫�" :value="0"/>
                 <el-option label="杞﹂棿妫�" :value="1"/>
                 <el-option label="鍑哄巶妫�" :value="2"/>
@@ -57,7 +70,7 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="妫�娴嬬粨鏋滐細" prop="checkResult">
-              <el-select v-model="form.checkResult">
+              <el-select v-model="form.checkResult" :disabled="operationType === 'view'">
                 <el-option label="鍚堟牸" :value="1"/>
                 <el-option label="涓嶅悎鏍�" :value="0"/>
               </el-select>
@@ -67,7 +80,14 @@
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="妫�楠屽憳锛�" prop="checkUserName">
-              <el-select v-model="form.checkUserName" placeholder="璇烽�夋嫨" clearable filterable style="width: 100%">
+              <el-select
+                  v-model="form.checkUserName"
+                  placeholder="璇烽�夋嫨"
+                  clearable
+                  filterable
+                  style="width: 100%"
+                  :disabled="operationType === 'view'"
+              >
                 <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName"
                            :value="item.nickName"/>
               </el-select>
@@ -84,13 +104,34 @@
                   format="YYYY-MM-DD"
                   clearable
                   style="width: 100%"
+                  :disabled="operationType === 'view'"
               />
             </el-form-item>
           </el-col>
         </el-row>
       </el-form>
+      <el-descriptions
+          v-else
+          :column="2"
+          border
+          size="small"
+          style="margin-bottom: 12px;"
+      >
+        <el-descriptions-item label="浜у搧鍚嶇О">{{ viewProductName }}</el-descriptions-item>
+        <el-descriptions-item label="瑙勬牸鍨嬪彿">{{ viewProductModel }}</el-descriptions-item>
+        <el-descriptions-item label="鍗曚綅">{{ form.unit || '-' }}</el-descriptions-item>
+        <el-descriptions-item label="鎵瑰彿">{{ form.batchNo || '-' }}</el-descriptions-item>
+        <el-descriptions-item label="妫�楠岀被鍨�">{{ viewCheckType }}</el-descriptions-item>
+        <el-descriptions-item label="妫�娴嬬粨鏋�">{{ viewCheckResult }}</el-descriptions-item>
+        <el-descriptions-item label="妫�楠屽憳">{{ form.checkUserName || '-' }}</el-descriptions-item>
+        <el-descriptions-item label="妫�娴嬫棩鏈�">{{ form.checkTime || '-' }}</el-descriptions-item>
+      </el-descriptions>
       <div style="margin-bottom: 10px">
-        <el-button type="primary" @click="isShowItems = true">娣诲姞妫�娴嬮」鐩�</el-button>
+        <el-button
+            v-if="operationType !== 'view'"
+            type="primary"
+            @click="isShowItems = true"
+        >娣诲姞妫�娴嬮」鐩�</el-button>
       </div>
       <PIMTable
           rowKey="id"
@@ -101,13 +142,18 @@
           height="400"
       >
         <template #slot="{ row }">
-          <el-input v-model="row.testValue" clearable/>
+          <span v-if="operationType === 'view'">{{ row.testValue }}</span>
+          <el-input
+              v-else
+              v-model="row.testValue"
+              clearable
+          />
         </template>
       </PIMTable>
       <template #footer>
         <div class="dialog-footer">
-          <el-button type="primary" @click="submitForm">纭</el-button>
-          <el-button @click="closeDia">鍙栨秷</el-button>
+          <el-button v-if="operationType !== 'view'" type="primary" @click="submitForm">纭</el-button>
+          <el-button @click="closeDia">{{ operationType === 'view' ? '鍏抽棴' : '鍙栨秷' }}</el-button>
         </div>
       </template>
     </el-dialog>
@@ -117,7 +163,7 @@
 </template>
 
 <script setup>
-import {ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
+import {ref, reactive, toRefs, getCurrentInstance, nextTick, computed} from "vue";
 import {modelList, productTreeList} from "@/api/basicData/product.js";
 import {qualityInspectParamInfo} from "@/api/qualityManagement/qualityInspectParam.js";
 import {qualityInspectDetailByProductId} from "@/api/qualityManagement/metricMaintenance.js";
@@ -190,6 +236,7 @@
         name: '鍒犻櫎',
         type: 'text',
         clickFun: (row) => handleDelete(row.id),
+        disabled: () => operationType.value === 'view',
       }
     ]
   }
@@ -203,6 +250,14 @@
 const currentProductId = ref(0);
 const modelOptions = ref([]);
 
+const getTodayStr = () => {
+  const now = new Date();
+  const y = now.getFullYear();
+  const m = String(now.getMonth() + 1).padStart(2, "0");
+  const d = String(now.getDate()).padStart(2, "0");
+  return `${y}-${m}-${d}`;
+};
+
 // 鎵撳紑寮规
 const openDialog = async (type, row) => {
   operationType.value = type;
@@ -211,7 +266,7 @@
   })
   // 鍏堥噸缃〃鍗曟暟鎹紙淇濇寔瀛楁瀹屾暣锛岄伩鍏嶅脊绐楅娆℃覆鏌撴椂瑙﹀彂蹇呭~绾㈡鈥滈棯涓�涓嬧�濓級
   form.value = {
-    checkTime: "",
+    checkTime: getTodayStr(),
     supplier: "",
     productName: "",
     productId: "",
@@ -246,6 +301,27 @@
     // 缂栬緫妯″紡涓嬶紝鍏堝姞杞芥寚鏍囬�夐」锛岀劧鍚庡姞杞藉弬鏁板垪琛�
     if (currentProductId.value) {
 
+    } else {
+      getQualityInspectParamList(row.id);
+    }
+  }
+  if (operationType.value === 'view') {
+    await fetchData(row.id);
+    currentProductId.value = row.productId || 0
+    if (currentProductId.value) {
+      try {
+        const res = await modelList({id: currentProductId.value});
+        modelOptions.value = res || [];
+        if (form.value.productModelId) {
+          handleChangeModel(form.value.productModelId);
+        }
+      } catch (e) {
+        console.error("鍔犺浇瑙勬牸鍨嬪彿澶辫触", e);
+        modelOptions.value = [];
+      }
+    }
+    if (currentProductId.value) {
+      // 鍔犺浇鍙傛暟鍒楄〃锛屼繚璇佲�滆鎯呪�濅篃鑳藉睍绀哄寲楠屽��/鏍囧噯鍊肩瓑
     } else {
       getQualityInspectParamList(row.id);
     }
@@ -289,7 +365,7 @@
 
 const findNodeById = (nodes, productId) => {
   for (let i = 0; i < nodes.length; i++) {
-    if (nodes[i].value === productId) {
+    if (String(nodes[i].value) === String(productId)) {
       return nodes[i].label; // 鎵惧埌鑺傜偣锛岃繑鍥炶鑺傜偣
     }
     if (nodes[i].children && nodes[i].children.length > 0) {
@@ -301,6 +377,34 @@
   }
   return null; // 娌℃湁鎵惧埌鑺傜偣锛岃繑鍥瀗ull
 };
+
+// 璇︽儏妯″紡灞曠ず瀛楁锛堜笉浣跨敤琛ㄥ崟鎺т欢锛�
+const viewProductName = computed(() => {
+  const id = form.value?.productId
+  const label = id ? findNodeById(productOptions.value || [], id) : null
+  return label || id || '-'
+})
+
+const viewProductModel = computed(() => {
+  const modelId = form.value?.productModelId
+  const matched = (modelOptions.value || []).find((x) => String(x.id) === String(modelId))
+  return matched?.model || modelId || '-'
+})
+
+const viewCheckType = computed(() => {
+  const t = form.value?.checkType
+  if (t === 0 || t === '0') return '鍏ュ巶妫�'
+  if (t === 1 || t === '1') return '杞﹂棿妫�'
+  if (t === 2 || t === '2') return '鍑哄巶妫�'
+  return '-'
+})
+
+const viewCheckResult = computed(() => {
+  const r = form.value?.checkResult
+  if (r === 1 || r === '1') return '鍚堟牸'
+  if (r === 0 || r === '0') return '涓嶅悎鏍�'
+  return '-'
+})
 
 function convertIdToValue(data) {
   return data.map((item) => {
@@ -319,6 +423,7 @@
 
 // 鎻愪氦浜у搧琛ㄥ崟
 const submitForm = () => {
+  if (operationType.value === 'view') return;
   proxy.$refs.formRef.validate(valid => {
     if (valid) {
       const data = {...form.value, qualityInspectItem: tableData.value}
@@ -365,6 +470,7 @@
 };
 
 const handleDelete = (id) => {
+  if (operationType.value === 'view') return;
   tableData.value = tableData.value.filter(item => item.id !== id);
 }
 

--
Gitblit v1.9.3