From e3bf21045fc29371449c7e888d786370dc962ae1 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 07 九月 2026 15:42:09 +0800
Subject: [PATCH] feat(inspection): 优化检验数据保存逻辑

---
 src/views/business/inspectionTask/inspection.vue |  103 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 73 insertions(+), 30 deletions(-)

diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue
index 1bb499c..8b4c763 100644
--- a/src/views/business/inspectionTask/inspection.vue
+++ b/src/views/business/inspectionTask/inspection.vue
@@ -144,7 +144,7 @@
           <el-select v-if="cableTagList.length > 0" v-model="currentTab" clearable placeholder="璇烽�夋嫨" size="small"
             @change="(m) => handleChangeCableTag(currentSample.id, 0, 'cableTag', m)
               " @focus="getCableTag(currentSample.id)">
-            <el-option v-for="item in cableTagList" :key="item.cableTag" :label="item.cableTag" :value="item.cableTag">
+            <el-option v-for="(item, index) in cableTagList" :key="index" :label="item.cableTag" :value="item.cableTag">
               <span style="float: left">{{ item.cableTag }}</span>
               <el-tag v-if="item.status == 0" size="small" style="float: right; margin-top: 5px"
                 type="danger">鏈</el-tag>
@@ -159,7 +159,7 @@
             size="small" @change="(m) =>
               handleChangeCableTag(currentSample.id, 0, 'repetitionTag', m)
               " @focus="getRepetitionTag(currentSample.id)">
-            <el-option v-for="item in repetitionTagList" :key="item.repetitionTag" :label="item.radius"
+            <el-option v-for="(item, index) in repetitionTagList" :key="index" :label="item.radius"
               :value="item.repetitionTag">
               <span style="float: left">{{ item.radius }}</span>
               <el-tag v-if="item.status == 0" size="small" style="float: right; margin-top: 5px"
@@ -173,7 +173,7 @@
           <span v-if="typeSource == '1'">&nbsp;&nbsp;寰呮楠屾暟閲忥細</span>
           <el-select v-if="typeSource == '1'" v-model="rawMaterialTag" placeholder="璇烽�夋嫨" size="small" @change="(m) => handleChangeCableTag(currentSample.id, 4, 'cableTag', m)
             " @focus="getRawMaterialTag(currentSample.id)">
-            <el-option v-for="item in rawMaterialTagList" :key="item.rawMaterialTag" :label="item.rawMaterialTag"
+            <el-option v-for="(item, index) in rawMaterialTagList" :key="index" :label="item.rawMaterialTag"
               :value="item.rawMaterialTag">
               <span style="float: left">{{ item.rawMaterialTag }}</span>
               <el-tag v-if="item.status == 0" size="small" style="float: right; margin-top: 5px"
@@ -756,6 +756,8 @@
       result: null,
       worker: null,
       worker0: null,
+      // 妫�楠屽�兼寜瑙﹀彂椤哄簭涓茶淇濆瓨锛岄伩鍏嶅悓涓�妫�楠岄」鐨勬棫璇锋眰瑕嗙洊鏂拌姹傘��
+      saveQueue: null,
       wareLength: [],
       dataAcquisitionInfo: {},
       dataAcquisitionInfoNew: {},
@@ -898,6 +900,7 @@
     },
   },
   created() {
+    this.saveQueue = Promise.resolve();
     let { sonLaboratory, orderId, state, inspectorList, typeSource,isSplit } =
       this.$route.query;
     this.sonLaboratory = sonLaboratory;
@@ -932,8 +935,9 @@
       this.refreshView()
     },
     // 鐩戝惉褰撳墠妯℃澘鍙樺寲
-    currentTable(val1, val0) {
+    async currentTable(val1, val0) {
       if (val0 != null && val1 != val0) {
+        await this.waitForPendingSaves();
         if (this.changeType && this.changeType > 0) {
           // 濡傛灉鏄厜绾ゃ�佸厜绾ゅ甫锛屽垯涓嶆墽琛屼笅闈㈡搷浣�
           return;
@@ -1137,7 +1141,8 @@
       this.checkUser = "";
     },
     // 鍒锋柊椤甸潰
-    refreshView() {
+    async refreshView() {
+      await this.waitForPendingSaves();
       this.loading = true;
       doInsOrder({
         id: this.id,
@@ -1739,6 +1744,7 @@
     },
     // 鍒囨崲鏍峰搧
     async handleChangeSample(row, column, event) {
+      await this.waitForPendingSaves();
       // 鍒濆鍖栨暟鎹�
       this.param = {};
       this.sampleVisible = false;
@@ -2463,26 +2469,30 @@
             currentInsItem: n,
           })
         );
+        // 鍏堜繚瀛樹富绾跨▼涓凡缁忚緭鍏ョ殑鍘熷鍊笺�俉orker 瀹屾垚璁$畻鍚庝細鍐嶆鍏ラ槦淇濆瓨璁$畻缁撴灉銆�
+        // 杩欐牱鍗充娇鐢ㄦ埛杈撳叆鍚庣珛鍗冲埛鏂般�佸垏鎹㈡垨杩斿洖锛屾渶鍚庣紪杈戠殑鍗曞厓鏍间篃涓嶄細涓㈠け銆�
+        if (currentInsItemId) {
+          this.saveInsContext(currentInsItemId);
+        }
       } catch (error) {
         console.log(444, error);
       }
 
       // 鐩戝惉 Worker 杩斿洖鐨勭粨鏋�
       this.worker.onmessage = (event) => {
-        this.result = JSON.parse(event.data);
-        switch (this.result.method) {
+        const workerResult = JSON.parse(event.data);
+        this.result = workerResult;
+        switch (workerResult.method) {
           case "saveInsContext":
             this.$nextTick(() => {
+              const resultValue = workerResult.value;
               // this.$delete(this.tableList[0],'arr')
               this.$set(
                 this.tableList[0],
                 "arr",
-                this.result.value.tableList[0].arr
+                resultValue.tableList[0].arr
               );
-              this.param = this.result.value.param;
-              if (this.result.value.currentInsItemId) {
-                currentInsItemId = this.result.value.currentInsItemId;
-              }
+              this.param = resultValue.param;
               // 鐗规畩澶勭悊涓�涓嬬粨璁�,浼氭湁杩欑鐗规畩鎯呭喌
               for (var i in this.param) {
                 if (
@@ -2497,23 +2507,28 @@
                   }
                 }
               }
-              this.saveInsContext(currentInsItemId);
+              const sourceInsItemId =
+                resultValue.sourceInsItemId != null &&
+                  resultValue.sourceInsItemId !== ""
+                  ? resultValue.sourceInsItemId
+                  : currentInsItemId;
+              this.saveInsContext([
+                sourceInsItemId,
+                resultValue.currentInsItemId,
+              ]);
             });
             break;
           case "tableList":
             this.$nextTick(() => {
               // 鏇存柊鏁版嵁
               this.$delete(this.tableList[0], "arr");
-              this.$set(this.tableList[0], "arr", this.result.value[0].arr);
+              this.$set(this.tableList[0], "arr", workerResult.value[0].arr);
               // this.param = this.result.value.param
-              if (this.result.value.currentInsItem) {
-                currentInsItemId = this.result.value.currentInsItem.i;
-              }
             });
             break;
           case "getCurrentInsProduct":
             // 鏇存柊椤甸潰鏁版嵁
-            this.getCurrentInsProduct(this.result.value);
+            this.getCurrentInsProduct(workerResult.value);
             break;
         }
       };
@@ -2830,7 +2845,7 @@
           this.submitLoading = false;
         });
     },
-    submit() {
+    async submit() {
       if (this.verifyUser === null || this.verifyUser === "") {
         this.$message.error("璇锋寚瀹氬鏍镐汉鍛�");
         return;
@@ -2851,6 +2866,7 @@
         this.$message.error("璇峰~鍐橧FS搴撳瓨鐗╂枡鎵规灞炴��");
         return;
       }
+      await this.waitForPendingSaves();
       this.submitLoading = true;
       checkSubmitPlan({
         orderId: this.orderId,
@@ -2940,14 +2956,26 @@
       return;
     },
     // 缁熶竴鍦ㄨ繖閲屼繚瀛樻暟鎹�
-    saveInsContext(currentInsItemId) {
+    saveInsContext(currentInsItemIds) {
       try {
         if (this.param) {
-          let param = null;
-          if (currentInsItemId) {
-            param = { [currentInsItemId]: this.param[currentInsItemId] };
-          } else {
-            param = this.param;
+          const ids = (Array.isArray(currentInsItemIds)
+            ? currentInsItemIds
+            : [currentInsItemIds]
+          )
+            .filter((id) => id != null && id !== "")
+            .map((id) => String(id));
+          let param = this.param;
+          if (ids.length > 0) {
+            param = {};
+            [...new Set(ids)].forEach((id) => {
+              if (this.param[id]) {
+                param[id] = this.param[id];
+              }
+            });
+            if (Object.keys(param).length === 0) {
+              return;
+            }
           }
           let isNoTestValue = ''
           for (let key in param) {
@@ -2959,16 +2987,25 @@
               }
             }
           }
-          saveInsContext({
+          const payload = {
             param: JSON.stringify(param),
             currentTable: this.currentTable,
             sampleId: this.currentSample.id,
             orderId: this.orderId,
             sonLaboratory: this.sonLaboratory,
             isNoTestValue: isNoTestValue
-          }).then((res) => {
-            this.$message.success("宸蹭繚瀛�");
-          });
+          };
+          const previousSave = this.saveQueue || Promise.resolve();
+          this.saveQueue = previousSave
+            .catch(() => undefined)
+            .then(() => saveInsContext(payload))
+            .then(() => {
+              this.$message.success("宸蹭繚瀛�");
+            })
+            .catch((error) => {
+              console.error("妫�楠屾暟鎹繚瀛樺け璐�", error);
+              this.$message.error("妫�楠屾暟鎹繚瀛樺け璐ワ紝璇烽噸璇�");
+            });
           // 鍚� Worker 鍙戦�佹秷鎭紝寮�濮嬪鐞嗛�昏緫
           this.worker.postMessage(
             JSON.stringify({
@@ -2982,6 +3019,11 @@
         }
       } catch (error) {
         console.log(999, error);
+      }
+    },
+    async waitForPendingSaves() {
+      if (this.saveQueue) {
+        await this.saveQueue;
       }
     },
     // 璁惧鏀瑰彉
@@ -3145,7 +3187,8 @@
         return v;
       }
     },
-    goback() {
+    async goback() {
+      await this.waitForPendingSaves();
       this.$router.go(-1)
     }
   },

--
Gitblit v1.9.3