From deb0a2b84b5a6a7dc916b1a4e625f32c00c87ade Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期二, 27 一月 2026 09:17:25 +0800
Subject: [PATCH] fix(出库): 处理MES缺失的物料并优化扫码逻辑

---
 src/pages/outbound/materialOutbound.vue |  259 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 186 insertions(+), 73 deletions(-)

diff --git a/src/pages/outbound/materialOutbound.vue b/src/pages/outbound/materialOutbound.vue
index 0c7bbcf..876d241 100644
--- a/src/pages/outbound/materialOutbound.vue
+++ b/src/pages/outbound/materialOutbound.vue
@@ -7,14 +7,14 @@
             type="icon"
             icon="scan"
             color="#0d867f"
-            @click="openScan"
             style="color: #0d867f"
+            @click="openScan"
           ></wd-button>
         </template>
       </CardTitle>
 
       <!-- 褰撳墠鐗╂枡淇℃伅 -->
-      <view class="material-info" v-if="currentMaterial">
+      <view v-if="currentMaterial" class="material-info">
         <wd-card custom-class="info-card">
           <view class="info-compact">
             <view class="icon_box">
@@ -55,26 +55,28 @@
               <text class="outbound_item_label">鐢熶骇鎵规鍙凤細</text>
               <text class="outbound_item_value">{{ item.monofilamentNumber || "-" }}</text>
             </view>
-            <view class="outbound_item_row">
-              <text class="outbound_item_label">瑙勬牸鍨嬪彿锛�</text>
-              <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>
+            <template v-if="!item.isMesMissing">
+              <view class="outbound_item_row">
+                <text class="outbound_item_label">瑙勬牸鍨嬪彿锛�</text>
+                <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>
+            </template>
           </view>
         </view>
         <view class="outbound_item_action">
@@ -91,7 +93,7 @@
 
     <!-- 搴曢儴鎸夐挳 -->
     <view v-if="goodsList.length > 0" class="outbound_footer">
-      <wd-button block @click="handleOutbound" style="background: #0d867f">
+      <wd-button block style="background: #0d867f" @click="handleOutbound">
         <text class="text-[#fff]">鍑哄簱</text>
       </wd-button>
     </view>
@@ -126,6 +128,19 @@
   return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
 };
 
+const handleMonofilamentNumber = (value?: string) => {
+  if (!value) return "";
+  if (!value.includes("-")) {
+    if (value.length < 3) {
+      toast.error("鍗曚笣缂栧彿闀垮害涓嶈冻锛屾棤娉曟坊鍔� '-'");
+      return "";
+    }
+    const insertIndex = value.length - 3;
+    return `${value.slice(0, insertIndex)}-${value.slice(insertIndex)}`;
+  }
+  return value;
+};
+
 // 鐩存帴鎵爜
 const openScan = () => {
   scanRef.value?.triggerScan();
@@ -152,57 +167,140 @@
       return;
     }
 
-    // 瑙f瀽鎵爜鏁版嵁锛岀幇鍦ㄤ簩缁寸爜鍙寘鍚玦d
-    let scanData;
-    try {
-      scanData = JSON.parse(scanCode);
-    } catch (e) {
-      toast.error("浜岀淮鐮佹牸寮忛敊璇�");
-      return;
+    // 鍘绘帀棣栧熬绌烘牸
+    const scanText = String(scanCode).trim();
+
+    // 鍒ゆ柇鏄惁涓� JSON 鏍煎紡锛堢粸绾跨瓑鍘熸湁浜岀淮鐮侊級
+    const isJsonCode = scanText.startsWith("{") || scanText.startsWith("[");
+
+    let tagData: any = null;
+    let outPutId: string | number | undefined;
+    let monofilamentNumber: string | undefined;
+    let needContractCheck = false; // 鏄惁闇�瑕佽繘琛屽悎鍚屽彿鏍¢獙锛堝彧瀵圭粸绾匡級
+
+    if (isJsonCode) {
+      // ===== 缁炵嚎绛夊師鏈変簩缁寸爜閫昏緫锛圝SON锛� =====
+      let scanData;
+      try {
+        scanData = JSON.parse(scanText);
+      } catch {
+        toast.error("浜岀淮鐮佹牸寮忛敊璇�");
+        return;
+      }
+
+      outPutId = scanData.id;
+
+      if (!outPutId) {
+        toast.error("浜岀淮鐮佹牸寮忛敊璇紝缂哄皯id淇℃伅");
+        return;
+      }
+
+      // 妫�鏌ユ槸鍚﹀凡瀛樺湪锛堟牴鎹� id 鍒ゆ柇锛�
+      const exists = goodsList.value.some((item) => {
+        const itemId = item.id;
+        return itemId && itemId === outPutId && itemId !== "-";
+      });
+
+      if (exists) {
+        toast.error("璇ユ潯鐮佸凡瀛樺湪锛岃鍕块噸澶嶆壂鐮�");
+        return;
+      }
+
+      // 璋冪敤鎺ュ彛鑾峰彇缁炵嚎/鎷変笣璇︾粏淇℃伅锛堝惈鍑哄簱鐘舵�侊級
+      const { data } = await OutboundApi.getTagByIdAll({
+        outPutId: outPutId,
+      });
+
+      const list = data || [];
+      if (!list.length) {
+        toast.error("鏈煡璇㈠埌鏉$爜淇℃伅");
+        return;
+      }
+
+      tagData = list[0];
+      needContractCheck = true; // 鍙湁缁炵嚎闇�瑕佸仛鍚堝悓鍙锋牎楠�
+    } else {
+      // ===== 鍗曚笣鎷変笣浜岀淮鐮侀�昏緫锛堢函瀛楃涓诧級 =====
+      // 绀轰緥锛歓D7z30202616101201#[@]01,桅5.6,-,750826011001001,600.6
+      // 闇�瑕佹彁鍙栦互 75 寮�澶寸殑鍗曚笣鍙�
+      const parts = scanText.split(/[,\s]/).filter((p) => !!p);
+      monofilamentNumber = parts.find((p) => p.startsWith("75"));
+
+      if (!monofilamentNumber) {
+        toast.error("浜岀淮鐮佹牸寮忛敊璇紝鏈壘鍒板崟涓濆彿");
+        return;
+      }
+
+      // 妫�鏌ユ槸鍚﹀凡瀛樺湪锛堟牴鎹崟涓濆彿鍒ゆ柇锛�
+      const exists = goodsList.value.some((item) => {
+        const itemMono = item.monofilamentNumber;
+        return itemMono && itemMono === monofilamentNumber && itemMono !== "-";
+      });
+
+      if (exists) {
+        toast.error("璇ユ潯鐮佸凡瀛樺湪锛岃鍕块噸澶嶆壂鐮�");
+        return;
+      }
+
+      // 璋冪敤鎷変笣鎺ュ彛锛欸ET /mes/app/getTagByLsMonofilamentNumber?monofilamentNumber=xxxx
+      let data;
+      try {
+        const response = await OutboundApi.getTagByLsMonofilamentNumber({
+          monofilamentNumber,
+        });
+        data = response.data;
+      } catch {
+        data = null;
+      }
+
+      const list = Array.isArray(data) ? data : data ? [data] : [];
+      if (!list.length) {
+        const formattedMonofilamentNumber = handleMonofilamentNumber(monofilamentNumber);
+        if (!formattedMonofilamentNumber) {
+          return;
+        }
+        const newItem = {
+          id: monofilamentNumber || "-",
+          contractNo: "鏈湪mes涓敓浜�",
+          monofilamentNumber: formattedMonofilamentNumber,
+          model: "-",
+          weight: "-",
+          clienteleName: "-",
+          actuallyLength: "-",
+          productionDate: "-",
+          type: "",
+          devicemodel: "",
+          state: "",
+          projectId: "",
+          productuser: "",
+          rawData: null,
+          scanCode: scanText,
+          scanTime: formatTime(new Date()),
+          isMesMissing: true,
+        };
+        goodsList.value.push(newItem);
+        toast.success("鎵爜鎴愬姛");
+        return;
+      }
+
+      tagData = list[0];
+      outPutId = tagData?.id || monofilamentNumber;
+      // 鎷変笣涓嶅仛鍚堝悓鍙锋牎楠�
     }
 
-    const outPutId = scanData.id;
-
-    if (!outPutId) {
-      toast.error("浜岀淮鐮佹牸寮忛敊璇紝缂哄皯id淇℃伅");
-      return;
-    }
-
-    // 妫�鏌ユ槸鍚﹀凡瀛樺湪锛堟牴鎹甶d鍒ゆ柇锛�
-    const exists = goodsList.value.some((item) => {
-      const itemId = item.id;
-      return itemId && itemId === outPutId && itemId !== "-";
-    });
-
-    if (exists) {
-      toast.error("璇ユ潯鐮佸凡瀛樺湪锛岃鍕块噸澶嶆壂鐮�");
-      return;
-    }
-
-    // 璋冪敤鎺ュ彛鑾峰彇缁炵嚎/鎷変笣璇︾粏淇℃伅锛堝惈鍑哄簱鐘舵�侊級
-    const { data } = await OutboundApi.getTagByIdAll({
-      outPutId: outPutId,
-    });
-
-    const list = data || [];
-    if (!list.length) {
-      toast.error("鏈煡璇㈠埌鏉$爜淇℃伅");
-      return;
-    }
-
-    const tagData = list[0];
-
-    // 宸插嚭搴撴牎楠�
+    // 宸插嚭搴撴牎楠岋紙缁炵嚎 / 鎷変笣 閫氱敤锛�
     if (tagData?.state === "宸插嚭搴�") {
       toast.error("璇ユ潯鐮佸凡鍑哄簱锛屾棤娉曢噸澶嶅嚭搴�");
       return;
     }
 
-    // 鍚堝悓鍙锋牎楠岋細妫�鏌ユ壂鐮佺殑鍚堝悓鍙锋槸鍚︾瓑浜庡彂璐у崟鐨剉srccode
-    const scannedContractNo = tagData?.contractno || "";
-    if (scannedContractNo && vsrccode.value && scannedContractNo !== vsrccode.value) {
-      toast.error(`鍚堝悓鍙�"${scannedContractNo}"涓庡綋鍓嶅彂璐у崟涓�"${vsrccode.value}"涓嶅尮閰峘);
-      return;
+    // 鍚堝悓鍙锋牎楠岋細鍙缁炵嚎锛圝SON 鍦烘櫙锛夎繘琛屾牎楠�
+    if (needContractCheck) {
+      const scannedContractNo = tagData?.contractno || "";
+      if (scannedContractNo && vsrccode.value && scannedContractNo !== vsrccode.value) {
+        toast.error(`鍚堝悓鍙�"${scannedContractNo}"涓庡綋鍓嶅彂璐у崟涓�"${vsrccode.value}"涓嶅尮閰峘);
+        return;
+      }
     }
 
     // 鎻愬彇鏁版嵁瀛楁锛堟牴鎹帴鍙h繑鍥炵殑鏁版嵁缁撴瀯锛�
@@ -214,6 +312,7 @@
         tagData?.monofilamentNumber ||
         tagData?.systemno ||
         tagData?.systemNo ||
+        monofilamentNumber ||
         "-",
       model: tagData?.model || "-",
       weight: tagData?.actuallylength || tagData?.actuallyLength || tagData?.weight || "-",
@@ -227,7 +326,7 @@
       productuser: tagData?.productuser || "",
       // 淇濈暀鍘熷鏁版嵁
       rawData: tagData,
-      scanCode: scanCode,
+      scanCode: scanText,
     };
 
     // 娣诲姞鍒板垪琛�
@@ -316,6 +415,7 @@
         const requestData = goodsList.value.map((item) => ({
           outPutId: item.id,
           projectId: item.projectId || "",
+          monofilamentNumber: item.monofilamentNumber || "",
         }));
 
         // 鎸夊嚭搴撳崟鏄庣粏鏋勫缓璇锋眰浣�
@@ -324,6 +424,7 @@
           cdeliveryid: currentMaterial.value?.cdeliveryid || "",
           cdeliverybid: currentMaterial.value?.cdeliverybid || "",
           materialcode: currentMaterial.value?.materialcode || "",
+          vfree4: currentMaterial.value?.vfree4 || "",
         };
 
         try {
@@ -364,15 +465,27 @@
   uni.$on("scanMaterial", getScanCode);
 };
 
+// 瀹夊叏瑙g爜锛堝吋瀹瑰凡瑙g爜鎴栨湭缂栫爜鐨勬儏鍐碉級
+const safeDecode = (val: any) => {
+  if (typeof val !== "string") return val || "";
+  try {
+    // 濡傛灉鏄紪鐮佽繃鐨勶紙鍖呭惈 %锛夛紝decode 涓�娆★紱鍚﹀垯鐩存帴杩斿洖
+    return val.includes("%") ? decodeURIComponent(val) : val;
+  } catch {
+    return val;
+  }
+};
+
 onLoad((options: any) => {
   // 浠庤矾鐢卞弬鏁颁腑鑾峰彇鐗╂枡鍩烘湰淇℃伅銆佸嚭搴撳崟淇℃伅鍜� vsrccode
   currentMaterial.value = {
-    materialname: options.materialname || "-",
-    materialspec: options.materialspec || "-",
+    materialname: safeDecode(options.materialname || "-"),
+    materialspec: safeDecode(options.materialspec || "-"),
     shippedQuantity: Number(options.shippedQuantity || 0),
-    cdeliveryid: options.cdeliveryid || "",
-    cdeliverybid: options.cdeliverybid || "",
-    materialcode: options.materialcode || "",
+    cdeliveryid: safeDecode(options.cdeliveryid || ""),
+    cdeliverybid: safeDecode(options.cdeliverybid || ""),
+    materialcode: safeDecode(options.materialcode || ""),
+    vfree4: safeDecode(options.vfree4 || ""),
   };
   vsrccode.value = options.vsrccode || "";
 });

--
Gitblit v1.9.3