From aabc85a2c5187837da4fb8d415439b933f231abf Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 07 七月 2026 16:50:38 +0800
Subject: [PATCH] 排班:离职后不可以点击排班

---
 src/views/personnelManagement/classsSheduling/index.vue |  121 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 117 insertions(+), 4 deletions(-)

diff --git a/src/views/personnelManagement/classsSheduling/index.vue b/src/views/personnelManagement/classsSheduling/index.vue
index 8228be9..59e65b4 100644
--- a/src/views/personnelManagement/classsSheduling/index.vue
+++ b/src/views/personnelManagement/classsSheduling/index.vue
@@ -142,7 +142,8 @@
                      :key="'d' + i">
                   <el-dropdown trigger="click"
                                placement="bottom"
-                               @command="(e) => handleCommand(e, m)"
+                               :disabled="isCellBlockedByLeaveDate(item, m)"
+                               @command="(e) => handleCommand(e, item, m)"
                                class="shift-dropdown">
                     <div class="shift-box"
                          :class="{
@@ -354,6 +355,7 @@
     update,
     staffOnJobListPage,
   } from "@/api/personnelManagement/class";
+  import { findStaffLeaveListPage } from "@/api/personnelManagement/staffLeave.js";
   import { deptTreeSelect } from "@/api/system/user.js";
   import { getAttendanceRules } from "@/api/personnelManagement/attendanceRules.js";
   import { useDict } from "@/utils/dict";
@@ -403,6 +405,7 @@
   // 浜哄憳鍒楄〃
   const personList = ref([]);
   const personListAll = ref([]);
+  const leaveDateMap = ref({});
 
   // 鍔犺浇鐘舵��
   const loading = ref(false);
@@ -657,6 +660,15 @@
       proxy.$modal.msgError("璇烽�夋嫨鐝");
       return;
     }
+    const blockedEmployees = (personList.value || []).filter(item => {
+      const leaveDate = getEmployeeLeaveDate(item?.id);
+      const weekEndDate = getSchedulingWeekEndDate();
+      return leaveDate && weekEndDate && weekEndDate.getTime() > leaveDate.getTime();
+    });
+    if (blockedEmployees.length) {
+      proxy.$modal.msgError("瀛樺湪宸茶秴杩囩鑱屾棩鏈熺殑浜哄憳锛屼笉鑳界户缁帓鐝�");
+      return;
+    }
     loading.value = true;
     add({
       startWeek,
@@ -732,10 +744,14 @@
       });
   };
   // 澶勭悊鍛戒护
-  const handleCommand = (e, m) => {
+  const handleCommand = (e, row, cell) => {
+    if (isCellBlockedByLeaveDate(row, cell)) {
+      proxy.$modal.msgError("璇ュ憳宸ュ凡瓒呭嚭绂昏亴鏃ユ湡锛屼笉鑳界户缁帓鐝�");
+      return;
+    }
     // if (e != m.shift) {
     update({
-      id: m.id,
+      id: cell.id,
       personalAttendanceLocationConfigId: e,
     }).then(res => {
       proxy.$modal.msgSuccess("鎿嶄綔鎴愬姛");
@@ -782,6 +798,29 @@
     });
   };
 
+  const getLeaveDates = () => {
+    findStaffLeaveListPage({
+      current: -1,
+      size: -1,
+    }).then(res => {
+      const records = Array.isArray(res?.data?.records) ? res.data.records : [];
+      const map = {};
+      records.forEach(item => {
+        const staffId = item?.staffOnJobId ?? item?.staff_on_job_id;
+        const leaveDate = item?.leaveDate ?? item?.leave_date;
+        if (!staffId || !leaveDate) return;
+        const key = String(staffId);
+        const prev = map[key];
+        if (!prev || String(leaveDate) > String(prev)) {
+          map[key] = leaveDate;
+        }
+      });
+      leaveDateMap.value = map;
+      updatePersonListByDept();
+      syncPersonListSelection();
+    });
+  };
+
   const findDeptNodeById = (deptId, deptList = deptOptions.value) => {
     const list = Array.isArray(deptList) ? deptList : [];
     for (const node of list) {
@@ -815,8 +854,63 @@
     const deptIds = new Set(collectDeptIds(node));
     personList.value = (personListAll.value || []).filter(item => {
       const itemDeptId = item.deptId ?? item.sysDeptId ?? item.dept_id;
-      return deptIds.has(String(itemDeptId));
+      return deptIds.has(String(itemDeptId)) && !isEmployeeBlockedByLeaveDate(item);
     });
+  };
+
+  const parseDateOnly = value => {
+    if (!value) return null;
+    if (value instanceof Date) {
+      const d = new Date(value);
+      d.setHours(0, 0, 0, 0);
+      return d;
+    }
+    const normalized = String(value).trim().slice(0, 10);
+    if (!normalized) return null;
+    const d = new Date(normalized.replace(/-/g, "/"));
+    if (Number.isNaN(d.getTime())) return null;
+    d.setHours(0, 0, 0, 0);
+    return d;
+  };
+
+  const getSchedulingWeekEndDate = () => {
+    if (!schedulingQuery.week) return null;
+    const start = new Date(schedulingQuery.week);
+    start.setHours(0, 0, 0, 0);
+    return new Date(start.getTime() + 24 * 60 * 60 * 1000 * 5);
+  };
+
+  const getCellDate = cell => parseDateOnly(cell?.time);
+
+  const getEmployeeLeaveDate = staffId => {
+    const leaveDate = leaveDateMap.value[String(staffId)];
+    return parseDateOnly(leaveDate);
+  };
+
+  const isEmployeeBlockedByLeaveDate = item => {
+    const leaveDate = getEmployeeLeaveDate(item?.id);
+    if (!leaveDate) return false;
+    const weekEndDate = getSchedulingWeekEndDate();
+    if (!weekEndDate) return false;
+    return weekEndDate.getTime() > leaveDate.getTime();
+  };
+
+  const isCellBlockedByLeaveDate = (row, cell) => {
+    const staffId = row?.userId ?? row?.user_id ?? row?.id;
+    const leaveDate = getEmployeeLeaveDate(staffId);
+    const cellDate = getCellDate(cell);
+    if (!leaveDate || !cellDate) return false;
+    return cellDate.getTime() > leaveDate.getTime();
+  };
+
+  const syncPersonListSelection = () => {
+    if (!Array.isArray(schedulingQuery.userId) || !schedulingQuery.userId.length) return;
+    const validIds = new Set((personList.value || []).map(item => String(item.id)));
+    const nextIds = schedulingQuery.userId.filter(id => validIds.has(String(id)));
+    if (nextIds.length !== schedulingQuery.userId.length) {
+      schedulingQuery.userId = nextIds;
+      proxy.$modal.msgWarning("宸茶嚜鍔ㄥ墧闄よ秴鍑虹鑱屾棩鏈熺殑浜哄憳");
+    }
   };
 
   const setDefaultShiftByDept = () => {
@@ -855,6 +949,7 @@
   onMounted(() => {
     fetchData();
     getUsers();
+    getLeaveDates();
     fetchDeptOptions();
     if (query.month) {
       init();
@@ -878,6 +973,24 @@
   );
 
   watch(
+    () => schedulingQuery.week,
+    () => {
+      if (!schedulingVisible.value) return;
+      updatePersonListByDept();
+      syncPersonListSelection();
+    }
+  );
+
+  watch(
+    () => schedulingQuery.deptId,
+    () => {
+      if (!schedulingVisible.value) return;
+      updatePersonListByDept();
+      syncPersonListSelection();
+    }
+  );
+
+  watch(
     () => schedulingVisible.value,
     val => {
       if (!val) return;

--
Gitblit v1.9.3