From a8cc9d60a80afd7362e1d0fd31fb4307a6e04e2e Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期五, 31 七月 2026 10:22:14 +0800
Subject: [PATCH] fix: 芯线分层领用

---
 src/pages/production/twist/receive/steelCore/form.vue |  151 +++++++++++++++-----------------------------------
 1 files changed, 46 insertions(+), 105 deletions(-)

diff --git a/src/pages/production/twist/receive/steelCore/form.vue b/src/pages/production/twist/receive/steelCore/form.vue
index d3fb9a4..7d31a3c 100644
--- a/src/pages/production/twist/receive/steelCore/form.vue
+++ b/src/pages/production/twist/receive/steelCore/form.vue
@@ -21,7 +21,7 @@
       />
       <wd-input
         v-model="model.monofilamentNumber"
-        label="鏍峰搧缂栧彿"
+        label="鐩樺彿"
         label-width="100px"
         prop="monofilamentNumber"
         clearable
@@ -33,7 +33,7 @@
         label-width="100px"
         prop="amount"
         clearable
-        placeholder="璇疯緭鍏ラ暱搴�"
+        placeholder="璇疯緭鍏ユ暟閲�"
       />
       <wd-input
         v-model="model.weight"
@@ -60,7 +60,6 @@
 <script lang="ts" setup>
 import { onMounted, watch } from "vue";
 import useFormData from "@/hooks/useFormData";
-import TwistApi from "@/api/product/twist";
 import ManageApi from "@/api/product/manage";
 import { useToast } from "wot-design-uni";
 
@@ -80,14 +79,11 @@
 });
 
 const emits = defineEmits(["refresh"]);
-const paramsId = ref();
-const editId = ref(); // 缂栬緫鏃剁殑ID
-const allListData = ref<any[]>([]); // 瀛樺偍瀹屾暣鍒楄〃鏁版嵁
 const toast = useToast();
 const { form: model } = useFormData({
   diskMaterial: undefined, // 鑺嚎绫诲瀷
   model: undefined, // 瑙勬牸鍨嬪彿
-  monofilamentNumber: undefined, // 鏍峰搧缂栧彿
+  monofilamentNumber: undefined, // 鐩樺彿
   amount: undefined, // 鏁伴噺
   weight: undefined, // 閲嶉噺
   supplier: undefined, // 鍘傚
@@ -150,105 +146,28 @@
   { immediate: true }
 );
 
-// 鏂板鎻愪氦
+// 鏀堕泦琛ㄥ崟鏁版嵁锛堜笉璋� API锛岃繑鍥炵粰鐖剁粍浠跺鐞嗭級
+const collectData = () => {
+  return {
+    diskMaterial: model.diskMaterial,
+    model: model.model,
+    monofilamentNumber: model.monofilamentNumber,
+    amount: model.amount,
+    weight: model.weight,
+    supplier: model.supplier,
+    type: model.type,
+  };
+};
+
+// 鏂板鎻愪氦锛堝吋瀹规棫妯″紡锛岀埗缁勪欢鍙皟鐢級
 const submit = async () => {
-  const currentWireId = props.wireId || paramsId.value;
-  const { code } = await TwistApi.addStrandedWireDish([
-    {
-      wireId: currentWireId,
-      ...model,
-    },
-  ]);
-  if (code == 200) {
-    toast.success("鏂板鎴愬姛");
-    emits("refresh");
-    return true;
-  }
-  return false;
+  return collectData();
 };
 
-// 缂栬緫鎻愪氦锛堜篃璧版柊澧炴帴鍙o紝鎻愪氦鏁翠釜鍒楄〃锛�
+// 缂栬緫鎻愪氦锛堝吋瀹规棫妯″紡锛屼笉璋傾PI锛岃繑鍥炶〃鍗曟暟鎹級
 const submitEdit = async (list?: any[], id?: number) => {
-  const currentList = list || allListData.value;
-  const currentId = id || editId.value;
-
-  if (!currentId) {
-    toast.error("缂哄皯璁板綍ID");
-    return false;
-  }
-
-  // 鏇存柊鍒楄〃涓搴旂殑鏁版嵁椤�
-  const updatedList = currentList.map((item) => {
-    if (item.id === currentId) {
-      // 淇濈暀鍘熸湁鏁版嵁锛岀劧鍚庢洿鏂颁慨鏀圭殑瀛楁
-      const updatedItem = {
-        ...item, // 鍏堜繚鐣欏師鏈夌殑鎵�鏈夋暟鎹�
-        diskMaterial: model.diskMaterial,
-        model: model.model,
-        monofilamentNumber: model.monofilamentNumber,
-        amount: model.amount,
-        weight: model.weight,
-        supplier: model.supplier,
-        type: model.type,
-      };
-      return updatedItem;
-    }
-    return item;
-  });
-
-  // 鎻愪氦鏁翠釜鍒楄〃
-  const { code } = await TwistApi.addStrandedWireDish(updatedList);
-
-  if (code == 200) {
-    toast.success("鏇存柊鎴愬姛");
-    return true;
-  }
-  return false;
+  return collectData();
 };
-
-// 璁剧疆琛ㄥ崟鏁版嵁锛堢敤浜庣紪杈戞椂鍥炴樉锛�
-const setFormData = (list: any[], currentEditId: number) => {
-  // 瀹夊叏妫�鏌ワ細纭繚list鏄暟缁�
-  if (!Array.isArray(list)) {
-    return;
-  }
-
-  // 瀛樺偍瀹屾暣鍒楄〃鏁版嵁
-  allListData.value = list;
-  editId.value = currentEditId;
-
-  // 鎵惧埌褰撳墠缂栬緫椤瑰苟鍥炴樉鍒拌〃鍗�
-  const currentItem = list.find((item) => item.id === currentEditId);
-  if (currentItem) {
-    model.diskMaterial = currentItem.diskMaterial;
-    model.model = currentItem.model;
-    model.monofilamentNumber = currentItem.monofilamentNumber;
-    model.amount = currentItem.amount;
-    model.weight = currentItem.weight;
-    model.supplier = currentItem.supplier;
-    model.type = currentItem.type || "閽㈣姱";
-    // 璁剧疆鑺嚎绫诲瀷鐨勫洖鏄惧��
-    diskMaterialValue.value = currentItem.diskMaterial || "";
-  }
-};
-
-// 鐩戝惉缂栬緫鏁版嵁鍙樺寲锛岃嚜鍔ㄥ洖鏄�
-watch(
-  () => props.editData,
-  (newData) => {
-    if (newData && props.mode === "edit") {
-      model.diskMaterial = newData.diskMaterial || "";
-      model.model = newData.model || "";
-      model.monofilamentNumber = newData.monofilamentNumber || "";
-      model.amount = newData.amount || "";
-      model.weight = newData.weight || "";
-      model.supplier = newData.supplier || "";
-      model.type = newData.type || "閽㈣姱";
-      diskMaterialValue.value = newData.diskMaterial || "";
-    }
-  },
-  { immediate: true, deep: true }
-);
 
 // 閲嶇疆琛ㄥ崟鏁版嵁
 const resetFormData = () => {
@@ -268,7 +187,7 @@
     model.diskMaterial = data.diskMaterial || "";
     model.model = data.model || "";
     model.monofilamentNumber = data.monofilamentNumber || "";
-    model.amount = data.oneLength || data.amount || "";
+    model.amount = data.amount || data.oneLength || "";
     model.weight = data.weight || "";
     model.supplier = data.supplier || "";
     model.type = data.type || "閽㈣姱";
@@ -276,9 +195,30 @@
   }
 };
 
-onLoad((options: any) => {
-  paramsId.value = options.id;
-});
+// 璁剧疆琛ㄥ崟鏁版嵁锛堢敤浜庣紪杈戞椂鍥炴樉锛屽吋瀹� edit.vue锛�
+const setFormData = (item: any) => {
+  if (item) {
+    model.diskMaterial = item.diskMaterial || "";
+    model.model = item.model || "";
+    model.monofilamentNumber = item.monofilamentNumber || "";
+    model.amount = item.amount || "";
+    model.weight = item.weight || "";
+    model.supplier = item.supplier || "";
+    model.type = item.type || "閽㈣姱";
+    diskMaterialValue.value = item.diskMaterial || "";
+  }
+};
+
+// 鐩戝惉缂栬緫鏁版嵁鍙樺寲锛岃嚜鍔ㄥ洖鏄�
+watch(
+  () => props.editData,
+  (newData) => {
+    if (newData && props.mode === "edit") {
+      setFormData(newData);
+    }
+  },
+  { immediate: true, deep: true }
+);
 
 onMounted(async () => {
   await loadDiskMaterialDict();
@@ -288,6 +228,7 @@
 defineExpose({
   submit,
   submitEdit,
+  collectData,
   setFormData,
   resetFormData,
   fillFormData,

--
Gitblit v1.9.3