| | |
| | | <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> |
| | |
| | | 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"; |
| | |
| | | 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); |
| | | // 检查页面是否可见,如果不可见则不处理扫码数据 |
| | | if (!isPageVisible.value) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 检查是否已选择标签 |
| | | if (!tab.value) { |
| | |
| | | } |
| | | |
| | | // 找到当前选中的层 |
| | | console.log("tab.value:===========2", tab.value); |
| | | const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value); |
| | | if (!currentLayer) { |
| | | toast.error("未找到当前选中的层"); |
| | | return; |
| | | } |
| | | console.log("tab.value:===========3", currentLayer); |
| | | // 在发起请求前,先校验该单丝是否已在当前或其他层级被领用 |
| | | const scannedOutputId = JSON.parse(code.code).id; |
| | | const alreadyUsed = nodeList.value.some((node) => |
| | | (node.strandedWireDish || []).some((item: any) => item.outputId === scannedOutputId) |
| | | ); |
| | | if (alreadyUsed) { |
| | | toast.error("该单丝已领用,请勿重复扫码"); |
| | | return; |
| | | |
| | | // 解析扫码数据 |
| | | const scanData = JSON.parse(code.code); |
| | | |
| | | // 判断层级是否匹配 |
| | | if (scanData.layer && scanData.layer !== currentLayer.twistedLayer) { |
| | | toast.error( |
| | | `领用层级不对,当前层是:${currentLayer.twistedLayer},领用单丝层是:${scanData.layer}` |
| | | ); |
| | | // return; |
| | | } |
| | | |
| | | const { data } = await TwistApi.getScarn({ |
| | | outPutId: scannedOutputId, |
| | | outPutId: scanData.id, |
| | | twistId: currentLayer.twistId, |
| | | }); |
| | | |
| | |
| | | // 设置默认第一层 |
| | | if (nodeList.value && nodeList.value.length > 0 && !tab.value) { |
| | | tab.value = nodeList.value[0].twistedLayer; |
| | | console.log("设置默认第一层:", tab.value); |
| | | // 设置默认标签后,加载第一层的数据 |
| | | getList(); |
| | | } |
| | |
| | | } |
| | | }; |
| | | |
| | | // 删除卡片 |
| | | const handleDeleteCard = async (layer: any, cardData: any) => { |
| | | // 显示确认提示 |
| | | uni.showModal({ |
| | | title: "提示", |
| | | content: "确定要删除该单丝吗?", |
| | | success: async (res) => { |
| | | if (res.confirm) { |
| | | try { |
| | | // 如果有id,调用接口删除 |
| | | 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); |
| | |
| | | getRootNumber(options.id); |
| | | // getRootNumber(118); |
| | | }); |
| | | |
| | | onShow(() => { |
| | | // 页面显示时标记为可见 |
| | | isPageVisible.value = true; |
| | | }); |
| | | |
| | | onHide(() => { |
| | | // 页面隐藏时标记为不可见 |
| | | isPageVisible.value = false; |
| | | }); |
| | | |
| | | onUnload(() => { |
| | | // 开启广播监听事件 |
| | | // 取消广播监听事件 |
| | | uni.$off("scanMono", getScanCode); |
| | | isPageVisible.value = false; |
| | | }); |
| | | </script> |
| | | |