From 646135b9c54d6ccf5d47af30bf208bdfe5005017 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 09 十二月 2025 10:31:44 +0800
Subject: [PATCH] fix: 二维码内容简化,只传一个id。根据id查询详细信息。

---
 src/pages/outbound/index.vue |  256 +++++++++++++++++++--------------------------------
 1 files changed, 95 insertions(+), 161 deletions(-)

diff --git a/src/pages/outbound/index.vue b/src/pages/outbound/index.vue
index a3a435c..ec42661 100644
--- a/src/pages/outbound/index.vue
+++ b/src/pages/outbound/index.vue
@@ -25,6 +25,18 @@
               <text class="outbound_item_value">{{ item.model || "-" }}</text>
             </view>
             <view class="outbound_item_row">
+              <text class="outbound_item_label">閲嶉噺锛�</text>
+              <text class="outbound_item_value">{{ item.weight || "-" }} kg</text>
+            </view>
+            <view class="outbound_item_row">
+              <text class="outbound_item_label">鍘傚锛�</text>
+              <text class="outbound_item_value">{{ item.clienteleName || "-" }}</text>
+            </view>
+            <view class="outbound_item_row">
+              <text class="outbound_item_label">娈甸暱锛�</text>
+              <text class="outbound_item_value">{{ item.actuallyLength || "-" }} M</text>
+            </view>
+            <view class="outbound_item_row">
               <text class="outbound_item_label">鐢熶骇鏃ユ湡锛�</text>
               <text class="outbound_item_value">{{ item.productionDate || "-" }}</text>
             </view>
@@ -68,170 +80,92 @@
   return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
 };
 
-// 瑙f瀽鎵爜鍐呭
-const parseScanCode = (scanCode: string) => {
-  try {
-    // 绗竴娆¤В鏋愶細瑙f瀽澶栧眰JSON
-    const outerParsed = JSON.parse(scanCode);
-
-    // 濡傛灉澶栧眰鏈� code 瀛楁锛屼笖鏄瓧绗︿覆锛岄渶瑕佸啀娆¤В鏋�
-    let innerData = null;
-    if (outerParsed.code && typeof outerParsed.code === "string") {
-      try {
-        const innerParsed = JSON.parse(outerParsed.code);
-
-        // 鏌ユ壘鎵�鏈夋暟瀛梜ey锛堝 "12480"锛夛紝杩欎釜鏁板瓧key灏辨槸id
-        const keys = Object.keys(innerParsed);
-        // 鎵惧埌鎵�鏈夋暟瀛梜ey锛屾帓闄� "code" 瀛楁
-        const numberKeys = keys.filter((key) => !isNaN(Number(key)) && key !== "code");
-
-        if (numberKeys.length > 0) {
-          // 鍙栫涓�涓暟瀛梜ey锛堣繖涓氨鏄痠d锛�
-          const dataKey = numberKeys[0];
-          const idValue = Number(dataKey); // 鏁板瓧key灏辨槸id鍊�
-          // 鎻愬彇鏁板瓧key瀵瑰簲鐨勬暟鎹璞�
-          const extractedData = innerParsed[dataKey];
-          if (extractedData) {
-            innerData = { ...extractedData }; // 澶嶅埗鏁版嵁瀵硅薄
-            // 纭繚鏁版嵁瀵硅薄涓湁id瀛楁锛屽鏋滄病鏈夊垯浣跨敤鏁板瓧key浣滀负id
-            if (!innerData.id) {
-              innerData.id = idValue;
-            }
-          }
-        } else {
-          // 濡傛灉娌℃湁鏁板瓧key锛屽皾璇曠洿鎺ヤ娇鐢ㄥ璞★紙鎺掗櫎 code 瀛楁锛�
-          const { code, ...rest } = innerParsed;
-          if (Object.keys(rest).length > 0) {
-            innerData = rest;
-          }
-        }
-      } catch (e) {
-        console.error("鍐呭眰JSON瑙f瀽澶辫触:", e);
-      }
-    } else {
-      // 濡傛灉娌℃湁 code 瀛楁锛岀洿鎺ヤ娇鐢ㄥ灞傛暟鎹�
-      innerData = outerParsed;
-    }
-
-    // 濡傛灉 innerData 浠嶇劧涓虹┖锛屽皾璇曠洿鎺ヨВ鏋�
-    if (!innerData) {
-      innerData = outerParsed;
-    }
-
-    // 濡傛灉 innerData 浠嶇劧鍖呭惈鏁板瓧key缁撴瀯锛堝 { "12480": {...}, "code": "..." }锛夛紝闇�瑕佸啀娆℃彁鍙�
-    if (innerData && typeof innerData === "object" && !innerData.id && !innerData.contractno) {
-      const keys = Object.keys(innerData);
-      const numberKeys = keys.filter((key) => !isNaN(Number(key)) && key !== "code");
-      if (numberKeys.length > 0) {
-        const dataKey = numberKeys[0];
-        const extractedData = innerData[dataKey];
-        if (extractedData) {
-          innerData = { ...extractedData };
-        }
-      }
-    }
-
-    // 鎻愬彇鏁版嵁瀛楁锛堟牴鎹簩缁寸爜瀹為檯瀛楁鍚嶇粺涓�锛�
-    const data = {
-      id: innerData?.id,
-      contractNo: innerData?.contractno,
-      batchNo: innerData?.monofilamentnumber,
-      model: innerData?.model,
-      weight: innerData?.actuallyweight,
-      productionDate: innerData?.producttime,
-      projectId: innerData?.projectid,
-      // 淇濈暀鍘熷鏁版嵁锛堜繚瀛樻彁鍙栧悗鐨勬暟鎹璞★級
-      rawData: innerData,
-      scanCode: scanCode,
-    };
-
-    // 濡傛灉鎵爜鏁版嵁涓湁 projectId锛屼繚瀛樺畠
-    if (data.projectId && !projectId.value) {
-      projectId.value = data.projectId;
-    }
-
-    return data;
-  } catch (error) {
-    console.error("JSON瑙f瀽澶辫触:", error);
-    // 濡傛灉涓嶆槸JSON锛屽皾璇曟寜閫楀彿鍒嗗壊锛堝彲鑳芥槸CSV鏍煎紡锛�
-    const parts = scanCode.split(",");
-    if (parts.length >= 5) {
-      return {
-        id: parts[0] || "-", // 鍋囪绗竴涓槸id
-        contractNo: parts[1] || "-",
-        batchNo: parts[2] || "-",
-        model: parts[3] || "-",
-        weight: parts[4] || "-",
-        productionDate: parts[5] || "-",
-        projectId: projectId.value || "-",
-        scanCode: scanCode,
-      };
-    }
-    // 濡傛灉閮芥棤娉曡В鏋愶紝杩斿洖鍘熷瀛楃涓�
-    return {
-      id: scanCode, // 浣跨敤鍘熷瀛楃涓蹭綔涓篿d
-      contractNo: scanCode,
-      batchNo: "-",
-      model: "-",
-      weight: "-",
-      productionDate: "-",
-      projectId: projectId.value || "-",
-      scanCode: scanCode,
-    };
-  }
-};
-
 // 鎵爜鍥炶皟
-const getScanCode = (code: any) => {
-  // 濡傛灉 code 鏄璞′笖鏈� code 瀛楁锛屼娇鐢� code.code锛涘惁鍒欑洿鎺ヤ娇鐢� code
-  let scanCode = code.code || code;
+const getScanCode = async (code: any) => {
+  try {
+    // 濡傛灉 code 鏄璞′笖鏈� code 瀛楁锛屼娇鐢� code.code锛涘惁鍒欑洿鎺ヤ娇鐢� code
+    let scanCode = code.code || code;
 
-  // 濡傛灉 scanCode 鏄璞★紝灏濊瘯鑾峰彇鍏� code 瀛楁
-  if (typeof scanCode === "object" && scanCode.code) {
-    scanCode = scanCode.code;
+    // 濡傛灉 scanCode 鏄璞★紝灏濊瘯鑾峰彇鍏� code 瀛楁
+    if (typeof scanCode === "object" && scanCode.code) {
+      scanCode = scanCode.code;
+    }
+
+    // 濡傛灉 scanCode 鏄瓧绗︿覆锛岀洿鎺ヤ娇鐢紱濡傛灉鏄璞★紝杞负瀛楃涓�
+    if (typeof scanCode !== "string") {
+      scanCode = JSON.stringify(scanCode);
+    }
+
+    if (!scanCode) {
+      toast.error("鎵爜鍐呭涓虹┖");
+      return;
+    }
+
+    // 瑙f瀽鎵爜鏁版嵁锛岀幇鍦ㄤ簩缁寸爜鍙寘鍚玦d
+    let scanData;
+    try {
+      scanData = JSON.parse(scanCode);
+    } catch (e) {
+      toast.error("浜岀淮鐮佹牸寮忛敊璇�");
+      return;
+    }
+
+    const outPutId = scanData.id;
+
+    if (!outPutId) {
+      toast.error("浜岀淮鐮佹牸寮忛敊璇紝缂哄皯id淇℃伅");
+      return;
+    }
+
+    // 妫�鏌ユ槸鍚﹀凡瀛樺湪锛堟牴鎹甶d鍒ゆ柇锛�
+    const exists = outboundList.value.some((item) => {
+      const itemId = item.id;
+      return itemId && itemId === outPutId && itemId !== "-";
+    });
+
+    if (exists) {
+      toast.error("璇ユ潯鐮佸凡瀛樺湪锛岃鍕块噸澶嶆壂鐮�");
+      return;
+    }
+
+    // 璋冪敤鎺ュ彛鑾峰彇缁炵嚎璇︾粏淇℃伅
+    const { data: tagData } = await OutboundApi.getTagByIdJx({
+      outPutId: outPutId,
+    });
+
+    // 鎻愬彇鏁版嵁瀛楁锛堟牴鎹帴鍙h繑鍥炵殑鏁版嵁缁撴瀯锛�
+    const parsedData = {
+      id: tagData?.id || outPutId,
+      contractNo: tagData?.contractno || tagData?.contractNo || "-",
+      batchNo: tagData?.systemno || tagData?.systemNo || tagData?.batchNo || "-",
+      model: tagData?.model || "-",
+      weight: tagData?.actuallyweight || tagData?.actuallyWeight || tagData?.weight || "-",
+      clienteleName: tagData?.clientelename || tagData?.clienteleName || "-",
+      actuallyLength: tagData?.actuallylength || tagData?.actuallyLength || "-",
+      productionDate: tagData?.producttime || tagData?.productionDate || "-",
+      projectId: tagData?.projectid || tagData?.projectId || projectId.value || "",
+      // 淇濈暀鍘熷鏁版嵁
+      rawData: tagData,
+      scanCode: scanCode,
+    };
+
+    // 濡傛灉鎺ュ彛杩斿洖鐨勬暟鎹腑鏈� projectId锛屼繚瀛樺畠
+    if (parsedData.projectId && !projectId.value) {
+      projectId.value = parsedData.projectId;
+    }
+
+    // 娣诲姞鍒板垪琛�
+    const newItem = {
+      ...parsedData,
+      scanTime: formatTime(new Date()),
+    };
+
+    outboundList.value.push(newItem);
+    toast.success("鎵爜鎴愬姛");
+  } catch (error: any) {
+    console.error("鎵爜澶勭悊澶辫触:", error);
+    toast.error(error.msg || "浜岀淮鐮佸紓甯革紝璇锋洿鎹簩缁寸爜锛�");
   }
-
-  // 濡傛灉 scanCode 鏄瓧绗︿覆锛岀洿鎺ヤ娇鐢紱濡傛灉鏄璞★紝杞负瀛楃涓�
-  if (typeof scanCode !== "string") {
-    scanCode = JSON.stringify(scanCode);
-  }
-
-  if (!scanCode) {
-    toast.error("鎵爜鍐呭涓虹┖");
-    return;
-  }
-
-  // 瑙f瀽鎵爜鍐呭
-  const parsedData = parseScanCode(scanCode);
-
-  // 浣跨敤id浣滀负鍞竴鏍囪瘑
-  const uniqueId = parsedData.id;
-
-  // 濡傛灉娌℃湁id锛屾彁绀洪敊璇�
-  if (!uniqueId || uniqueId === "-" || uniqueId === null || uniqueId === undefined) {
-    toast.error("鎵爜鍐呭缂哄皯鍞竴鏍囪瘑锛屾棤娉曟坊鍔�");
-    return;
-  }
-
-  // 妫�鏌ユ槸鍚﹀凡瀛樺湪锛堟牴鎹甶d鍒ゆ柇锛�
-  const exists = outboundList.value.some((item) => {
-    const itemId = item.id;
-    return itemId && itemId === uniqueId && itemId !== "-";
-  });
-
-  if (exists) {
-    toast.error("璇ユ潯鐮佸凡瀛樺湪锛岃鍕块噸澶嶆壂鐮�");
-    return;
-  }
-
-  // 娣诲姞鍒板垪琛�
-  const newItem = {
-    ...parsedData,
-    scanTime: formatTime(new Date()),
-  };
-
-  outboundList.value.push(newItem);
-  toast.success("鎵爜鎴愬姛");
 };
 
 // 瑙﹀彂鎵爜

--
Gitblit v1.9.3