From 3315f8bc2dd9b0f2aa40e6bea962344cc0b80bed Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 29 九月 2025 11:23:18 +0800
Subject: [PATCH] 领料修改

---
 src/pages/production/twist/receive/monofil.vue |  267 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 235 insertions(+), 32 deletions(-)

diff --git a/src/pages/production/twist/receive/monofil.vue b/src/pages/production/twist/receive/monofil.vue
index 80d234f..87cc830 100644
--- a/src/pages/production/twist/receive/monofil.vue
+++ b/src/pages/production/twist/receive/monofil.vue
@@ -1,61 +1,264 @@
 <template>
-  <view class="page">
-    <CardTitle title="鍗曚笣棰嗙敤" :hideAction="false">
-      <template #action>
-        <wd-button type="icon" icon="scan" color="#0D867F" @click="scanCode"></wd-button>
+  <view class="list_box">
+    <z-paging
+      ref="pagingRef"
+      :fixed="false"
+      :auto-show-back-to-top="true"
+      :loading-more-enabled="false"
+      @query="getList"
+    >
+      <template #top>
+        <CardTitle title="鍗曚笣棰嗙敤" :hideAction="false">
+          <template #action>
+            <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
+          </template>
+        </CardTitle>
       </template>
-    </CardTitle>
-    <view class="list_box">
-      <MonofilCard v-for="(item, index) in 4" :key="index" />
-    </view>
-    <scan />
+      <!-- <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">
+            <text class="text-[#fff]">淇濆瓨</text>
+          </wd-button>
+        </view>
+      </template>
+    </z-paging>
+    <Scan ref="scanRef" emitName="scanMono" />
+    <StatisticsModal
+      v-model:visible="showStatisticsModal"
+      :nodeList="nodeList"
+      @confirm="handleConfirmSave"
+    />
+    <wd-toast />
   </view>
 </template>
 
 <script setup lang="ts">
 import CardTitle from "@/components/card-title/index.vue";
 import MonofilCard from "../components/MonofilCard.vue";
-import scan from "@/components/scan/index.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";
+import ManageApi from "@/api/product/manage";
+import TwistApi from "@/api/product/twist";
+import zPaging from "@/components/z-paging/z-paging.vue";
+// import { useZebraScan } from "@/hooks/useZebraScan";
+// const { init, start, stop, triggerScan } = useZebraScan();
 
-const cardList = ref<any[]>([]);
+const paramsId = ref();
+const pagingRef = ref();
+const scanRef = ref();
+const toast = useToast();
+const tab = ref("");
+const showStatisticsModal = ref(false);
 
-const BroadcastScanningToObtainData = (res: any) => {
-  console.log("鑾峰彇娆℃暟", res.code);
-  let barcode = res.code;
-  console.log("鎵撳嵃鏁版嵁", barcode);
-};
+// 鐩戝惉鏍囩鍒囨崲
+watch(tab, () => {
+  if (tab.value) {
+    console.log("tab.value:===========1", tab.value);
+    getList();
+  }
+});
 
-const scanCode = () => {
-  uni.scanCode({
-    onlyFromCamera: true,
-    success: (res) => {
-      console.log("鏉$爜绫诲瀷锛�" + res.scanType);
-      console.log("鏉$爜鍐呭锛�" + res.result);
-      cardList.value.push(res.result);
-    },
+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("璇峰厛閫夋嫨涓�涓眰");
+    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 = [];
+    }
+    currentLayer.strandedWireDish.push(newItem);
+
+    // 鍒锋柊褰撳墠灞傜殑鏁版嵁鏄剧ず
+    getList();
+  } else {
+    toast.error("璇ュ崟涓濆凡棰嗙敤锛岃鍕块噸澶嶆壂鐮�");
+  }
 };
 
-onLoad(() => {
+const openScan = () => {
+  scanRef.value.triggerScan();
+};
+
+const getList = async () => {
+  // 浠庡綋鍓嶉�変腑灞傜殑 strandedWireDish 涓幏鍙栨暟鎹�
+  const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
+  if (currentLayer && currentLayer.strandedWireDish) {
+    pagingRef.value.complete(currentLayer.strandedWireDish);
+  } else {
+    pagingRef.value.complete([]);
+  }
+};
+
+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(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(async (options: any) => {
   // 寮�鍚箍鎾洃鍚簨浠�
-  uni.$on("scan", BroadcastScanningToObtainData);
+  uni.$on("scanMono", getScanCode);
+  paramsId.value = options.id;
+
+  // 璋冪敤鑾峰彇鏍瑰彿鎺ュ彛
+  getRootNumber(options.id);
+  // getRootNumber(118);
 });
 onUnload(() => {
   // 寮�鍚箍鎾洃鍚簨浠�
-  uni.$off("scan", BroadcastScanningToObtainData);
+  uni.$off("scanMono", getScanCode);
 });
 </script>
 
 <style lang="scss" scoped>
-.page {
+.list_box {
+  height: calc(100vh - 100px);
   background: #f3f9f8;
-  .list_box {
-    height: calc(100% - 100px);
-    overflow: scroll;
-  }
 }
 :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>

--
Gitblit v1.9.3