From 9f959614d9168ed5a86530ee3cb735d0b007238b Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期三, 29 四月 2026 09:20:49 +0800
Subject: [PATCH] feat(productionManagement): 新增工艺路线绑定功能

---
 src/views/productionManagement/workOrder/index.vue |  212 ++++++++++++++++++++++++++++------------------------
 1 files changed, 113 insertions(+), 99 deletions(-)

diff --git a/src/views/productionManagement/workOrder/index.vue b/src/views/productionManagement/workOrder/index.vue
index 18423af..edae03e 100644
--- a/src/views/productionManagement/workOrder/index.vue
+++ b/src/views/productionManagement/workOrder/index.vue
@@ -234,7 +234,7 @@
                   placeholder="璇烽�夋嫨鐝粍鎴愬憳"
               >
                 <el-option
-                    v-for="user in userTeamOptions"
+                    v-for="user in reportForm.userIdsList"
                     :key="user.userId"
                     :label="user.nickName"
                     :value="{ userId: user.userId, userName: user.nickName }"
@@ -243,25 +243,25 @@
             </el-form-item>
           </el-col>
 
-          <el-col :span="12">
-            <el-form-item label="鏈哄彴" prop="deviceId">
-              <el-select
-                  v-model="reportForm.deviceId"
-                  placeholder="璇烽�夋嫨鏈哄彴"
-                  filterable
-                  clearable
-                  @change="(val) => handleDeviceChange(val)"
-                  :disabled="isDetail"
-              >
-                <el-option
-                    v-for="item in deviceOptions"
-                    :key="item.id"
-                    :label="item.deviceName"
-                    :value="item.id"
-                />
-              </el-select>
-            </el-form-item>
-          </el-col>
+<!--          <el-col :span="12">-->
+<!--            <el-form-item label="鏈哄彴" prop="deviceId">-->
+<!--              <el-select-->
+<!--                  v-model="reportForm.deviceId"-->
+<!--                  placeholder="璇烽�夋嫨鏈哄彴"-->
+<!--                  filterable-->
+<!--                  clearable-->
+<!--                  @change="(val) => handleDeviceChange(val)"-->
+<!--                  :disabled="isDetail"-->
+<!--              >-->
+<!--                <el-option-->
+<!--                    v-for="item in deviceOptions"-->
+<!--                    :key="item.id"-->
+<!--                    :label="item.deviceName"-->
+<!--                    :value="item.id"-->
+<!--                />-->
+<!--              </el-select>-->
+<!--            </el-form-item>-->
+<!--          </el-col>-->
 
           <el-col :span="12">
             <el-form-item label="瀹℃牳浜�" prop="auditUserId">
@@ -337,10 +337,8 @@
             </el-button>
           </el-col>
         </el-row>
-
         <el-table :data="scheduleRows" border style="width: 100%" v-loading="scheduleLoading">
-          <el-table-column type="index" label="搴忓彿" width="70" align="center" />
-
+          <el-table-column type="index" label="搴忓彿" width="70" align="center" :index="indexMethod" />
           <el-table-column label="鏈涓婃満鏈哄彴" min-width="220">
             <template #default="{ row }">
               <el-select
@@ -441,6 +439,7 @@
 import {ElMessageBox, ElMessage} from "element-plus";
 import Pagination from "@/components/PIMTable/Pagination.vue";
 import dayjs from "dayjs";
+import { processList } from '@/api/productionManagement/productionProcess.js'
 import {
   productWorkOrderPage,
   updateProductWorkOrder,
@@ -500,50 +499,15 @@
   return [val];
 };
 
-const isCurrentUserReportWorker = (row) => {
+const isCurrentUserInUserIds = (row) => {
   const uid = String(currentUserId.value || "");
   if (!uid) return false;
-  if (!row) return false;
 
-  const candidateIds = [
-    row.reportUserIds,
-    row.reportWorkerIds,
-    row.userIdList,
-    row.reportUserId,
-    row.userId,
-  ]
-      .flatMap((v) => normalizeArray(v))
-      .map((v) => String(v))
+  const ids = normalizeArray(row?.userIds)
+      .map(id => String(id))
       .filter(Boolean);
 
-  if (candidateIds.includes(uid)) return true;
-
-  const candidateNames = [
-    row.userNames,
-    row.reportUserNames,
-    row.reportWorkerNames,
-    row.userName,
-  ]
-      .flatMap((v) => normalizeArray(v))
-      .map((v) => String(v))
-      .filter(Boolean);
-
-  if (currentUserName.value && candidateNames.includes(currentUserName.value)) {
-    return true;
-  }
-
-  if (Array.isArray(row.reportWorkerList)) {
-    const list = row.reportWorkerList
-        .map((item) => String(item?.userId ?? item?.id ?? ""))
-        .filter(Boolean);
-    if (list.includes(uid)) return true;
-    const nameList = row.reportWorkerList
-        .map((item) => String(item?.userName ?? item?.nickName ?? ""))
-        .filter(Boolean);
-    if (currentUserName.value && nameList.includes(currentUserName.value)) return true;
-  }
-
-  return false;
+  return ids.includes(uid);
 };
 
 const canOperateByReportWorker = computed(() => {
@@ -707,8 +671,7 @@
       return;
     }
 
-    const rows = buildScheduleRowsFromRecords(records);
-
+    const rows = records.map(record => mapMachineRecordToScheduleRow(record));
     scheduleRows.value = rows.length > 0 ? rows : [createScheduleRow({})];
   } catch (error) {
     console.error("鑾峰彇鎺掍骇璁板綍澶辫触", error);
@@ -849,6 +812,10 @@
   }
 
   return payload;
+};
+
+const indexMethod = (index) => {
+  return (schedulePage.current - 1) * schedulePage.size + index + 1;
 };
 
 const mapMachineRecordToScheduleRow = (record) => {
@@ -1042,13 +1009,21 @@
         clickFun: row => {
           showReportDialog(row);
         },
+        // 鐢ㄦ埛褰撳墠id
+        disabled: row => row.completeQuantity !==0 ||
+            !isCurrentUserInUserIds(row)
       },
       {
         name: "鐢熶骇鎺掍骇",
         clickFun: row => {
+          if (!row.canSchedule) {
+            ElMessage.warning("褰撳墠鐢ㄦ埛涓嶅湪璇ュ伐搴忎汉鍛樹腑锛屼笉鑳界敓浜ф帓浜�");
+            return;
+          }
           openScheduleDialog(row);
         },
-      },
+        disabled: row => !row.canSchedule || row.completeQuantity >= row.planQuantity
+      }
       // {
       //   name:"瀹℃牳",
       //   color: "#f56c6c",
@@ -1292,18 +1267,27 @@
   page.size = obj.limit;
   getList();
 };
-const getList = () => {
+const getList = async () => {
   tableLoading.value = true;
-  const params = {...searchForm.value, ...page};
-  productWorkOrderPage(params)
-      .then(res => {
-        tableLoading.value = false;
-        tableData.value = res.data.records;
-        page.total = res.data.total;
-      })
-      .catch(() => {
-        tableLoading.value = false;
-      });
+
+  try {
+    await ensureCurrentUser();
+    await processLists();
+
+    const params = { ...searchForm.value, ...page };
+    const res = await productWorkOrderPage(params);
+
+    const records = Array.isArray(res?.data?.records) ? res.data.records : [];
+
+    tableData.value = records.map(row => ({
+      ...row,
+      canSchedule: canScheduleByWorkOrderNo(row)
+    }));
+
+    page.total = res?.data?.total || 0;
+  } finally {
+    tableLoading.value = false;
+  }
 };
 
 // 涓嬭浇骞舵墦鍗板伐鍗曟祦杞崱锛堟枃浠舵祦锛�
@@ -1394,14 +1378,9 @@
 };
 
 const showReportDialog = row => {
-  // if (!isCurrentUserReportWorker(row)) {
-  //   ElMessage.warning("褰撳墠鐢ㄦ埛涓嶆槸璇ュ伐鍗曠殑鎶ュ伐浜猴紝鏃犳硶鎶ュ伐");
-  //   return;
-  // }
   currentReportRowData.value = row;
   reportForm.planQuantity = row.planQuantity - row.completeQuantity;
-  reportForm.quantity =
-      row.quantity !== undefined && row.quantity !== null ? row.quantity : null;
+  reportForm.quantity = row.quantity !== undefined && row.quantity !== null ? row.quantity : null;
   reportForm.productProcessRouteItemId = row.productProcessRouteItemId;
   reportForm.workOrderId = row.id;
   reportForm.reportWork = row.reportWork;
@@ -1411,6 +1390,20 @@
   reportForm.replenishQty = 0;
   reportForm.teamList = [];
   reportForm.scrapQty = 0;
+  reportForm.userIds = row.userIds || [];
+
+  const ids = (row.userIds || "")
+      .split(",")
+      .map(id => id.trim())
+      .filter(Boolean);
+
+  reportForm.userIdsList = userTeamOptions.value
+      .filter(item => ids.includes(String(item.userId)))
+      .map(item => ({
+        userId: item.userId,
+        nickName: item.nickName
+      }));
+
 
   nextTick(() => {
     reportFormRef.value?.clearValidate();
@@ -1483,20 +1476,6 @@
       return;
     }
 
-    if (!reportForm.startTime || !reportForm.endTime) {
-      ElMessageBox.alert("寮�濮嬫椂闂村拰缁撴潫鏃堕棿涓嶈兘涓虹┖", "鎻愮ず", {
-        confirmButtonText: "纭畾",
-      });
-      return;
-    }
-
-    if (dayjs(reportForm.startTime).isSame(dayjs(reportForm.endTime)) || dayjs(reportForm.startTime).isAfter(dayjs(reportForm.endTime))) {
-      ElMessageBox.alert("寮�濮嬫椂闂村繀椤诲皬浜庣粨鏉熸椂闂�", "鎻愮ず", {
-        confirmButtonText: "纭畾",
-      });
-      return;
-    }
-
     const submitData = {
       ...reportForm,
       quantity: quantity,
@@ -1557,9 +1536,44 @@
   }
 }
 
-onMounted(() => {
-  ensureCurrentUser();
-  getList();
+const processData = ref([]);
+
+// 鏌ヨ鎵�鏈夊伐搴�
+const processLists = async () => {
+  console.log(processData.value)
+  if (processData.value.length > 0) {
+    return processData.value;
+  }
+  const res = await processList();
+
+  processData.value = Array.isArray(res?.data) ? res.data : [];
+  return processData.value;
+};
+
+// 鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁鑳芥帓浜�
+const canScheduleByWorkOrderNo = (row) => {
+  if (!row) return false;
+
+  const uid = String(currentUserId.value || "");
+  if (!uid) return false;
+
+  const currentProcess = processData.value.find(item =>
+      String(item.id) === String(row.processId)
+  );
+
+  if (!currentProcess) return false;
+
+  const ids = normalizeArray(currentProcess.userIds)
+      .map(id => String(id).trim())
+      .filter(Boolean);
+
+  return ids.includes(uid);
+};
+
+onMounted(async () => {
+  await ensureCurrentUser();
+  await processLists();
+  await getList();
   getUserList();
   getDeviceList();
 });

--
Gitblit v1.9.3