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 | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 105 insertions(+), 14 deletions(-)
diff --git a/src/pages/production/twist/receive/monofil.vue b/src/pages/production/twist/receive/monofil.vue
index 1c7a03e..23ffec7 100644
--- a/src/pages/production/twist/receive/monofil.vue
+++ b/src/pages/production/twist/receive/monofil.vue
@@ -25,7 +25,12 @@
<block v-for="item in nodeList" :key="item">
<wd-tab :title="item.twistedLayer" :name="item.twistedLayer">
<scroll-view class="content" scroll-y>
- <MonofilCard v-for="(m, i) in item.strandedWireDish" :key="i" :data="m" />
+ <MonofilCard
+ v-for="(m, i) in item.strandedWireDish"
+ :key="i"
+ :data="m"
+ @delete="handleDeleteCard(item, m)"
+ />
</scroll-view>
</wd-tab>
</block>
@@ -79,7 +84,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,25 +100,22 @@
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);
- try {
- const { data } = await TwistApi.getScarn({
- outPutId: JSON.parse(code.code).id,
- });
+ // 妫�鏌ラ〉闈㈡槸鍚﹀彲瑙侊紝濡傛灉涓嶅彲瑙佸垯涓嶅鐞嗘壂鐮佹暟鎹�
+ if (!isPageVisible.value) {
+ return;
+ }
+ try {
// 妫�鏌ユ槸鍚﹀凡閫夋嫨鏍囩
if (!tab.value) {
toast.error("璇峰厛閫夋嫨涓�涓眰");
@@ -121,10 +123,49 @@
}
// 鎵惧埌褰撳墠閫変腑鐨勫眰
- console.log("tab.value:===========2", tab.value);
const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
if (!currentLayer) {
toast.error("鏈壘鍒板綋鍓嶉�変腑鐨勫眰");
+ return;
+ }
+
+ // 瑙f瀽鎵爜鏁版嵁锛氬彲鑳藉寘鍚� id(outPutId) 鎴� monofilamentNumber
+ let scanCode = code.code || code;
+ const scanData = JSON.parse(scanCode);
+ const outPutId = scanData.id;
+ const monofilamentNumber = scanData.monofilamentNumber;
+
+ 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;
}
@@ -155,6 +196,7 @@
}
} catch (error) {
toast.error("浜岀淮鐮佸紓甯革紝璇锋洿鎹簩缁寸爜锛�");
+ console.log(error);
}
};
@@ -258,7 +300,6 @@
// 璁剧疆榛樿绗竴灞�
if (nodeList.value && nodeList.value.length > 0 && !tab.value) {
tab.value = nodeList.value[0].twistedLayer;
- console.log("璁剧疆榛樿绗竴灞�:", tab.value);
// 璁剧疆榛樿鏍囩鍚庯紝鍔犺浇绗竴灞傜殑鏁版嵁
getList();
}
@@ -334,6 +375,44 @@
}
};
+// 鍒犻櫎鍗$墖
+const handleDeleteCard = async (layer: any, cardData: any) => {
+ // 鏄剧ず纭鎻愮ず
+ uni.showModal({
+ title: "鎻愮ず",
+ content: "纭畾瑕佸垹闄よ鍗曚笣鍚楋紵",
+ success: async (res) => {
+ if (res.confirm) {
+ try {
+ // 濡傛灉鏈塱d锛岃皟鐢ㄦ帴鍙e垹闄�
+ if (cardData.id !== undefined && cardData.id !== null) {
+ const { code, msg } = await TwistApi.deleteStrandedWireDish(cardData.id);
+ if (code !== 200) {
+ toast.error(msg || "鍒犻櫎澶辫触");
+ return;
+ }
+ }
+
+ // 鍓嶇鐩存帴鍒犻櫎锛堟棤璁烘槸鍚︽湁id锛岄兘浠庡墠绔垹闄わ級
+ if (layer.strandedWireDish && Array.isArray(layer.strandedWireDish)) {
+ const index = layer.strandedWireDish.findIndex(
+ (item: any) => item.monofilamentNumber === cardData.monofilamentNumber
+ );
+ if (index !== -1) {
+ layer.strandedWireDish.splice(index, 1);
+ toast.success("鍒犻櫎鎴愬姛");
+ // 鍒锋柊褰撳墠灞傜殑鏁版嵁鏄剧ず
+ getList();
+ }
+ }
+ } catch (error: any) {
+ toast.error(error.msg || "鍒犻櫎澶辫触");
+ }
+ }
+ },
+ });
+};
+
onLoad(async (options: any) => {
// 寮�鍚箍鎾洃鍚簨浠�
uni.$on("scanMono", getScanCode);
@@ -343,9 +422,21 @@
getRootNumber(options.id);
// getRootNumber(118);
});
+
+onShow(() => {
+ // 椤甸潰鏄剧ず鏃舵爣璁颁负鍙
+ isPageVisible.value = true;
+});
+
+onHide(() => {
+ // 椤甸潰闅愯棌鏃舵爣璁颁负涓嶅彲瑙�
+ isPageVisible.value = false;
+});
+
onUnload(() => {
- // 寮�鍚箍鎾洃鍚簨浠�
+ // 鍙栨秷骞挎挱鐩戝惉浜嬩欢
uni.$off("scanMono", getScanCode);
+ isPageVisible.value = false;
});
</script>
--
Gitblit v1.9.3