From 2de633725d5e5d843853240933f63220dc4e4cb2 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 03 十二月 2025 16:53:57 +0800
Subject: [PATCH] fix: 导体会存在每隔一段距离需要标记的情况,需要通知工人进行标记。

---
 src/pages/production/wire/report/wire.vue |  163 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 149 insertions(+), 14 deletions(-)

diff --git a/src/pages/production/wire/report/wire.vue b/src/pages/production/wire/report/wire.vue
index e391316..15e8fd9 100644
--- a/src/pages/production/wire/report/wire.vue
+++ b/src/pages/production/wire/report/wire.vue
@@ -116,10 +116,17 @@
         </view>
 
         <template #footer>
-          <view class="flex justify-start">
-            <wd-button plain size="small" type="primary" @click="openChildDialog(item)">
+          <view class="flex justify-start gap-2">
+            <wd-button
+              plain
+              size="small"
+              type="primary"
+              @click="openChildDialog(item)"
+              style="margin-right: 10px"
+            >
               鎶ュ伐绠$悊
             </wd-button>
+            <wd-button plain size="small" @click="() => toSelfInspect(item)">鑷</wd-button>
           </view>
         </template>
       </wd-card>
@@ -130,7 +137,10 @@
       <view class="parent-dialog">
         <view class="dialog-header">
           <text class="dialog-title">鏂板鏉嗗寘</text>
-          <wd-icon name="close" class="close-icon" @click="closeParentDialog"></wd-icon>
+          <view class="dialog-header-actions">
+            <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
+            <wd-icon name="close" class="close-icon" @click="closeParentDialog"></wd-icon>
+          </view>
         </view>
         <view class="dialog-content">
           <wd-cell-group>
@@ -151,13 +161,14 @@
               label="鏉嗗寘鍙�"
               label-width="100px"
               placeholder="璇疯緭鍏ユ潌鍖呭彿"
+              type="number"
             />
             <wd-input
               v-model="newParentData.poleWeight"
               label="鏉嗛噸(kg)"
               label-width="100px"
-              type="number"
               placeholder="璇疯緭鍏ユ潌閲�"
+              type="number"
             />
             <wd-picker
               v-model="newParentData.supplier"
@@ -169,7 +180,7 @@
           </wd-cell-group>
         </view>
         <view class="dialog-footer">
-          <wd-button plain @click="closeParentDialog">鍙栨秷</wd-button>
+          <wd-button plain @click="closeParentDialog" style="margin-right: 10px">鍙栨秷</wd-button>
           <wd-button type="primary" class="ml-2" @click="handleSaveNewParent">淇濆瓨</wd-button>
         </view>
       </view>
@@ -183,6 +194,9 @@
         @close="handleDrawClose"
       />
     </wd-popup>
+
+    <!-- 鎵爜缁勪欢 -->
+    <Scan ref="scanRef" emitName="scanRodBag" />
 
     <wd-toast />
   </view>
@@ -199,6 +213,7 @@
 import { getTeamId } from "@/utils/cache";
 import { useUserStore } from "@/store/modules/user";
 import WireDetailApi from "@/api/product/wire";
+import Scan from "@/components/scan/index.vue";
 
 const toast = useToast();
 const userStore = useUserStore();
@@ -233,6 +248,9 @@
   wireId: "",
   poleNumber: "",
 });
+
+// 鎵爜缁勪欢鐩稿叧
+const scanRef = ref();
 
 // 鑾峰彇璇︽儏鏁版嵁
 const getDetailData = async (id: string) => {
@@ -317,15 +335,13 @@
 
 // 鏂板鐖剁骇鏁版嵁 - 鎵撳紑寮规
 const handleAddParent = () => {
-  const lastParent = parentDataList.value[0];
-
-  // 鍒濆鍖栨柊鏁版嵁锛屽鏋滄湁鏈�鍚庝竴鏉℃暟鎹紝浣跨敤鍏跺�间綔涓洪粯璁ゅ��
+  // 娓呯┖鎵�鏈夋暟鎹�
   newParentData.value = {
-    poleNumber: lastParent?.poleNumber || "",
-    poleModel: lastParent?.poleModel || "",
-    polePackageNumber: lastParent?.polePackageNumber || "",
-    poleWeight: lastParent?.poleWeight || null,
-    supplier: lastParent?.supplier || "",
+    poleNumber: "",
+    poleModel: "",
+    polePackageNumber: "",
+    poleWeight: undefined,
+    supplier: "",
     isConsumed: 1,
   };
 
@@ -490,18 +506,107 @@
   drawFormRef.visible = false;
 };
 
+// 璺宠浆鍒拌嚜妫�椤甸潰
+const toSelfInspect = (row: any) => {
+  uni.navigateTo({
+    url: `/pages/production/wire/selfInspect/index?wireId=${paramsId.value}&poleModel=${row.poleModel || ""}&poleNumber=${row.poleNumber || ""}`,
+  });
+};
+
+// 鎵撳紑鎵爜
+const openScan = () => {
+  if (scanRef.value) {
+    scanRef.value.triggerScan();
+  } else {
+    toast.error("鎵爜缁勪欢鏈垵濮嬪寲");
+  }
+};
+
+// 澶勭悊鎵爜缁撴灉
+const getScanCode = (code: any) => {
+  try {
+    console.log("鎵爜缁撴灉:", code.code);
+
+    let scanData: any = {};
+
+    // 灏濊瘯瑙f瀽 JSON 鏍煎紡
+    try {
+      scanData = JSON.parse(code.code);
+    } catch (e) {
+      // 濡傛灉涓嶆槸 JSON锛屽皾璇曟寜閫楀彿鍒嗗壊
+      const arr = code.code.split(",");
+      if (arr.length >= 5) {
+        // 鏍规嵁 wireForm.vue 鐨勬牸寮忥細arr[2] 鏄潌鍨嬪彿锛宎rr[3] 鏄鐢ㄦ潌鍙凤紝arr[4] 鏄潌閲�
+        scanData = {
+          poleModel: arr[2],
+          poleNumber: arr[3],
+          poleWeight: arr[4],
+        };
+      } else {
+        // 濡傛灉鏍煎紡涓嶅尮閰嶏紝灏濊瘯鍏朵粬瑙f瀽鏂瑰紡
+        // 鍙兘鏄悎鏍艰瘉浜岀淮鐮侊紝鍖呭惈鐐夋鍙枫�佺墝鍙枫�佽鏍笺�佸噣閲嶇瓑淇℃伅
+        // 鏍规嵁鍚堟牸璇佷俊鎭紝灏濊瘯鎻愬彇鍏抽敭瀛楁
+        const codeStr = code.code;
+
+        // 灏濊瘯鎻愬彇鐐夋鍙凤紙鏍煎紡锛氭暟瀛�-鏁板瓧-鏁板瓧锛�
+        const batchMatch = codeStr.match(/(\d{6,}-\d{3,}-\d{3,})/);
+        if (batchMatch) {
+          scanData.poleNumber = batchMatch[1]; // 鐐夋鍙蜂綔涓洪鐢ㄦ潌鍙�
+        }
+
+        // 灏濊瘯鎻愬彇鐗屽彿锛圓6绛夛級
+        const brandMatch = codeStr.match(/鐗屽彿[锛�:]\s*([A-Z]\d+)/i) || codeStr.match(/([A-Z]\d+)/);
+        if (brandMatch) {
+          scanData.poleModel = brandMatch[1]; // 鐗屽彿浣滀负鏉嗗瀷鍙�
+        }
+
+        // 灏濊瘯鎻愬彇鍑�閲嶏紙鏁板瓧+KG锛�
+        const weightMatch =
+          codeStr.match(/鍑�閲峓锛�:]\s*(\d+(?:\.\d+)?)\s*KG/i) ||
+          codeStr.match(/(\d+(?:\.\d+)?)\s*KG/i);
+        if (weightMatch) {
+          scanData.poleWeight = parseFloat(weightMatch[1]);
+        }
+      }
+    }
+
+    // 鍙~鍏呬笁涓瓧娈碉細棰嗙敤鏉嗗彿銆佹潌鍨嬪彿銆佹潌閲�(kg)
+    if (scanData.poleNumber) {
+      newParentData.value.poleNumber = scanData.poleNumber;
+    }
+    if (scanData.poleModel) {
+      newParentData.value.poleModel = scanData.poleModel;
+    }
+    if (scanData.poleWeight) {
+      newParentData.value.poleWeight = parseFloat(scanData.poleWeight);
+    }
+
+    toast.success("鎵爜鎴愬姛锛屽凡濉厖淇℃伅");
+  } catch (error) {
+    console.error("瑙f瀽鎵爜鏁版嵁澶辫触:", error);
+    toast.error("浜岀淮鐮佹牸寮忛敊璇紝璇锋鏌ヤ簩缁寸爜");
+  }
+};
+
 onLoad(async (options: any) => {
   paramsId.value = options.id;
   await getDetailData(options.id);
   await loadSupplierDict();
   await getData();
+  // 寮�鍚壂鐮佺洃鍚簨浠�
+  uni.$on("scanRodBag", getScanCode);
+});
+
+onUnload(() => {
+  // 鍙栨秷鎵爜鐩戝惉浜嬩欢
+  uni.$off("scanRodBag", getScanCode);
 });
 </script>
 
 <style lang="scss" scoped>
 .list {
   min-height: calc(100vh - 30px);
-  padding: 12px;
+  padding: 12px 4px;
   background: #f3f9f8;
 
   :deep() {
@@ -543,6 +648,36 @@
   border-radius: 12px 12px 0 0;
 }
 
+.dialog-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: 16px;
+  border-bottom: 1px solid #e6e6e6;
+  position: sticky;
+  top: 0;
+  background: #fff;
+  z-index: 10;
+}
+
+.dialog-header-actions {
+  display: flex;
+  align-items: center;
+  gap: 8px;
+}
+
+.dialog-title {
+  font-size: 16px;
+  color: #333;
+  font-weight: 500;
+}
+
+.close-icon {
+  font-size: 20px;
+  color: #999;
+  padding: 4px;
+}
+
 .dialog-content {
   flex: 1;
   overflow-y: auto;

--
Gitblit v1.9.3