From bfbea958be8afe7e0522dc19f8a468eb35a3f9b9 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 13 十一月 2025 10:29:09 +0800
Subject: [PATCH] fix: 钢芯领用添加芯线类型字段,添加扫码领用功能

---
 src/pages/production/twist/receive/monofil.vue |  109 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 62 insertions(+), 47 deletions(-)

diff --git a/src/pages/production/twist/receive/monofil.vue b/src/pages/production/twist/receive/monofil.vue
index 7f66e3d..9456e8e 100644
--- a/src/pages/production/twist/receive/monofil.vue
+++ b/src/pages/production/twist/receive/monofil.vue
@@ -79,7 +79,7 @@
 import MonofilCard from "../components/MonofilCard.vue";
 import StatisticsModal from "../components/StatisticsModal.vue";
 import { useToast } from "wot-design-uni";
-import { onLoad, onUnload } from "@dcloudio/uni-app";
+import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
 import Scan from "@/components/scan/index.vue";
 import ManageApi from "@/api/product/manage";
 import TwistApi from "@/api/product/twist";
@@ -95,62 +95,66 @@
 const showStatisticsModal = ref(false);
 const showManualInput = ref(false);
 const manualOutPutId = ref("");
+const isPageVisible = ref(false); // 鏍囪椤甸潰鏄惁鍙
 
 // 鐩戝惉鏍囩鍒囨崲
 watch(tab, () => {
   if (tab.value) {
-    console.log("tab.value:===========1", tab.value);
     getList();
   }
 });
 
 const getScanCode = async (code: any) => {
-  console.log("鑷畾涔夋壂鎻忕殑缁撴灉鍥炶皟鍑芥暟:", code);
-  // let parseData = code.trim();
-  console.log("code:===========", JSON.parse(code.code));
-  console.log("id:=============", JSON.parse(code.code).id);
-  const { data } = await TwistApi.getScarn({
-    outPutId: JSON.parse(code.code).id,
-  });
-
-  // 妫�鏌ユ槸鍚﹀凡閫夋嫨鏍囩
-  if (!tab.value) {
-    toast.error("璇峰厛閫夋嫨涓�涓眰");
+  // 妫�鏌ラ〉闈㈡槸鍚﹀彲瑙侊紝濡傛灉涓嶅彲瑙佸垯涓嶅鐞嗘壂鐮佹暟鎹�
+  if (!isPageVisible.value) {
     return;
   }
 
-  // 鎵惧埌褰撳墠閫変腑鐨勫眰
-  console.log("tab.value:===========2", tab.value);
-  const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
-  if (!currentLayer) {
-    toast.error("鏈壘鍒板綋鍓嶉�変腑鐨勫眰");
-    return;
-  }
-
-  // 妫�鏌ュ綋鍓嶅眰鏄惁宸插瓨鍦ㄨ鍗曚笣
-  const exists = currentLayer.strandedWireDish?.some(
-    (item: any) => item.monofilamentNumber === data.monofilamentNumber
-  );
-  if (!exists) {
-    const { id, outPutId, wireId, oneLength, ...rest } = data;
-    const newItem = {
-      wireId: paramsId.value,
-      outputId: id,
-      amount: oneLength,
-      ongLength: oneLength,
-      ...rest,
-    };
-
-    // 娣诲姞鍒板綋鍓嶅眰鐨� strandedWireDish 涓�
-    if (!currentLayer.strandedWireDish) {
-      currentLayer.strandedWireDish = [];
+  try {
+    // 妫�鏌ユ槸鍚﹀凡閫夋嫨鏍囩
+    if (!tab.value) {
+      toast.error("璇峰厛閫夋嫨涓�涓眰");
+      return;
     }
-    currentLayer.strandedWireDish.push(newItem);
 
-    // 鍒锋柊褰撳墠灞傜殑鏁版嵁鏄剧ず
-    getList();
-  } else {
-    toast.error("璇ュ崟涓濆凡棰嗙敤锛岃鍕块噸澶嶆壂鐮�");
+    // 鎵惧埌褰撳墠閫変腑鐨勫眰
+    const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
+    if (!currentLayer) {
+      toast.error("鏈壘鍒板綋鍓嶉�変腑鐨勫眰");
+      return;
+    }
+    const { data } = await TwistApi.getScarn({
+      outPutId: JSON.parse(code.code).id,
+      twistId: currentLayer.twistId,
+    });
+
+    // 妫�鏌ュ綋鍓嶅眰鏄惁宸插瓨鍦ㄨ鍗曚笣
+    const exists = currentLayer.strandedWireDish?.some(
+      (item: any) => item.monofilamentNumber === data.monofilamentNumber
+    );
+    if (!exists) {
+      const { id, outPutId, wireId, oneLength, ...rest } = data;
+      const newItem = {
+        wireId: paramsId.value,
+        outputId: id,
+        amount: oneLength,
+        ongLength: oneLength,
+        ...rest,
+      };
+
+      // 娣诲姞鍒板綋鍓嶅眰鐨� strandedWireDish 涓�
+      if (!currentLayer.strandedWireDish) {
+        currentLayer.strandedWireDish = [];
+      }
+      currentLayer.strandedWireDish.push(newItem);
+
+      // 鍒锋柊褰撳墠灞傜殑鏁版嵁鏄剧ず
+      getList();
+    } else {
+      toast.error("璇ュ崟涓濆凡棰嗙敤锛岃鍕块噸澶嶆壂鐮�");
+    }
+  } catch (error) {
+    toast.error("浜岀淮鐮佸紓甯革紝璇锋洿鎹簩缁寸爜锛�");
   }
 };
 
@@ -254,7 +258,6 @@
     // 璁剧疆榛樿绗竴灞�
     if (nodeList.value && nodeList.value.length > 0 && !tab.value) {
       tab.value = nodeList.value[0].twistedLayer;
-      console.log("璁剧疆榛樿绗竴灞�:", tab.value);
       // 璁剧疆榛樿鏍囩鍚庯紝鍔犺浇绗竴灞傜殑鏁版嵁
       getList();
     }
@@ -339,15 +342,27 @@
   getRootNumber(options.id);
   // getRootNumber(118);
 });
+
+onShow(() => {
+  // 椤甸潰鏄剧ず鏃舵爣璁颁负鍙
+  isPageVisible.value = true;
+});
+
+onHide(() => {
+  // 椤甸潰闅愯棌鏃舵爣璁颁负涓嶅彲瑙�
+  isPageVisible.value = false;
+});
+
 onUnload(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
+  // 鍙栨秷骞挎挱鐩戝惉浜嬩欢
   uni.$off("scanMono", getScanCode);
+  isPageVisible.value = false;
 });
 </script>
 
 <style lang="scss" scoped>
 .list_box {
-  height: calc(100vh - 100px);
+  height: calc(100vh - 50px);
   background: #f3f9f8;
   display: flex;
   flex-direction: column;
@@ -410,7 +425,7 @@
 }
 
 .content {
-  height: calc(100vh - 280px);
+  height: calc(100vh - 200px);
   width: 100%;
 }
 

--
Gitblit v1.9.3