From f2e14fbd69737ca7717835fcc4e02c0f01de10d4 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期一, 02 二月 2026 10:12:42 +0800
Subject: [PATCH] fix: 修复扫码时code参数格式不一致导致的解析错误

---
 src/pages/production/twist/receive/monofil.vue |   51 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/src/pages/production/twist/receive/monofil.vue b/src/pages/production/twist/receive/monofil.vue
index b4998fc..23ffec7 100644
--- a/src/pages/production/twist/receive/monofil.vue
+++ b/src/pages/production/twist/receive/monofil.vue
@@ -129,21 +129,45 @@
       return;
     }
 
-    // 瑙f瀽鎵爜鏁版嵁
-    const scanData = JSON.parse(code.code);
+    // 瑙f瀽鎵爜鏁版嵁锛氬彲鑳藉寘鍚� id(outPutId) 鎴� monofilamentNumber
+    let scanCode = code.code || code;
+    const scanData = JSON.parse(scanCode);
+    const outPutId = scanData.id;
+    const monofilamentNumber = scanData.monofilamentNumber;
 
-    // 鍒ゆ柇灞傜骇鏄惁鍖归厤
-    if (scanData.layer && scanData.layer !== currentLayer.twistedLayer) {
-      toast.error(
-        `棰嗙敤灞傜骇涓嶅锛屽綋鍓嶅眰鏄細${currentLayer.twistedLayer}锛岄鐢ㄥ崟涓濆眰鏄細${scanData.layer}`
-      );
-      // return;
+    let data: any;
+
+    if (outPutId) {
+      // 鏈� outPutId锛氬厛鏌ュ眰绾э紝鍐嶈皟 scarn
+      const { data: tagData } = await TwistApi.getTagByIdLs({
+        outPutId: outPutId,
+      });
+      if (tagData.layer && tagData.layer !== currentLayer.twistedLayer) {
+        toast.error(
+          `棰嗙敤灞傜骇涓嶅锛屽綋鍓嶅眰鏄細${currentLayer.twistedLayer}锛岄鐢ㄥ崟涓濆眰鏄細${tagData.layer}`
+        );
+      }
+      const res = await TwistApi.getScarn({
+        outPutId: outPutId,
+        twistId: currentLayer.twistId,
+      });
+      data = res.data;
+    } else if (monofilamentNumber) {
+      // 鏃� outPutId 鏈� monofilamentNumber锛氬彧璋� scarnTag锛岃繑鍥炲惈 layer 鐢ㄤ簬鎻愮ず
+      const res = await TwistApi.getScarnTag({
+        monofilamentNumber,
+        twistId: currentLayer.twistId,
+      });
+      data = res.data;
+      if (data.layer && data.layer !== currentLayer.twistedLayer) {
+        toast.error(
+          `棰嗙敤灞傜骇涓嶅锛屽綋鍓嶅眰鏄細${currentLayer.twistedLayer}锛岄鐢ㄥ崟涓濆眰鏄細${data.layer}`
+        );
+      }
+    } else {
+      toast.error("浜岀淮鐮佹牸寮忛敊璇紝缂哄皯id鎴栧崟涓濈紪鍙蜂俊鎭�");
+      return;
     }
-
-    const { data } = await TwistApi.getScarn({
-      outPutId: scanData.id,
-      twistId: currentLayer.twistId,
-    });
 
     // 妫�鏌ュ綋鍓嶅眰鏄惁宸插瓨鍦ㄨ鍗曚笣
     const exists = currentLayer.strandedWireDish?.some(
@@ -172,6 +196,7 @@
     }
   } catch (error) {
     toast.error("浜岀淮鐮佸紓甯革紝璇锋洿鎹簩缁寸爜锛�");
+    console.log(error);
   }
 };
 

--
Gitblit v1.9.3