From c8e476f028d4d5cddffb4952f4f621652591ec48 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期一, 15 六月 2026 17:42:15 +0800
Subject: [PATCH] 人员薪资部门选项排除当月已发放工资表的部门

---
 src/api/personnelManagement/staffSalaryMain.js                         |    9 ++++
 src/views/personnelManagement/monthlyStatistics/components/formDia.vue |   84 ++++++++++++++++++++++++++++++-----------
 2 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/src/api/personnelManagement/staffSalaryMain.js b/src/api/personnelManagement/staffSalaryMain.js
index 08de85c..7ff6667 100644
--- a/src/api/personnelManagement/staffSalaryMain.js
+++ b/src/api/personnelManagement/staffSalaryMain.js
@@ -48,3 +48,12 @@
     data: ids,
   });
 }
+
+// 鑾峰彇鍙敤閮ㄩ棬鍒楄〃锛堟牴鎹湀浠芥煡璇紝鎺掗櫎宸插彂鏀惧伐璧勮〃鐨勯儴闂級
+export function staffSalaryMainAvailableDepts(salaryMonth) {
+  return request({
+    url: "/staffSalaryMain/availableDepts",
+    method: "get",
+    params: { salaryMonth },
+  });
+}
\ No newline at end of file
diff --git a/src/views/personnelManagement/monthlyStatistics/components/formDia.vue b/src/views/personnelManagement/monthlyStatistics/components/formDia.vue
index 808c817..7793d4a 100644
--- a/src/views/personnelManagement/monthlyStatistics/components/formDia.vue
+++ b/src/views/personnelManagement/monthlyStatistics/components/formDia.vue
@@ -36,6 +36,18 @@
               </el-form-item>
             </el-col>
             <el-col :span="6">
+              <el-form-item label="閫夋嫨宸ヨ祫鏈堜唤"
+                            prop="salaryMonth">
+                <el-date-picker v-model="form.salaryMonth"
+                                type="month"
+                                value-format="YYYY-MM"
+                                format="YYYY-MM"
+                                placeholder="璇烽�夋嫨宸ヨ祫鏈堜唤"
+                                style="width: 100%"
+                                clearable />
+              </el-form-item>
+            </el-col>
+            <el-col :span="6">
               <el-form-item label="閫夋嫨閮ㄩ棬"
                             prop="deptIds">
                 <el-select v-model="form.deptIds"
@@ -47,20 +59,9 @@
                   <el-option v-for="item in deptOptions"
                              :key="item.deptId"
                              :label="item.deptName"
-                             :value="item.deptId" />
+                             :value="item.deptId"
+                             :disabled="isDeptDisabled(item.deptId)" />
                 </el-select>
-              </el-form-item>
-            </el-col>
-            <el-col :span="6">
-              <el-form-item label="閫夋嫨宸ヨ祫鏈堜唤"
-                            prop="salaryMonth">
-                <el-date-picker v-model="form.salaryMonth"
-                                type="month"
-                                value-format="YYYY-MM"
-                                format="YYYY-MM"
-                                placeholder="璇烽�夋嫨宸ヨ祫鏈堜唤"
-                                style="width: 100%"
-                                clearable />
               </el-form-item>
             </el-col>
             <el-col :span="6">
@@ -344,18 +345,20 @@
     computed,
     getCurrentInstance,
     nextTick,
+    watch,
   } from "vue";
   import { ArrowUp } from "@element-plus/icons-vue";
   import FormDialog from "@/components/Dialog/FormDialog.vue";
   import { listDept } from "@/api/system/dept.js";
   import { staffOnJobList } from "@/api/personnelManagement/monthlyStatistics.js";
-  import { bankList } from "@/api/personnelManagement/bank.js";
-  import {
-    staffSalaryMainAdd,
-    staffSalaryMainUpdate,
-    staffSalaryMainCalculateSalary,
-    staffSalaryMainCalculateByEmployeeId,
-  } from "@/api/personnelManagement/staffSalaryMain.js";
+import { bankList } from "@/api/personnelManagement/bank.js";
+import {
+  staffSalaryMainAdd,
+  staffSalaryMainUpdate,
+  staffSalaryMainCalculateSalary,
+  staffSalaryMainCalculateByEmployeeId,
+  staffSalaryMainAvailableDepts,
+} from "@/api/personnelManagement/staffSalaryMain.js";
   import { userListNoPageByTenantId } from "@/api/system/user.js";
 
   const emit = defineEmits(["update:modelValue", "close"]);
@@ -378,6 +381,7 @@
   const addPersonVisible = ref(false);
   const taxDialogVisible = ref(false);
   const deptOptions = ref([]);
+  const availableDeptIds = ref(new Set());
   const deptStaffTree = ref([]);
   const employeeList = ref([]);
   const selectedEmployees = ref([]);
@@ -573,11 +577,32 @@
     return list;
   }
 
-  const loadDeptOptions = () => {
+  // 鍔犺浇鎵�鏈夐儴闂�
+  const loadAllDeptOptions = () => {
     listDept().then(res => {
       const tree = res.data ?? [];
       deptOptions.value = flattenDept(tree);
     });
+  };
+
+  // 鍔犺浇鍙敤閮ㄩ棬鍒楄〃锛堢敤浜庡垽鏂儴闂ㄦ槸鍚﹀彲閫夛級
+  const loadAvailableDepts = (salaryMonth) => {
+    if (!salaryMonth) {
+      availableDeptIds.value = new Set();
+      return;
+    }
+    staffSalaryMainAvailableDepts(salaryMonth).then(res => {
+      const availableDepts = Array.isArray(res.data) ? res.data : [];
+      availableDeptIds.value = new Set(availableDepts.map(d => d.deptId));
+    });
+  };
+
+  // 鍒ゆ柇閮ㄩ棬鏄惁绂佺敤
+  const isDeptDisabled = (deptId) => {
+    // 濡傛灉娌℃湁閫夋嫨鏈堜唤锛屾墍鏈夐儴闂ㄩ兘鍙��
+    if (!form.value.salaryMonth) return false;
+    // 濡傛灉宸查�夋嫨鏈堜唤锛屽彧鏈夊湪鍙敤閮ㄩ棬鍒楄〃涓殑閮ㄩ棬鎵嶅彲閫�
+    return !availableDeptIds.value.has(deptId);
   };
 
   // 鏋勫缓 閮ㄩ棬-浜哄憳 鏍戯紙鐢ㄤ簬鏂板浜哄憳寮圭獥锛�
@@ -621,9 +646,9 @@
   const openDialog = (type, row) => {
     nextTick(() => {
       resetRecalcState();
-      loadDeptOptions();
       loadBankOptions();
       loadUserList();
+      loadAllDeptOptions();
       employeeList.value = [];
       Object.assign(form.value, {
         id: undefined,
@@ -655,8 +680,21 @@
           employeeList.value = row.staffSalaryDetailList.map(e => normalizeEmployeeRow(e));
         }
       }
+      // 缂栬緫鐘舵�佷笖鏈夋湀浠芥椂锛屽姞杞藉彲鐢ㄩ儴闂ㄥ垪琛�
+      if (type === "edit" && form.value.salaryMonth) {
+        loadAvailableDepts(form.value.salaryMonth);
+      }
     });
   };
+
+  // 鐩戝惉宸ヨ祫鏈堜唤鍙樺寲锛屾竻绌洪儴闂ㄩ�夋嫨骞跺姞杞藉彲鐢ㄩ儴闂ㄥ垪琛�
+  watch(() => form.value.salaryMonth, (newMonth, oldMonth) => {
+    // 鍒囨崲鏈堜唤鏃舵竻绌哄凡閫夋嫨鐨勯儴闂�
+    if (newMonth !== oldMonth) {
+      form.value.deptIds = [];
+    }
+    loadAvailableDepts(newMonth);
+  });
 
   const openAddPerson = () => {
     loadDeptStaffTree();
@@ -895,4 +933,4 @@
     font-weight: bold;
     font-size: 18px;
   }
-</style>
+</style>
\ No newline at end of file

--
Gitblit v1.9.3