From af4f45eaa2703ecf991bd10f07f6df179f2677d9 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 19 十一月 2025 10:04:45 +0800
Subject: [PATCH] Merge branch 'refs/heads/yyb'

---
 src/pages/production/twist/report/index.vue |  205 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 175 insertions(+), 30 deletions(-)

diff --git a/src/pages/production/twist/report/index.vue b/src/pages/production/twist/report/index.vue
index f100b78..b9244b1 100644
--- a/src/pages/production/twist/report/index.vue
+++ b/src/pages/production/twist/report/index.vue
@@ -12,15 +12,23 @@
               <text class="text-[#0D867F] ml-2 font-medium">鐢熶骇浜�</text>
               <text class="text-[#333333] ml-2">{{ item.productUser }}</text>
             </view>
-            <view class="text-[#A8A8A8]" @click="toEdit">缂栬緫</view>
+            <!-- <view class="text-[#A8A8A8]" @click="toEdit">缂栬緫</view> -->
           </view>
         </template>
-        <ProductionCard :data="cardAttr" :value="item" />
+        <TwistReportCard :data="cardAttr" :value="item" />
         <template #footer>
           <wd-button size="small" plain style="margin-right: 10px" @click="toAttachment(item)">
             闄勪欢
           </wd-button>
-          <wd-button size="small" plain @click="handleSelfCheck(item.id)">鑷</wd-button>
+          <wd-button
+            size="small"
+            plain
+            style="margin-right: 10px"
+            @click="handleSelfCheck(item.id)"
+          >
+            鑷
+          </wd-button>
+          <wd-button size="small" plain type="error" @click="handleDelete(item)">鍒犻櫎</wd-button>
         </template>
       </wd-card>
     </z-paging>
@@ -30,7 +38,12 @@
         <wd-button type="text" @click="cancel">鍙栨秷</wd-button>
         <wd-button type="text" @click="submit">纭畾</wd-button>
       </view>
-      <TwistForm ref="twistFormRef" />
+      <TwistForm
+        ref="twistFormRef"
+        :first-tare-value="twistReportList.length > 0 ? twistReportList[0].tare : undefined"
+        :team-id="teamId"
+        :is-first-report="twistReportList.length === 0"
+      />
     </wd-popup>
     <wd-popup v-model="drawFormRef.visible" position="bottom" custom-class="yl-popup">
       <Draw
@@ -47,13 +60,15 @@
 <script setup lang="ts">
 import CardTitle from "@/components/card-title/index.vue";
 import TwistForm from "./form.vue";
-import { useToast } from "wot-design-uni";
-import ProductionCard from "../../components/ProductionCard.vue";
+import { useToast, dayjs } from "wot-design-uni";
+import TwistReportCard from "../components/TwistReportCard.vue";
 import { onLoad } from "@dcloudio/uni-app";
-import { ref, reactive } from "vue";
+import { ref, reactive, nextTick } from "vue";
 import ManageApi from "@/api/product/manage";
 import TwistApi from "@/api/product/twist";
 import Draw from "./draw.vue";
+import HomeApi from "@/api/home";
+import { setTeamId, getTeamId } from "@/utils/cache";
 
 const drawFormRef = reactive({
   visible: false,
@@ -95,36 +110,65 @@
 
 const cardAttr = ref<any[]>([
   {
-    label: "棰嗙敤鏉嗗彿",
-    prop: "poleNumber",
-  },
-  {
-    label: "鏉嗛噸(kg)",
-    prop: "poleWeight",
-  },
-  {
-    label: "鍗曚笣鐩樺彿",
+    label: "鎵规鍙�",
     prop: "monofilamentNumber",
+    span: 24,
   },
   {
-    label: "瀹為檯閲嶉噺(kg)",
-    prop: "actuallyWeight",
+    label: "璐ㄩ噺杩芥函鍙�",
+    prop: "systemNo",
+    span: 24,
   },
   {
     label: "鐩橀暱(m)",
     prop: "oneLength",
   },
   {
-    label: "鐞嗚閲嶉噺(kg)",
-    prop: "theoryWeight",
-  },
-  {
     label: "瑙勬牸鍨嬪彿",
     prop: "model",
+  },
+  {
+    label: "鐢熶骇闀垮害(m)",
+    prop: "actuallyLength",
+  },
+  {
+    label: "鐩樺叿鐨噸(kg)",
+    prop: "tare",
+  },
+  {
+    label: "鐢熶骇鏃ユ湡",
+    prop: "productTime",
+    span: 24,
+  },
+  {
+    label: "鍔犲伐鏃堕棿(h)",
+    prop: "processHour",
   },
 ]);
 
 const twistReportList = ref<any[]>([]);
+const teamId = ref<string | number | null>(null);
+
+// 鑾峰彇骞剁紦瀛樼彮缁処D
+const initTeamId = async () => {
+  // 鍏堝皾璇曚粠缂撳瓨鑾峰彇
+  const cachedTeamId = getTeamId();
+  if (cachedTeamId) {
+    teamId.value = cachedTeamId;
+    return;
+  }
+
+  // 濡傛灉缂撳瓨涓病鏈夛紝鍒欒皟鐢ㄦ帴鍙h幏鍙�
+  try {
+    const { data } = await HomeApi.getIndex();
+    if (data && data.team) {
+      teamId.value = data.team;
+      setTeamId(data.team);
+    }
+  } catch (error) {
+    console.error("鑾峰彇鐝粍ID澶辫触:", error);
+  }
+};
 
 const toEdit = () => {
   uni.navigateTo({
@@ -132,23 +176,83 @@
   });
 };
 
+// 涓昏〃鏁版嵁
+const mainTableData = ref<any>({});
+
+// 鑾峰彇涓昏〃鏁版嵁
+const getMainTableData = async () => {
+  try {
+    const { data } = await TwistApi.getTwistDetailById({
+      id: paramsId.value,
+    });
+    mainTableData.value = {
+      model: data.model,
+      totalLength: data.totalLength,
+      systemNo: data.systemNo,
+    };
+    // 璁剧疆涓昏〃鏁版嵁鍒拌〃鍗曠粍浠�
+    if (twistFormRef.value) {
+      twistFormRef.value.setMainTableData(mainTableData.value);
+    }
+  } catch (error) {
+    console.error("鑾峰彇涓昏〃鏁版嵁澶辫触:", error);
+  }
+};
+
 const addReport = async () => {
-  dialog.visible = true;
-  // 鎵撳紑鏂板寮圭獥鏃惰嚜鍔ㄦ墽琛�
-  // await showDrawPopup();
+  // 妫�鏌ユ槸鍚︽墍鏈夋暟鎹兘宸蹭繚瀛橈紙閮芥湁id锛�
+  if (twistReportList.value.length > 0 && twistReportList.value.every((item) => item.id)) {
+    // 纭繚涓昏〃鏁版嵁宸茶幏鍙�
+    if (!mainTableData.value.model) {
+      await getMainTableData();
+    }
+    dialog.visible = true;
+    // 绛夊緟寮圭獥鎵撳紑鍚庤缃暟鎹�
+    await nextTick();
+    if (twistFormRef.value) {
+      twistFormRef.value.setMainTableData(mainTableData.value);
+    }
+  } else if (twistReportList.value.length === 0) {
+    // 纭繚涓昏〃鏁版嵁宸茶幏鍙�
+    if (!mainTableData.value.model) {
+      await getMainTableData();
+    }
+    dialog.visible = true;
+    // 绛夊緟寮圭獥鎵撳紑鍚庤缃暟鎹�
+    await nextTick();
+    if (twistFormRef.value) {
+      twistFormRef.value.setMainTableData(mainTableData.value);
+    }
+  } else {
+    toast.warning("璇峰厛淇濆瓨鏈潯鏁版嵁锛屽啀鏂板");
+  }
 };
 
 const submit = async () => {
+  // 楠岃瘉蹇呭~瀛楁 - 鏍规嵁鍙傝�冧唬鐮侊紝闇�瑕佹鏌ョ敓浜ч暱搴﹀拰鐩樺叿鐨噸
+  const formData = twistFormRef.value?.getFormData?.() || {};
+  const firstTareValue =
+    twistReportList.value.length > 0 ? twistReportList.value[0].tare : undefined;
+
+  if (!formData.actuallyLength) {
+    toast.warning("璇疯緭鍏ョ敓浜ч暱搴﹀悗鍐嶆彁浜�");
+    return;
+  }
+
+  if (!formData.tare && !firstTareValue) {
+    toast.warning("璇疯緭鍏ョ洏鍏风毊閲嶅悗鍐嶆彁浜�");
+    return;
+  }
+
   const isSuccess = await twistFormRef.value.submit();
-  dialog.visible = !isSuccess; // 濡傛灉鎻愪氦鎴愬姛锛屽叧闂脊绐�
   if (isSuccess) {
-    // 鎻愪氦鎴愬姛鍚庢墽琛�
-    // showDrawPopup();
+    dialog.visible = false;
+    // 鎻愪氦鎴愬姛鍚庡埛鏂板垪琛�
+    pagingRef.value?.reload();
   }
 };
 
 const cancel = () => {
-  toast.show("鍙栨秷");
   dialog.visible = false;
 };
 
@@ -197,6 +301,35 @@
   });
 };
 
+// 鍒犻櫎鎶ュ伐璁板綍
+const handleDelete = (item: any) => {
+  uni.showModal({
+    title: "鎻愮ず",
+    content: "纭畾鍒犻櫎鍚楋紵",
+    success: async (res) => {
+      if (res.confirm) {
+        try {
+          if (item.id) {
+            const { code } = await TwistApi.deleteWireOutput({ id: item.id });
+            if (code == 200) {
+              toast.success("鍒犻櫎鎴愬姛");
+              // 鍒锋柊鍒楄〃
+              pagingRef.value?.reload();
+            } else {
+              toast.error("鍒犻櫎澶辫触");
+            }
+          } else {
+            toast.warning("璇ヨ褰曞皻鏈繚瀛橈紝鏃犳硶鍒犻櫎");
+          }
+        } catch (error) {
+          console.error("鍒犻櫎澶辫触:", error);
+          toast.error("鍒犻櫎澶辫触锛岃閲嶈瘯");
+        }
+      }
+    },
+  });
+};
+
 // 淇濈暀鍘熸湁鐨刢onfirm鍑芥暟锛岀敤浜庡叾浠栧湴鏂硅皟鐢�
 // const confirm = async () => {
 //   await showDrawPopup();
@@ -208,11 +341,23 @@
     wireId: paramsId.value,
     type: "缁炵嚎",
   });
+  // 鏍煎紡鍖栫敓浜ф棩鏈�
+  if (Array.isArray(data)) {
+    data.forEach((item: any) => {
+      if (item.productTime) {
+        item.productTime = dayjs(item.productTime).format("YYYY-MM-DD HH:mm:ss");
+      }
+    });
+  }
   pagingRef.value.complete(data);
 };
 
-onLoad((options: any) => {
+onLoad(async (options: any) => {
   paramsId.value = options.id;
+  // 鑾峰彇骞剁紦瀛樼彮缁処D
+  await initTeamId();
+  // 鑾峰彇涓昏〃鏁版嵁
+  await getMainTableData();
   showDrawPopup();
 });
 </script>

--
Gitblit v1.9.3