spring
2025-11-13 0d6e0f0efa92c9347884c83170ec8d47dd5f5ef4
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,78 @@
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 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: scanData.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 +270,6 @@
    // 设置默认第一层
    if (nodeList.value && nodeList.value.length > 0 && !tab.value) {
      tab.value = nodeList.value[0].twistedLayer;
      console.log("设置默认第一层:", tab.value);
      // 设置默认标签后,加载第一层的数据
      getList();
    }
@@ -339,15 +354,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 +437,7 @@
}
.content {
  height: calc(100vh - 280px);
  height: calc(100vh - 200px);
  width: 100%;
}