spring
2025-09-29 3315f8bc2dd9b0f2aa40e6bea962344cc0b80bed
src/pages/production/twist/receive/monofil.vue
@@ -2,9 +2,9 @@
  <view class="list_box">
    <z-paging
      ref="pagingRef"
      v-model="cardList"
      :fixed="false"
      :auto-show-back-to-top="true"
      :loading-more-enabled="false"
      @query="getList"
    >
      <template #top>
@@ -14,7 +14,16 @@
          </template>
        </CardTitle>
      </template>
      <MonofilCard v-for="(item, index) in cardList" :key="index" :data="item" />
      <!-- <MonofilCard v-for="(item, index) in cardList" :key="index" :data="item" /> -->
      <wd-tabs v-model="tab" slidable="always">
        <block v-for="item in nodeList" :key="item">
          <wd-tab :title="item.twistedLayer" :name="item.twistedLayer">
            <view class="content">
              <MonofilCard v-for="(m, i) in item.strandedWireDish" :key="i" :data="m" />
            </view>
          </wd-tab>
        </block>
      </wd-tabs>
      <template #bottom>
        <view class="flex justify-center items-center">
          <wd-button block @click="save">
@@ -24,6 +33,11 @@
      </template>
    </z-paging>
    <Scan ref="scanRef" emitName="scanMono" />
    <StatisticsModal
      v-model:visible="showStatisticsModal"
      :nodeList="nodeList"
      @confirm="handleConfirmSave"
    />
    <wd-toast />
  </view>
</template>
@@ -31,6 +45,7 @@
<script setup lang="ts">
import CardTitle from "@/components/card-title/index.vue";
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 Scan from "@/components/scan/index.vue";
@@ -43,8 +58,17 @@
const paramsId = ref();
const pagingRef = ref();
const scanRef = ref();
const cardList = ref<any[]>([]);
const toast = useToast();
const tab = ref("");
const showStatisticsModal = ref(false);
// 监听标签切换
watch(tab, () => {
  if (tab.value) {
    console.log("tab.value:===========1", tab.value);
    getList();
  }
});
const getScanCode = async (code: any) => {
  console.log("自定义扫描的结果回调函数:", code);
@@ -54,24 +78,43 @@
  const { data } = await TwistApi.getScarn({
    outPutId: JSON.parse(code.code).id,
  });
  const exists = cardList.value.some((item) => item.monofilamentNumber === data.monofilamentNumber);
  // 检查是否已选择标签
  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;
    console.log("sb", {
    const newItem = {
      wireId: paramsId.value,
      outputId: id,
      amount: oneLength,
      ongLength: oneLength,
      ...rest,
    });
    cardList.value.push({
      wireId: paramsId.value,
      outputId: id,
      amount: oneLength,
      ongLength: oneLength,
      ...rest,
    });
    pagingRef.value.complete(cardList.value);
    };
    // 添加到当前层的 strandedWireDish 中
    if (!currentLayer.strandedWireDish) {
      currentLayer.strandedWireDish = [];
    }
    currentLayer.strandedWireDish.push(newItem);
    // 刷新当前层的数据显示
    getList();
  } else {
    toast.error("该单丝已领用,请勿重复扫码");
  }
@@ -82,30 +125,115 @@
};
const getList = async () => {
  const { code, data } = await ManageApi.getStrandedWireDish({
    wireId: paramsId.value,
    type: "单丝",
  });
  if (code == 200) {
    pagingRef.value.complete(data);
  // 从当前选中层的 strandedWireDish 中获取数据
  const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
  if (currentLayer && currentLayer.strandedWireDish) {
    pagingRef.value.complete(currentLayer.strandedWireDish);
  } else {
    pagingRef.value.complete([]);
  }
};
const save = async () => {
  const { code } = await TwistApi.addStrandedWireDish(cardList.value);
let nodeList = ref<any[]>([]);
// 获取根号
const getRootNumber = async (wireId: number) => {
  const { code, data, msg } = await TwistApi.getRootNumber({ wireId });
  if (code === 200) {
    nodeList.value = data.nodeList;
    if (data.otherStrandedWireDish && data.otherStrandedWireDish.length > 0) {
      nodeList.value.push({
        strandedWireDish: data.otherStrandedWireDish,
        twistedLayer: "其他",
        twistId: null,
      });
    }
    // 设置默认第一层
    if (nodeList.value && nodeList.value.length > 0 && !tab.value) {
      tab.value = nodeList.value[0].twistedLayer;
      console.log("设置默认第一层:", tab.value);
      // 设置默认标签后,加载第一层的数据
      getList();
    }
  } else {
    toast.error(msg || "获取根号失败");
  }
};
const save = () => {
  // 检查 nodeList 中是否有新的单丝数据需要保存
  let hasNewData = false;
  nodeList.value.forEach((node) => {
    if (node.strandedWireDish && Array.isArray(node.strandedWireDish)) {
      const hasNewInLayer = node.strandedWireDish.some(
        (item: { id?: number }) => item.id === undefined || item.id === null
      );
      if (hasNewInLayer) {
        hasNewData = true;
      }
    }
  });
  if (!hasNewData) {
    toast.error("没有新的单丝数据需要保存");
    return;
  }
  // 显示统计弹框
  showStatisticsModal.value = true;
};
const handleConfirmSave = async () => {
  // 从 nodeList 中收集所有需要保存的新单丝数据
  const newData: any[] = [];
  nodeList.value.forEach((node) => {
    node.strandedWireDish.forEach((item: any) => {
      item.saleTwistId = node.twistId;
    });
    if (node.strandedWireDish && Array.isArray(node.strandedWireDish)) {
      const layerNewData = node.strandedWireDish.filter(
        (item: { id?: number }) => item.id === undefined || item.id === null
      );
      newData.push(...layerNewData);
    }
  });
  if (newData.length === 0) {
    toast.error("没有新的单丝数据需要保存");
    return;
  }
  const { code, msg } = await TwistApi.addStrandedWireDish(newData);
  if (code == 200) {
    toast.success("保存成功");
    cardList.value = [];
    toast.success(msg);
    // 清空所有层中已保存的数据(给已保存的数据添加 id)
    nodeList.value.forEach((node) => {
      if (node.strandedWireDish && Array.isArray(node.strandedWireDish)) {
        node.strandedWireDish.forEach((item: any) => {
          if (item.id === undefined || item.id === null) {
            item.id = Date.now(); // 临时标记为已保存
          }
        });
      }
    });
    pagingRef.value.refresh();
    getList();
  } else {
    toast.error("保存失败");
  }
};
onLoad((options: any) => {
onLoad(async (options: any) => {
  // 开启广播监听事件
  uni.$on("scanMono", getScanCode);
  paramsId.value = options.id;
  // 调用获取根号接口
  getRootNumber(options.id);
  // getRootNumber(118);
});
onUnload(() => {
  // 开启广播监听事件
@@ -121,4 +249,16 @@
:deep(.wd-button__content) {
  color: #0d867f;
}
:deep(.zp-paging-container) {
  background: transparent !important;
}
:deep(.zp-paging-container-content) {
  background: transparent !important;
}
:deep(.wd-tabs) {
  background: transparent !important;
}
:deep(.wd-tabs__nav) {
  margin-bottom: 10px;
}
</style>