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/report/form.vue |  184 +++++++++++++++++++++++++++------------------
 1 files changed, 110 insertions(+), 74 deletions(-)

diff --git a/src/pages/production/twist/report/form.vue b/src/pages/production/twist/report/form.vue
index 2e62f0c..cb804bb 100644
--- a/src/pages/production/twist/report/form.vue
+++ b/src/pages/production/twist/report/form.vue
@@ -2,103 +2,139 @@
   <wd-form ref="form" :model="model" class="relative form_box">
     <wd-cell-group :border="true">
       <wd-input
-        v-model="model.contractNo"
-        label="棰嗙敤鏉嗗彿"
-        label-width="100px"
-        prop="contractNo"
-        clearable
-        placeholder="璇疯緭鍏ラ鐢ㄦ潌鍙�"
-      />
-      <wd-input
-        v-model="model.status"
-        label="鏉嗛噸(kg)"
-        label-width="100px"
-        prop="status"
-        clearable
-        placeholder="璇疯緭鍏ユ潌閲�"
-      />
-      <wd-input
-        v-model="model.clientName"
-        label="鍗曚笣鐩樺彿"
-        label-width="100px"
-        prop="clientName"
-        clearable
-        placeholder="璇疯緭鍏ュ崟涓濈洏鍙�"
-      />
-      <wd-input
-        v-model="model.workbench"
-        label="瀹為檯閲嶉噺(kg)"
-        label-width="100px"
-        prop="workbench"
-        clearable
-        placeholder="璇疯緭鍏ュ疄闄呴噸閲�"
-      />
-      <wd-input
-        v-model="model.quality"
-        label="鐩橀暱(m)"
-        label-width="100px"
-        prop="quality"
-        clearable
-        placeholder="璇疯緭鍏ョ洏闀�"
-      />
-      <wd-input
-        v-model="model.specification"
-        label="鐞嗚閲嶉噺(kg)"
-        label-width="100px"
-        prop="specification"
-        clearable
-        placeholder="璇疯緭鍏ョ悊璁洪噸閲�"
-      />
-      <wd-input
-        v-model="model.disc"
-        label="瑙勬牸鍨嬪彿"
-        label-width="100px"
-        prop="disc"
-        clearable
-        placeholder="璇疯緭鍏ヨ鏍煎瀷鍙�"
-      />
-      <wd-input
         v-model="model.actuallyLength"
-        label="瀹為檯鐩橀暱(m)"
+        label="鐢熶骇闀垮害(m)"
         label-width="100px"
         prop="actuallyLength"
         clearable
-        placeholder="璇疯緭鍏ュ疄闄呯洏闀�"
-      />
+        placeholder="璇疯緭鍏ョ敓浜ч暱搴�"
+        type="digit"
+      >
+        <template #label>
+          <span style="color: #f56c6c">鐢熶骇闀垮害(m)</span>
+        </template>
+      </wd-input>
+      <wd-input
+        v-model="model.tare"
+        label="鐩樺叿鐨噸(kg)"
+        label-width="100px"
+        prop="tare"
+        :disabled="!isFirstReport"
+        :clearable="isFirstReport"
+        :placeholder="isFirstReport ? '璇疯緭鍏ョ洏鍏风毊閲�' : '鐩樺叿鐨噸鑷姩甯﹀嚭'"
+        type="digit"
+      >
+        <template #label>
+          <span style="color: #f56c6c">鐩樺叿鐨噸(kg)</span>
+        </template>
+      </wd-input>
     </wd-cell-group>
   </wd-form>
 </template>
 
 <script lang="ts" setup>
+import { computed, watch } from "vue";
 import useFormData from "@/hooks/useFormData";
-import { useToast } from "wot-design-uni";
+import { useToast, dayjs } from "wot-design-uni";
 import TwistApi from "@/api/product/twist";
+
+// 瀹氫箟 props
+const props = defineProps<{
+  firstTareValue?: number;
+  teamId?: string | number | null;
+  isFirstReport?: boolean; // 鏄惁鏄涓�鏉℃姤宸�
+}>();
+
+// 璁$畻鏄惁鏄涓�鏉℃姤宸�
+const isFirstReport = computed(() => props.isFirstReport ?? true);
 
 const paramsId = ref();
 const toast = useToast();
-const { form: model } = useFormData({
-  poleNumber: undefined, // 棰嗙敤鏉嗗彿
-  poleWeight: undefined, // 鏉嗛噸(kg)
-  monofilamentNumber: undefined, // 鍗曚笣鐩樺彿
-  actuallyWeight: undefined, // 瀹為檯閲嶉噺(kg)
-  oneLength: undefined, // 鐩橀暱(m)
-  theoryWeight: undefined, // 鐞嗚閲嶉噺(kg)
-  model: undefined, // 瑙勬牸鍨嬪彿
-  actuallyLength: undefined, // 瀹為檯鐩橀暱(m)
+const { form: model, resetForm } = useFormData({
+  actuallyLength: undefined, // 鐢熶骇闀垮害(m)
+  tare: undefined, // 鐩樺叿鐨噸(kg)
 });
 
+// 涓昏〃鏁版嵁锛堜粠鐖剁粍浠朵紶鍏ワ級
+const mainTableData = ref<any>({});
+
+// 璁剧疆涓昏〃鏁版嵁
+const setMainTableData = (data: any) => {
+  mainTableData.value = data;
+};
+
+// 鐩戝惉 firstTareValue 鍙樺寲锛屽鏋滀笉鏄涓�鏉★紝鑷姩濉厖
+watch(
+  () => props.firstTareValue,
+  (newVal) => {
+    if (!isFirstReport.value && newVal !== undefined) {
+      model.tare = newVal;
+    }
+  },
+  { immediate: true }
+);
+
 const submit = async () => {
-  const { code } = await TwistApi.addTwistOutput({
+  // 鑾峰彇绗竴鏉℃暟鎹殑鐨噸鍊硷紝鐢ㄤ簬鍚庣画鏂板鐨勬姤宸�
+  const firstTareValue = props.firstTareValue;
+
+  // 濡傛灉涓昏〃鏁版嵁鏈幏鍙栵紝灏濊瘯閲嶆柊鑾峰彇
+  if (!mainTableData.value.model) {
+    try {
+      const { data } = await TwistApi.getTwistDetailById({
+        id: paramsId.value,
+      });
+      mainTableData.value = {
+        model: data.model,
+        totalLength: data.totalLength,
+        systemNo: data.systemNo,
+      };
+    } catch (error) {
+      console.error("鑾峰彇涓昏〃鏁版嵁澶辫触:", error);
+      toast.error("鑾峰彇瑙勬牸鍨嬪彿鏁版嵁澶辫触锛岃閲嶈瘯");
+      return false;
+    }
+  }
+
+  // 鍐嶆妫�鏌ヤ富琛ㄦ暟鎹�
+  if (!mainTableData.value.model) {
+    toast.error("瑙勬牸鍨嬪彿鏁版嵁鏈幏鍙栵紝璇烽噸璇�");
+    return false;
+  }
+
+  const submitData = {
+    teamId: props.teamId || null,
     wireId: paramsId.value,
-    ...model,
-  });
+    type: "缁炵嚎",
+    actuallyLength: model.actuallyLength,
+    tare: model.tare || firstTareValue,
+    // 浠庝富琛ㄨ幏鍙栫殑瀛楁
+    model: mainTableData.value.model, // 瑙勬牸鍨嬪彿
+    oneLength: mainTableData.value.totalLength,
+    systemNo: mainTableData.value.systemNo,
+    monofilamentNumber: undefined, // 鎵规鍙凤紙鍚庣鑷姩鐢熸垚锛�
+    // 鐢熶骇鏃ユ湡鑷姩璁剧疆涓哄綋鍓嶆椂闂�
+    productTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
+  };
+
+  // 璋冭瘯鏃ュ織
+  console.log("鎻愪氦鏁版嵁:", submitData);
+  console.log("涓昏〃鏁版嵁:", mainTableData.value);
+
+  const { code } = await TwistApi.addTwistOutput(submitData);
   if (code == 200) {
     toast.success("鎻愪氦鎴愬姛");
+    resetForm();
     return true;
   } else {
     toast.error("鎻愪氦澶辫触");
     return false;
   }
+};
+
+// 鑾峰彇琛ㄥ崟鏁版嵁
+const getFormData = () => {
+  return { ...model };
 };
 
 onLoad((options: any) => {
@@ -107,12 +143,12 @@
 
 defineExpose({
   submit,
+  getFormData,
+  setMainTableData,
 });
 </script>
 
 <style lang="scss" scoped>
-.form_box {
-}
 .submit_btn {
   position: absolute;
   bottom: 0;

--
Gitblit v1.9.3