From c13c2bb15b501c74fe4270b0ae763e5c9422ee39 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 19 十一月 2025 10:02:52 +0800
Subject: [PATCH] fix: 重构绞线报工功能

---
 src/pages/production/twist/receive/steelCore/form.vue |  136 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 123 insertions(+), 13 deletions(-)

diff --git a/src/pages/production/twist/receive/steelCore/form.vue b/src/pages/production/twist/receive/steelCore/form.vue
index c4185ec..4561801 100644
--- a/src/pages/production/twist/receive/steelCore/form.vue
+++ b/src/pages/production/twist/receive/steelCore/form.vue
@@ -1,6 +1,16 @@
 <template>
   <wd-form ref="form" :model="model" class="relative form_box">
     <wd-cell-group :border="true">
+      <wd-picker
+        v-model="diskMaterialValue"
+        :columns="diskMaterialOptions"
+        label="鑺嚎绫诲瀷"
+        label-width="100px"
+        prop="diskMaterial"
+        placeholder="璇烽�夋嫨鑺嚎绫诲瀷"
+        clearable
+        @confirm="handleDiskMaterialChange"
+      />
       <wd-input
         v-model="model.model"
         label="瑙勬牸鍨嬪彿"
@@ -48,7 +58,23 @@
 <script lang="ts" setup>
 import useFormData from "@/hooks/useFormData";
 import TwistApi from "@/api/product/twist";
+import ManageApi from "@/api/product/manage";
 import { useToast } from "wot-design-uni";
+
+const props = defineProps({
+  mode: {
+    type: String,
+    default: "add",
+  },
+  editData: {
+    type: Object,
+    default: null,
+  },
+  wireId: {
+    type: [String, Number],
+    default: undefined,
+  },
+});
 
 const emits = defineEmits(["refresh"]);
 const paramsId = ref();
@@ -56,6 +82,7 @@
 const allListData = ref<any[]>([]); // 瀛樺偍瀹屾暣鍒楄〃鏁版嵁
 const toast = useToast();
 const { form: model } = useFormData({
+  diskMaterial: undefined, // 鑺嚎绫诲瀷
   model: undefined, // 瑙勬牸鍨嬪彿
   monofilamentNumber: undefined, // 鏍峰搧缂栧彿
   amount: undefined, // 鏁伴噺
@@ -64,11 +91,45 @@
   type: "閽㈣姱",
 });
 
+// 鑺嚎绫诲瀷瀛楀吀鏁版嵁
+const diskMaterialOptions = ref<Array<{ label: string; value: string }>>([]);
+const diskMaterialValue = ref("");
+
+// 鍔犺浇鑺嚎绫诲瀷瀛楀吀鏁版嵁
+const loadDiskMaterialDict = async () => {
+  try {
+    const res = await ManageApi.dictAPI("core_wire_type");
+    if (res.data && Array.isArray(res.data)) {
+      diskMaterialOptions.value = res.data.map((item: any) => ({
+        label: item.dictLabel || "",
+        value: item.dictValue || "",
+      }));
+    }
+  } catch (error) {
+    // 鍔犺浇瀛楀吀澶辫触锛岄潤榛樺鐞�
+  }
+};
+
+// 澶勭悊鑺嚎绫诲瀷閫夋嫨
+const handleDiskMaterialChange = (val: any) => {
+  model.diskMaterial = val.value;
+};
+
+// 鐩戝惉 model.diskMaterial 鍙樺寲锛屽悓姝ラ�夋嫨鍣ㄦ樉绀�
+watch(
+  () => model.diskMaterial,
+  (newValue) => {
+    diskMaterialValue.value = newValue || "";
+  },
+  { immediate: true }
+);
+
 // 鏂板鎻愪氦
 const submit = async () => {
+  const currentWireId = props.wireId || paramsId.value;
   const { code } = await TwistApi.addStrandedWireDish([
     {
-      wireId: paramsId.value,
+      wireId: currentWireId,
       ...model,
     },
   ]);
@@ -81,22 +142,22 @@
 };
 
 // 缂栬緫鎻愪氦锛堜篃璧版柊澧炴帴鍙o紝鎻愪氦鏁翠釜鍒楄〃锛�
-const submitEdit = async () => {
-  if (!editId.value) {
+const submitEdit = async (list?: any[], id?: number) => {
+  const currentList = list || allListData.value;
+  const currentId = id || editId.value;
+
+  if (!currentId) {
     toast.error("缂哄皯璁板綍ID");
     return false;
   }
 
-  console.log("submitEdit - 缂栬緫鍓嶇殑鍒楄〃:", allListData.value);
-  console.log("submitEdit - 褰撳墠琛ㄥ崟鏁版嵁:", model);
-  console.log("submitEdit - 缂栬緫鐨処D:", editId.value);
-
   // 鏇存柊鍒楄〃涓搴旂殑鏁版嵁椤�
-  const updatedList = allListData.value.map((item) => {
-    if (item.id === editId.value) {
+  const updatedList = currentList.map((item) => {
+    if (item.id === currentId) {
       // 淇濈暀鍘熸湁鏁版嵁锛岀劧鍚庢洿鏂颁慨鏀圭殑瀛楁
       const updatedItem = {
         ...item, // 鍏堜繚鐣欏師鏈夌殑鎵�鏈夋暟鎹�
+        diskMaterial: model.diskMaterial,
         model: model.model,
         monofilamentNumber: model.monofilamentNumber,
         amount: model.amount,
@@ -104,13 +165,10 @@
         supplier: model.supplier,
         type: model.type,
       };
-      console.log("submitEdit - 鏇存柊鍚庣殑椤�:", updatedItem);
       return updatedItem;
     }
     return item;
   });
-
-  console.log("submitEdit - 鎻愪氦鐨勫畬鏁村垪琛�:", updatedList);
 
   // 鎻愪氦鏁翠釜鍒楄〃
   const { code } = await TwistApi.addStrandedWireDish(updatedList);
@@ -126,7 +184,6 @@
 const setFormData = (list: any[], currentEditId: number) => {
   // 瀹夊叏妫�鏌ワ細纭繚list鏄暟缁�
   if (!Array.isArray(list)) {
-    console.error("setFormData: list 鍙傛暟涓嶆槸鏁扮粍", list);
     return;
   }
 
@@ -137,12 +194,59 @@
   // 鎵惧埌褰撳墠缂栬緫椤瑰苟鍥炴樉鍒拌〃鍗�
   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 = () => {
+  model.diskMaterial = undefined;
+  model.model = undefined;
+  model.monofilamentNumber = undefined;
+  model.amount = undefined;
+  model.weight = undefined;
+  model.supplier = undefined;
+  model.type = "閽㈣姱";
+  diskMaterialValue.value = "";
+};
+
+// 濉厖琛ㄥ崟鏁版嵁锛堢敤浜庢壂鐮佸悗鍥炴樉锛�
+const fillFormData = (data: any) => {
+  if (data) {
+    model.diskMaterial = data.diskMaterial || "";
+    model.model = data.model || "";
+    model.monofilamentNumber = data.monofilamentNumber || "";
+    model.amount = data.oneLength || data.amount || "";
+    model.weight = data.weight || "";
+    model.supplier = data.supplier || "";
+    model.type = data.type || "閽㈣姱";
+    diskMaterialValue.value = data.diskMaterial || "";
   }
 };
 
@@ -150,10 +254,16 @@
   paramsId.value = options.id;
 });
 
+onMounted(async () => {
+  await loadDiskMaterialDict();
+});
+
 defineExpose({
   submit,
   submitEdit,
   setFormData,
+  resetFormData,
+  fillFormData,
 });
 </script>
 

--
Gitblit v1.9.3