| | |
| | | // 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("请先选择一个层"); |
| | | 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("该单丝已领用,请勿重复扫码"); |
| | | // 找到当前选中的层 |
| | | 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 { data } = await TwistApi.getScarn({ |
| | | outPutId: scannedOutputId, |
| | | 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("二维码异常,请更换二维码!"); |
| | | } |
| | | }; |
| | | |