From 6e39775c07de5b9051cef1626a6e975b3a26ebfa Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 29 四月 2026 15:25:54 +0800
Subject: [PATCH] 更新生产报告表单,以动态处理报告状态并相应调整输入字段

---
 src/pages/productionManagement/productionReport/index.vue |  121 +++++++++++++++++++++++++++++----------
 1 files changed, 89 insertions(+), 32 deletions(-)

diff --git a/src/pages/productionManagement/productionReport/index.vue b/src/pages/productionManagement/productionReport/index.vue
index dcd0fd7..a037365 100644
--- a/src/pages/productionManagement/productionReport/index.vue
+++ b/src/pages/productionManagement/productionReport/index.vue
@@ -1,7 +1,7 @@
 <template>
   <view class="invoice-add">
     <!-- 浣跨敤閫氱敤椤甸潰澶撮儴缁勪欢 -->
-    <PageHeader title="鐢熶骇鎶ュ伐"
+    <PageHeader :title="pageTitle"
                 @back="goBack" />
     <!-- 琛ㄥ崟鍐呭 -->
     <u-form @submit="submitForm"
@@ -18,14 +18,16 @@
                    placeholder="鑷姩濉厖"
                    disabled />
         </u-form-item>
-        <u-form-item label="鏈鐢熶骇鏁伴噺"
+        <u-form-item v-if="!isStartReport"
+                     label="鏈鐢熶骇鏁伴噺"
                      prop="quantity"
                      required>
           <u-input v-model="form.quantity"
                    placeholder="璇疯緭鍏�"
                    type="number" />
         </u-form-item>
-        <u-form-item label="鎶ュ簾鏁伴噺"
+        <u-form-item v-if="!isStartReport"
+                     label="鎶ュ簾鏁伴噺"
                      prop="scrapQty">
           <u-input v-model="form.scrapQty"
                    placeholder="璇疯緭鍏�"
@@ -58,7 +60,7 @@
 </template>
 
 <script setup>
-  import { ref, nextTick } from "vue";
+  import { computed, ref, nextTick } from "vue";
   import { onLoad } from "@dcloudio/uni-app";
   import FooterButtons from "@/components/FooterButtons.vue";
 
@@ -68,7 +70,7 @@
       icon: "none",
     });
   };
-  import { addProductMain } from "@/api/productionManagement/productionReporting";
+  import { addProductMain ,getReportState} from "@/api/productionManagement/productionReporting";
   import { getInfo } from "@/api/login";
   import { userListNoPageByTenantId } from "@/api/system/user";
 
@@ -85,6 +87,20 @@
     productProcessRouteItemId: "",
     userId: "",
     schedulingUserId: "",
+  });
+
+  // 鎶ュ伐鐘舵�侊紙鏉ヨ嚜 reportState 鎺ュ彛锛�
+  const reportState = ref({});
+
+  // 寮�濮嬫姤宸ワ細闅愯棌鈥滄湰娆$敓浜ф暟閲�/鎶ュ簾鏁伴噺鈥�
+  const isStartReport = computed(() => Number(reportState.value?.state) === 1);
+
+  const pageTitle = computed(() => {
+    const state = Number(reportState.value?.state);
+    if (state === 1) return "寮�濮嬫姤宸�";
+    if (state === 2) return "缁撴潫鎶ュ伐";
+    if (state === 3) return "鎶ュ伐瀹屾垚";
+    return "鐢熶骇鎶ュ伐";
   });
 
   // 鐢熶骇浜洪�夋嫨鍣ㄧ姸鎬�
@@ -130,38 +146,47 @@
   // 鎻愪氦琛ㄥ崟
   const submitForm = async () => {
     submitting.value = true;
-    // 鏍¢獙琛ㄥ崟
-    if (!form.value.quantity) {
-      submitting.value = false;
-      showToast("璇疯緭鍏ユ湰娆$敓浜ф暟閲�");
-      return;
-    }
+    const planQuantity = Number(form.value.planQuantity) || 0;
     if (!form.value.schedulingUserId) {
       submitting.value = false;
       showToast("璇烽�夋嫨鐢熶骇浜�");
       return;
     }
-    // 杞崲涓烘暟瀛楄繘琛屾瘮杈�
-    const quantity = Number(form.value.quantity) || 0;
-    const scrapQty = Number(form.value.scrapQty) || 0;
-    const planQuantity = Number(form.value.planQuantity);
-    // 楠岃瘉鐢熶骇鏁伴噺鍜屾姤搴熸暟閲忕殑鍜屼笉鑳借秴杩囧緟鐢熶骇鏁伴噺
-    if (quantity + scrapQty > planQuantity) {
-      submitting.value = false;
-      showToast("鐢熶骇鏁伴噺鍜屾姤搴熸暟閲忕殑鍜屼笉鑳借秴杩囧緟鐢熶骇鏁伴噺");
-      return;
+
+    // 寮�濮嬫姤宸ワ細涓嶉渶瑕佸~鍐欐暟閲�/鎶ュ簾鏁伴噺
+    let quantity = 0;
+    let scrapQty = 0;
+    if (!isStartReport.value) {
+      // 鏍¢獙琛ㄥ崟
+      if (!form.value.quantity) {
+        submitting.value = false;
+        showToast("璇疯緭鍏ユ湰娆$敓浜ф暟閲�");
+        return;
+      }
+
+      // 杞崲涓烘暟瀛楄繘琛屾瘮杈�
+      quantity = Number(form.value.quantity) || 0;
+      scrapQty = Number(form.value.scrapQty) || 0;
+
+      // 楠岃瘉鐢熶骇鏁伴噺鍜屾姤搴熸暟閲忕殑鍜屼笉鑳借秴杩囧緟鐢熶骇鏁伴噺
+      if (quantity + scrapQty > planQuantity) {
+        submitting.value = false;
+        showToast("鐢熶骇鏁伴噺鍜屾姤搴熸暟閲忕殑鍜屼笉鑳借秴杩囧緟鐢熶骇鏁伴噺");
+        return;
+      }
+      if (quantity > planQuantity) {
+        submitting.value = false;
+        showToast("鏈鐢熶骇鏁伴噺涓嶈兘澶т簬寰呯敓浜ф暟閲�");
+        return;
+      }
     }
-    if (quantity > planQuantity) {
-      submitting.value = false;
-      showToast("鏈鐢熶骇鏁伴噺涓嶈兘澶т簬寰呯敓浜ф暟閲�");
-      return;
-    }
+
     // 鍑嗗鎻愪氦鏁版嵁锛岀‘淇濇暟閲忓瓧娈典负鏁板瓧绫诲瀷
     const submitData = {
       ...form.value,
-      quantity: Number(form.value.quantity),
-      scrapQty: Number(form.value.scrapQty) || 0,
-      planQuantity: Number(form.value.planQuantity) || 0,
+      quantity,
+      scrapQty,
+      planQuantity,
     };
     console.log(submitData, "submitData");
 
@@ -188,25 +213,57 @@
       getInfo().then(res => {
         // 榛樿浣跨敤褰撳墠鐧诲綍鐢ㄦ埛
         form.value.userId = res.user.userId;
-        form.value.userName = res.user.userName;
+        // 鍥炴樉灞曠ず鍚嶇О浼樺厛浣跨敤 nickName锛涜嫢鍚庣涓嶈繑鍥炲垯鍏滃簳鐢� userName
+        // 閬垮厤浣跨敤鍙兘涓� id 鐨� userName 瀛楁瀵艰嚧鈥滃洖鏄剧殑鏄� id鈥�
+        form.value.userName = res.user.nickName || res.user.userName;
         form.value.schedulingUserId = res.user.userId;
       });
       return;
     }
     try {
-      const orderRow = JSON.parse(options.orderRow);
+      // options.orderRow 鏉ヨ嚜璺敱鍙傛暟锛屽彲鑳芥槸 encodeURIComponent 鍚庣殑瀛楃涓�
+      const orderRowRaw =
+        typeof options.orderRow === "string" ? options.orderRow : String(options.orderRow);
+      let orderRowStr = orderRowRaw;
+      try {
+        orderRowStr = decodeURIComponent(orderRowRaw);
+      } catch (e) {
+        // 鑻ュ凡缁忔槸鏈紪鐮佺殑 JSON锛屽垯鏃犻渶瑙g爜
+      }
+      const orderRow = JSON.parse(orderRowStr);
       console.log("鏋勯�犵殑orderRow:", orderRow);
       console.log(orderRow, "orderRow======########");
       // 纭繚 planQuantity 杞崲涓哄瓧绗︿覆锛屼互渚垮湪 u-input 涓纭樉绀�
       form.value.planQuantity = orderRow.planQuantity != null ? String(orderRow.planQuantity) : "";
       form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId || "";
-      form.value.workOrderId = orderRow.id || "";
+      form.value.workOrderId = orderRow.workOrderId || "";
+
+      // 鑻ユ壂鐮佺粨鏋滃凡鎼哄甫 todayReportState锛屽垯鍏堟湰鍦版覆鏌撴爣棰�/鏄鹃殣
+      if (orderRow.todayReportState != null) {
+        reportState.value = { state: Number(orderRow.todayReportState) };
+      }
       getInfo().then(res => {
         // 榛樿浣跨敤褰撳墠鐧诲綍鐢ㄦ埛锛屼絾鍏佽鐢ㄦ埛淇敼
         form.value.userId = res.user.userId;
-        form.value.userName = res.user.userName;
+        // 鍥炴樉灞曠ず鍚嶇О浼樺厛浣跨敤 nickName锛涜嫢鍚庣涓嶈繑鍥炲垯鍏滃簳鐢� userName
+        form.value.userName = res.user.nickName || res.user.userName;
         form.value.schedulingUserId = res.user.userId;
       });
+
+      // 鏍规嵁鎵爜浼犲叆鐨� orderRow 鑾峰彇鎶ュ伐鐘舵��
+      getReportState(orderRow)
+        .then(res => {
+          if (res.code === 200) {
+            reportState.value = res.data || {};
+          } else {
+            // 鐘舵�佽幏鍙栧け璐ユ椂锛屼笉褰卞搷椤甸潰姝e父褰曞叆锛堝厹搴曟樉绀鸿緭鍏ラ」锛�
+            console.warn("getReportState 杩斿洖闈�200锛�", res);
+          }
+        })
+        .catch(err => {
+          console.error("鑾峰彇鎶ュ伐鐘舵�佸け璐�:", err);
+        });
+
       // 浣跨敤 nextTick 纭繚 DOM 鏇存柊
       nextTick(() => {
         console.log("form.value after assignment:", form.value);

--
Gitblit v1.9.3