From 78c565e37520fad100693c4e298e30e7c916d1bb Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 28 十月 2025 16:21:40 +0800
Subject: [PATCH] fix: 领用二维码异常提示,原材料自检重构

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

diff --git a/src/pages/production/twist/receive/steelCore/form.vue b/src/pages/production/twist/receive/steelCore/form.vue
index 92dfb7e..616e48f 100644
--- a/src/pages/production/twist/receive/steelCore/form.vue
+++ b/src/pages/production/twist/receive/steelCore/form.vue
@@ -26,10 +26,18 @@
         placeholder="璇疯緭鍏ラ暱搴�"
       />
       <wd-input
-        v-model="model.manufacturers"
+        v-model="model.weight"
+        label="閲嶉噺"
+        label-width="100px"
+        prop="weight"
+        clearable
+        placeholder="璇疯緭鍏ラ噸閲�"
+      />
+      <wd-input
+        v-model="model.supplier"
         label="鍘傚"
         label-width="100px"
-        prop="manufacturers"
+        prop="supplier"
         clearable
         placeholder="璇疯緭鍏ュ巶瀹�"
       />
@@ -39,18 +47,151 @@
 
 <script lang="ts" setup>
 import useFormData from "@/hooks/useFormData";
+import TwistApi from "@/api/product/twist";
+import { useToast } from "wot-design-uni";
 
+const props = defineProps({
+  mode: {
+    type: String,
+    default: "add",
+  },
+  editData: {
+    type: Object,
+    default: null,
+  },
+});
+
+const emits = defineEmits(["refresh"]);
+const paramsId = ref();
+const editId = ref(); // 缂栬緫鏃剁殑ID
+const allListData = ref<any[]>([]); // 瀛樺偍瀹屾暣鍒楄〃鏁版嵁
+const toast = useToast();
 const { form: model } = useFormData({
   model: undefined, // 瑙勬牸鍨嬪彿
   monofilamentNumber: undefined, // 鏍峰搧缂栧彿
   amount: undefined, // 鏁伴噺
-  manufacturers: undefined, // 鍘傚
+  weight: undefined, // 閲嶉噺
+  supplier: undefined, // 鍘傚
+  type: "閽㈣姱",
+});
+
+// 鏂板鎻愪氦
+const submit = async () => {
+  const { code } = await TwistApi.addStrandedWireDish([
+    {
+      wireId: paramsId.value,
+      ...model,
+    },
+  ]);
+  if (code == 200) {
+    toast.success("鏂板鎴愬姛");
+    emits("refresh");
+    return true;
+  }
+  return false;
+};
+
+// 缂栬緫鎻愪氦锛堜篃璧版柊澧炴帴鍙o紝鎻愪氦鏁翠釜鍒楄〃锛�
+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, // 鍏堜繚鐣欏師鏈夌殑鎵�鏈夋暟鎹�
+        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;
+};
+
+// 璁剧疆琛ㄥ崟鏁版嵁锛堢敤浜庣紪杈戞椂鍥炴樉锛�
+const setFormData = (list: any[], currentEditId: number) => {
+  // 瀹夊叏妫�鏌ワ細纭繚list鏄暟缁�
+  if (!Array.isArray(list)) {
+    console.error("setFormData: list 鍙傛暟涓嶆槸鏁扮粍", list);
+    return;
+  }
+
+  // 瀛樺偍瀹屾暣鍒楄〃鏁版嵁
+  allListData.value = list;
+  editId.value = currentEditId;
+
+  // 鎵惧埌褰撳墠缂栬緫椤瑰苟鍥炴樉鍒拌〃鍗�
+  const currentItem = list.find((item) => item.id === currentEditId);
+  if (currentItem) {
+    model.model = currentItem.model;
+    model.monofilamentNumber = currentItem.monofilamentNumber;
+    model.amount = currentItem.amount;
+    model.weight = currentItem.weight;
+    model.supplier = currentItem.supplier;
+    model.type = currentItem.type || "閽㈣姱";
+  }
+};
+
+// 鐩戝惉缂栬緫鏁版嵁鍙樺寲锛岃嚜鍔ㄥ洖鏄�
+watch(
+  () => props.editData,
+  (newData) => {
+    if (newData && props.mode === "edit") {
+      model.model = newData.model || "";
+      model.monofilamentNumber = newData.monofilamentNumber || "";
+      model.amount = newData.amount || "";
+      model.weight = newData.weight || "";
+      model.supplier = newData.supplier || "";
+      model.type = newData.type || "閽㈣姱";
+    }
+  },
+  { immediate: true, deep: true }
+);
+
+// 閲嶇疆琛ㄥ崟鏁版嵁
+const resetFormData = () => {
+  model.model = undefined;
+  model.monofilamentNumber = undefined;
+  model.amount = undefined;
+  model.weight = undefined;
+  model.supplier = undefined;
+  model.type = "閽㈣姱";
+};
+
+onLoad((options: any) => {
+  paramsId.value = options.id;
+});
+
+defineExpose({
+  submit,
+  submitEdit,
+  setFormData,
+  resetFormData,
 });
 </script>
 
 <style lang="scss" scoped>
-.form_box {
-}
 .submit_btn {
   position: absolute;
   bottom: 0;

--
Gitblit v1.9.3