From b461c6527e3a85e9af59e7680e792bcb5ffb6b7e Mon Sep 17 00:00:00 2001
From: ZN <zhang_12370@163.com>
Date: 星期二, 10 三月 2026 15:53:37 +0800
Subject: [PATCH] Merge branch 'dev_New' of http://114.132.189.42:9002/r/product-inventory-management into dev_New

---
 src/views/personnelManagement/monthlyStatistics/components/formDia.vue | 1056 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 771 insertions(+), 285 deletions(-)

diff --git a/src/views/personnelManagement/monthlyStatistics/components/formDia.vue b/src/views/personnelManagement/monthlyStatistics/components/formDia.vue
index c67fdd6..36c2ec3 100644
--- a/src/views/personnelManagement/monthlyStatistics/components/formDia.vue
+++ b/src/views/personnelManagement/monthlyStatistics/components/formDia.vue
@@ -1,318 +1,804 @@
 <template>
-  <el-dialog v-model="dialogVisible"
-             :title="title"
-             width="700px"
-             :close-on-click-modal="false">
-    <el-form ref="formRef"
-             :model="form"
-             :rules="rules"
-             label-width="140px"
-             label-position="top">
-      <el-row :gutter="20">
-        <el-col :span="12">
-          <el-form-item label="缁熻鏈堜唤"
-                        prop="payDate">
-            <el-date-picker v-model="form.payDate"
-                            type="month"
-                            value-format="YYYY-MM"
-                            format="YYYY-MM"
-                            placeholder="璇烽�夋嫨鏈堜唤"
-                            style="width: 100%"
-                            :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="濮撳悕"
-                        prop="staffId">
-            <el-select v-model="form.staffId"
-                       placeholder="璇烽�夋嫨鍛樺伐"
-                       style="width: 100%"
-                       :disabled="operationType === 'view'">
-              <el-option v-for="item in userList"
-                         :key="item.id"
-                         :label="item.staffName"
-                         :value="item.id" />
-            </el-select>
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row :gutter="20">
-        <el-col :span="12">
-          <el-form-item label="鍩烘湰宸ヨ祫"
-                        prop="basicSalary">
-            <el-input v-model="form.basicSalary"
-                      type="number"
-                      placeholder="璇疯緭鍏ュ熀鏈伐璧�"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="璁′欢宸ヨ祫"
-                        prop="pieceworkSalary">
-            <el-input v-model="form.pieceworkSalary"
-                      type="number"
-                      placeholder="璇疯緭鍏ヨ浠跺伐璧�"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row :gutter="20">
-        <el-col :span="12">
-          <el-form-item label="璁℃椂宸ヨ祫"
-                        prop="hourlySalary">
-            <el-input v-model="form.hourlySalary"
-                      type="number"
-                      placeholder="璇疯緭鍏ヨ鏃跺伐璧�"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="鍏朵粬鏀跺叆"
-                        prop="otherIncome">
-            <el-input v-model="form.otherIncome"
-                      type="number"
-                      placeholder="璇疯緭鍏ュ叾浠栨敹鍏�"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row :gutter="20">
-        <el-col :span="12">
-          <el-form-item label="绀句繚涓汉"
-                        prop="socialSecurityIndividuals">
-            <el-input v-model="form.socialSecurityIndividuals"
-                      type="number"
-                      placeholder="璇疯緭鍏ョぞ淇濅釜浜�"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="鍏Н閲戜釜浜�"
-                        prop="providentFundIndividuals">
-            <el-input v-model="form.providentFundIndividuals"
-                      type="number"
-                      placeholder="璇疯緭鍏ュ叕绉噾涓汉"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row :gutter="20">
-        <el-col :span="12">
-          <el-form-item label="涓汉鎵�寰楃◣"
-                        prop="personalIncomeTax">
-            <el-input v-model="form.personalIncomeTax"
-                      type="number"
-                      placeholder="璇疯緭鍏ヤ釜浜烘墍寰楃◣"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="鍏朵粬鎵f"
-                        prop="otherDeductions">
-            <el-input v-model="form.otherDeductions"
-                      type="number"
-                      placeholder="璇疯緭鍏ュ叾浠栨墸娆�"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-      </el-row>
-      <el-row :gutter="20">
-        <el-col :span="24">
-          <el-form-item label="澶囨敞"
-                        prop="remark">
-            <el-input v-model="form.remark"
-                      type="textarea"
-                      placeholder="璇疯緭鍏ュ娉�"
-                      :rows="3"
-                      :disabled="operationType === 'view'" />
-          </el-form-item>
-        </el-col>
-      </el-row>
-    </el-form>
+  <FormDialog
+    v-model="dialogVisible"
+    :title="operationType === 'add' ? '鏂板缓宸ヨ祫琛�' : '缂栬緫宸ヨ祫琛�'"
+    width="90%"
+    @close="closeDia"
+  >
     <template #footer>
-      <span class="dialog-footer">
-        <el-button @click="dialogVisible = false">鍙栨秷</el-button>
-        <el-button type="primary"
-                   @click="submitForm"
-                   v-if="operationType !== 'view'">
-          纭畾
-        </el-button>
-      </span>
+      <el-button type="info" @click="saveDraft">淇濆瓨鑽夌</el-button>
+      <el-button type="primary" @click="submitForm">纭鎻愪氦</el-button>
+      <el-button @click="closeDia">鍙栨秷</el-button>
     </template>
-  </el-dialog>
+    <div class="form-dia-body">
+      <!-- 鍩虹璧勬枡 -->
+      <el-card class="form-card" shadow="never">
+        <template #header>
+          <span class="card-title"><span class="card-title-line">|</span> 鍩虹璧勬枡</span>
+          <el-icon class="card-collapse"><ArrowUp /></el-icon>
+        </template>
+        <el-form ref="formRef" :model="form" :rules="rules" label-position="top">
+          <el-row :gutter="24">
+            <el-col :span="6">
+              <el-form-item label="宸ヨ祫涓婚" prop="salaryTitle">
+                <el-input
+                  v-model="form.salaryTitle"
+                  placeholder="璇疯緭鍏�"
+                  clearable
+                  maxlength="20"
+                  show-word-limit
+                />
+              </el-form-item>
+            </el-col>
+            <el-col :span="6">
+              <el-form-item label="閫夋嫨閮ㄩ棬" prop="deptIds">
+                <el-select
+                  v-model="form.deptIds"
+                  placeholder="璇烽�夋嫨"
+                  clearable
+                  multiple
+                  collapse-tags-tooltip
+                  style="width: 100%"
+                >
+                  <el-option
+                    v-for="item in deptOptions"
+                    :key="item.deptId"
+                    :label="item.deptName"
+                    :value="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">
+              <el-form-item label="澶囨敞" prop="remark">
+                <el-input
+                  v-model="form.remark"
+                  placeholder="璇疯緭鍏�"
+                  clearable
+                />
+              </el-form-item>
+            </el-col>
+          </el-row>
+          <el-row :gutter="24">
+            <el-col :span="6">
+              <el-form-item label="鏀粯閾惰" prop="payBank">
+                <el-select
+                  v-model="form.payBank"
+                  placeholder="璇烽�夋嫨"
+                  clearable
+                  filterable
+                  style="width: 100%"
+                >
+                  <el-option
+                    v-for="b in bankOptions"
+                    :key="b"
+                    :label="b"
+                    :value="b"
+                  />
+                </el-select>
+              </el-form-item>
+            </el-col>
+            <el-col :span="6">
+              <el-form-item label="瀹℃牳浜�" prop="auditUserId">
+                <el-select
+                  v-model="form.auditUserId"
+                  placeholder="璇烽�夋嫨瀹℃牳浜�"
+                  clearable
+                  filterable
+                  style="width: 100%"
+                >
+                  <el-option
+                    v-for="item in userList"
+                    :key="item.userId"
+                    :label="item.nickName"
+                    :value="item.userId"
+                  />
+                </el-select>
+              </el-form-item>
+            </el-col>
+          </el-row>
+        </el-form>
+      </el-card>
+
+      <!-- 鎿嶄綔鎸夐挳 -->
+      <div class="toolbar">
+        <el-button type="primary" @click="handleGenerate">鐢熸垚宸ヨ祫琛�</el-button>
+        <el-button @click="handleClear">娓呯┖</el-button>
+        <el-button @click="handleBatchDelete">鍒犻櫎</el-button>
+        <el-button @click="handleTaxForm">涓◣琛�</el-button>
+      </div>
+
+      <!-- 鍛樺伐宸ヨ祫璇︽儏琛ㄦ牸 -->
+      <div class="employee-table-wrap">
+        <el-table
+          ref="employeeTableRef"
+          :data="employeeList"
+          border
+          max-height="400"
+          @selection-change="onEmployeeSelectionChange"
+        >
+          <el-table-column type="selection" width="55" align="center" />
+          <el-table-column label="鍛樺伐濮撳悕" prop="staffName" minWidth="100" />
+          <el-table-column label="閮ㄩ棬" prop="deptName" minWidth="100" />
+          <el-table-column label="鍩烘湰宸ヨ祫" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.basicSalary"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.basicSalary = parseNum(row.basicSalary)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="璁′欢宸ヨ祫" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.pieceSalary"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.pieceSalary = parseNum(row.pieceSalary)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="璁℃椂宸ヨ祫" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.hourlySalary"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.hourlySalary = parseNum(row.hourlySalary)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="鍏朵粬鏀跺叆" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.otherIncome"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.otherIncome = parseNum(row.otherIncome)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="绀句繚涓汉" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.socialPersonal"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.socialPersonal = parseNum(row.socialPersonal)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="鍏Н閲戜釜浜�" minWidth="120">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.fundPersonal"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.fundPersonal = parseNum(row.fundPersonal)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="鍏朵粬鏀嚭" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.otherDeduct"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.otherDeduct = parseNum(row.otherDeduct)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="宸ヨ祫涓◣" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.salaryTax"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.salaryTax = parseNum(row.salaryTax)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="搴斿彂宸ヨ祫" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.grossSalary"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.grossSalary = parseNum(row.grossSalary)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="搴旀墸宸ヨ祫" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.deductSalary"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.deductSalary = parseNum(row.deductSalary)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="瀹炲彂宸ヨ祫" minWidth="110">
+            <template #default="{ row }">
+              <el-input
+                v-model.number="row.netSalary"
+                type="number"
+                placeholder="0"
+                size="small"
+                @input="row.netSalary = parseNum(row.netSalary)"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="澶囨敞" minWidth="120">
+            <template #default="{ row }">
+              <el-input
+                v-model="row.remark"
+                placeholder="璇疯緭鍏�"
+                size="small"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="鎿嶄綔" width="80" align="center" fixed="right">
+            <template #default="{ row }">
+              <el-button type="primary" link @click="removeEmployee(row)">鍒犻櫎</el-button>
+            </template>
+          </el-table-column>
+        </el-table>
+        <div v-if="!employeeList.length" class="table-empty">鏆傛棤鏁版嵁</div>
+        <div v-else class="salary-total">
+          <span class="total-label">宸ヨ祫鎬婚锛�</span>
+          <span class="total-value">楼 {{ totalSalary.toFixed(2) }}</span>
+        </div>
+      </div>
+    </div>
+
+
+
+    <!-- 鏂板浜哄憳寮圭獥 -->
+    <el-dialog
+      v-model="addPersonVisible"
+      title="鏂板浜哄憳"
+      width="400px"
+      append-to-body
+      @close="addPersonClose"
+    >
+      <div class="add-person-tree">
+        <el-tree
+          ref="personTreeRef"
+          :data="deptStaffTree"
+          show-checkbox
+          node-key="id"
+          :props="{ label: 'label', children: 'children' }"
+          default-expand-all
+        />
+      </div>
+      <template #footer>
+        <el-button @click="addPersonVisible = false">鍙栨秷</el-button>
+        <el-button type="primary" @click="confirmAddPerson">纭畾</el-button>
+      </template>
+    </el-dialog>
+
+    <!-- 涓◣琛ㄥ脊绐� -->
+    <el-dialog
+      v-model="taxDialogVisible"
+      title="涓◣琛�"
+      width="700px"
+      append-to-body
+    >
+      <div class="tax-desc">涓汉鎵�寰楃◣鍏嶅緛棰濓細5000鍏�</div>
+      <el-table :data="taxTableData" border style="width: 100%;margin-bottom: 20px;">
+        <el-table-column prop="level" label="绾ф暟" width="80" align="center" />
+        <el-table-column
+          prop="range"
+          label="鍏ㄥ勾搴旂撼绋庢墍寰楅/鍏�"
+          min-width="220"
+        />
+        <el-table-column
+          prop="rate"
+          label="绋庣巼(%)"
+          width="100"
+          align="center"
+        />
+        <el-table-column
+          prop="quickDeduction"
+          label="閫熺畻鎵i櫎鏁�/鍏�"
+          width="160"
+          align="center"
+        />
+      </el-table>
+    </el-dialog>
+  </FormDialog>
 </template>
 
 <script setup>
-  import { ref, reactive, computed, onMounted } from "vue";
-  import { ElMessage } from "element-plus";
-  import {
-    monthlyStatisticsAdd,
-    monthlyStatisticsUpdate,
-    staffOnJobList,
-  } from "@/api/personnelManagement/monthlyStatistics.js";
+import { ref, reactive, toRefs, computed, getCurrentInstance, nextTick } 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,
+} from "@/api/personnelManagement/staffSalaryMain.js";
+import { userListNoPageByTenantId } from "@/api/system/user.js";
 
-  const props = defineProps({
-    modelValue: {
-      type: Boolean,
-      default: false,
-    },
-    operationType: {
-      type: String,
-      default: "add",
-    },
-    row: {
-      type: Object,
-      default: () => ({}),
-    },
-  });
 
-  const emit = defineEmits(["update:modelValue", "close"]);
+const emit = defineEmits(["update:modelValue", "close"]);
+const props = defineProps({
+  modelValue: { type: Boolean, default: false },
+  operationType: { type: String, default: "add" },
+  row: { type: Object, default: () => ({}) },
+});
 
-  const dialogVisible = computed({
-    get: () => props.modelValue,
-    set: val => emit("update:modelValue", val),
-  });
+const { proxy } = getCurrentInstance();
 
-  const title = computed(() => {
-    if (props.operationType === "add") return "鏂板钖祫鍙拌处";
-    if (props.operationType === "edit") return "缂栬緫钖祫鍙拌处";
-    return "鏌ョ湅钖祫鍙拌处";
-  });
+const dialogVisible = computed({
+  get: () => props.modelValue,
+  set: (val) => emit("update:modelValue", val),
+});
 
-  const formRef = ref();
-  const form = reactive({
-    id: "",
-    payDate: "",
-    staffId: "",
-    basicSalary: 0,
-    pieceworkSalary: 0,
-    hourlySalary: 0,
-    otherIncome: 0,
-    socialSecurityIndividuals: 0,
-    providentFundIndividuals: 0,
-    personalIncomeTax: 0,
-    otherDeductions: 0,
-    payableWages: 0,
-    deductibleWages: 0,
-    actualWages: 0,
+const formRef = ref(null);
+const employeeTableRef = ref(null);
+const personTreeRef = ref(null);
+const addPersonVisible = ref(false);
+const taxDialogVisible = ref(false);
+const deptOptions = ref([]);
+const deptStaffTree = ref([]);
+const employeeList = ref([]);
+const selectedEmployees = ref([]);
+const bankOptions = ref([]);
+const userList = ref([]);
+const taxTableData = ref([
+  { level: 1, range: "涓嶈秴杩�36000鍏�", rate: 3, quickDeduction: 0 },
+  { level: 2, range: "瓒呰繃36000-144000鍏�", rate: 10, quickDeduction: 2520 },
+  { level: 3, range: "瓒呰繃144000-300000鍏�", rate: 20, quickDeduction: 16920 },
+  { level: 4, range: "瓒呰繃300000-420000鍏�", rate: 25, quickDeduction: 31920 },
+  { level: 5, range: "瓒呰繃420000-660000鍏�", rate: 30, quickDeduction: 52920 },
+  { level: 6, range: "瓒呰繃660000-960000鍏�", rate: 35, quickDeduction: 85920 },
+  { level: 7, range: "瓒呰繃960000鍏�", rate: 45, quickDeduction: 181920 },
+]);
+
+function parseNum(v) {
+  if (v === "" || v == null) return 0;
+  const n = Number(v);
+  return isNaN(n) ? 0 : n;
+}
+
+// 鍩虹璧勬枡琛ㄥ崟
+const data = reactive({
+  form: {
+    id: undefined,
+    salaryTitle: "",
+    deptIds: [],
+    salaryMonth: "",
     remark: "",
+    payBank: "",
+    auditUserId: undefined,
+  },
+  rules: {
+    salaryTitle: [{ required: true, message: "璇疯緭鍏ュ伐璧勪富棰�", trigger: "blur" }],
+    deptIds: [{ required: true, message: "璇烽�夋嫨閮ㄩ棬", trigger: "change" }],
+    salaryMonth: [{ required: true, message: "璇烽�夋嫨宸ヨ祫鏈堜唤", trigger: "change" }],
+    auditUserId: [{ required: true, message: "璇烽�夋嫨瀹℃牳浜�", trigger: "change" }],
+  },
+});
+const { form, rules } = toRefs(data);
+
+// 璁$畻宸ヨ祫鎬婚锛堟墍鏈夊憳宸ュ疄鍙戝伐璧勪箣鍜岋級
+const totalSalary = computed(() => {
+  return employeeList.value.reduce((sum, e) => sum + parseNum(e.netSalary), 0);
+});
+
+// 鏍规嵁瀹℃牳浜篒D鑾峰彇瀹℃牳浜哄悕绉�
+const auditUserName = computed(() => {
+  if (!form.value.auditUserId) return "";
+  const user = userList.value.find(u => u.userId === form.value.auditUserId);
+  return user ? user.nickName : "";
+});
+
+const loadBankOptions = () => {
+  return bankList().then((res) => {
+    const list = Array.isArray(res?.data) ? res.data : [];
+    bankOptions.value = list
+      .map((b) => (b?.bankName == null ? "" : String(b.bankName).trim()))
+      .filter((v) => v !== "");
   });
+};
 
-  const rules = {
-    payDate: [{ required: true, message: "璇烽�夋嫨缁熻鏈堜唤", trigger: "change" }],
-    staffId: [{ required: true, message: "璇烽�夋嫨鍛樺伐", trigger: "change" }],
-    basicSalary: [{ required: true, message: "璇疯緭鍏ュ熀鏈伐璧�", trigger: "blur" }],
-  };
+const loadUserList = () => {
+  return userListNoPageByTenantId().then((res) => {
+    userList.value = res.data || [];
+  });
+};
 
-  const userList = ref([]);
+// 鎵佸钩鍖栭儴闂ㄦ爲渚涗笅鎷変娇鐢�
+function flattenDept(tree, list = []) {
+  if (!tree?.length) return list;
+  tree.forEach((node) => {
+    list.push({ deptId: node.deptId, deptName: node.deptName });
+    if (node.children?.length) flattenDept(node.children, list);
+  });
+  return list;
+}
 
-  const loadUserList = () => {
-    // userListNoPage().then(res => {
-    //   userList.value = res.data || [];
-    // });
-    staffOnJobList().then(res => {
-      userList.value = res.data || [];
+const loadDeptOptions = () => {
+  listDept().then((res) => {
+    const tree = res.data ?? [];
+    deptOptions.value = flattenDept(tree);
+  });
+};
+
+// 鏋勫缓 閮ㄩ棬-浜哄憳 鏍戯紙鐢ㄤ簬鏂板浜哄憳寮圭獥锛�
+const loadDeptStaffTree = () => {
+  Promise.all([listDept(), staffOnJobList()]).then(([deptRes, staffRes]) => {
+    const tree = deptRes.data ?? [];
+    const staffList = staffRes.data ?? [];
+    const deptMap = new Map();
+    function walk(nodes) {
+      nodes.forEach((node) => {
+        deptMap.set(node.deptId, {
+          id: "dept_" + node.deptId,
+          deptId: node.deptId,
+          label: node.deptName,
+          type: "dept",
+          children: [],
+        });
+        if (node.children?.length) walk(node.children);
+      });
+    }
+    walk(tree);
+    staffList.forEach((s) => {
+      const deptId = s.deptId ?? s.dept_id;
+      const node = deptMap.get(deptId);
+      if (node) {
+        node.children.push({
+          id: s.id ?? s.staffId,
+          staffId: s.id ?? s.staffId,
+          label: s.staffName ?? s.name,
+          type: "staff",
+          ...s,
+        });
+      }
     });
-  };
+    deptStaffTree.value = Array.from(deptMap.values()).filter(
+      (n) => n.children && n.children.length > 0
+    );
+  });
+};
 
-  const openDialog = (type, row) => {
-    // 閲嶇疆琛ㄥ崟
-    Object.assign(form, {
-      id: "",
-      payDate: "",
-      staffId: "",
-      basicSalary: 0,
-      pieceworkSalary: 0,
-      hourlySalary: 0,
-      otherIncome: 0,
-      socialSecurityIndividuals: 0,
-      providentFundIndividuals: 0,
-      personalIncomeTax: 0,
-      otherDeductions: 0,
-      payableWages: 0,
-      deductibleWages: 0,
-      actualWages: 0,
+const openDialog = (type, row) => {
+  nextTick(() => {
+    loadDeptOptions();
+    loadBankOptions();
+    loadUserList();
+    employeeList.value = [];
+    Object.assign(form.value, {
+      id: undefined,
+      salaryTitle: "",
+      deptIds: [],
+      salaryMonth: "",
       remark: "",
+      payBank: "",
+      auditUserId: undefined,
     });
-
-    if (type === "add") {
-      dialogVisible.value = true;
-    } else if (type === "edit" || type === "view") {
-      if (row && row.id) {
-        Object.assign(form, row);
-        dialogVisible.value = true;
+    // 缂栬緫锛氬垪琛ㄩ〉宸茶繑鍥炰富琛ㄥ瓧娈碉紱杩欓噷鍙仛鍥炴樉锛堟槑缁嗙敱鈥滅敓鎴愬伐璧勮〃/璁$畻宸ヨ祫鈥濆緱鍒帮級
+    if (type === "edit" && row?.id) {
+      form.value.id = row.id;
+      form.value.salaryTitle = row.salaryTitle ?? "";
+      // deptIds 鍚庣鏄瓧绗︿覆锛堝涓敤閫楀彿鍒嗛殧锛夛紱褰撳墠琛ㄥ崟浠嶆槸鍗曢�� deptId
+      form.value.deptIds = row.deptIds
+        ? String(row.deptIds).split(",").map((id) => Number(id.trim())).filter(Boolean)
+        : [];
+      form.value.salaryMonth = row.salaryMonth ?? "";
+      form.value.remark = row.remark ?? "";
+      form.value.payBank = row.payBank ?? "";
+      form.value.auditUserId = row.auditUserId ?? undefined;
+      
+      // 濡傛灉鏈夊憳宸ユ槑缁嗘暟鎹紝鐩存帴鍙嶆樉
+      if (row.staffSalaryDetailList && row.staffSalaryDetailList.length > 0) {
+        employeeList.value = row.staffSalaryDetailList.map((e) => ({
+          staffOnJobId: e.staffOnJobId ?? e.staffId ?? e.id,
+          id: e.staffOnJobId ?? e.staffId ?? e.id,
+          staffName: e.staffName ?? "",
+          postName: e.postName ?? "",
+          deptName: e.deptName ?? "",
+          basicSalary: parseNum(e.basicSalary),
+          pieceSalary: parseNum(e.pieceSalary),
+          hourlySalary: parseNum(e.hourlySalary),
+          otherIncome: parseNum(e.otherIncome),
+          socialPersonal: parseNum(e.socialPersonal),
+          fundPersonal: parseNum(e.fundPersonal),
+          otherDeduct: parseNum(e.otherDeduct),
+          salaryTax: parseNum(e.salaryTax),
+          grossSalary: parseNum(e.grossSalary),
+          deductSalary: parseNum(e.deductSalary),
+          netSalary: parseNum(e.netSalary),
+          remark: e.remark ?? "",
+        }));
       }
     }
-  };
+  });
+};
 
-  const submitForm = () => {
-    formRef.value.validate(valid => {
-      if (valid) {
-        form.basicSalary = Number(form.basicSalary);
-        form.pieceworkSalary = Number(form.pieceworkSalary);
-        form.hourlySalary = Number(form.hourlySalary);
-        form.otherIncome = Number(form.otherIncome);
-        form.socialSecurityIndividuals = Number(form.socialSecurityIndividuals);
-        form.providentFundIndividuals = Number(form.providentFundIndividuals);
-        form.personalIncomeTax = Number(form.personalIncomeTax);
-        form.otherDeductions = Number(form.otherDeductions);
+const openAddPerson = () => {
+  loadDeptStaffTree();
+  addPersonVisible.value = true;
+  nextTick(() => {
+    personTreeRef.value?.setCheckedKeys([]);
+  });
+};
 
-        // 璁$畻搴斿彂宸ヨ祫銆佸簲鎵e伐璧勫拰瀹炲彂宸ヨ祫
-        const payableWages =
-          form.basicSalary +
-          form.pieceworkSalary +
-          form.hourlySalary +
-          form.otherIncome;
-        const deductibleWages =
-          form.socialSecurityIndividuals +
-          form.providentFundIndividuals +
-          form.personalIncomeTax +
-          form.otherDeductions;
-        const actualWages = payableWages - deductibleWages;
+const addPersonClose = () => {};
 
-        const submitData = {
-          ...form,
-          payableWages,
-          deductibleWages,
-          actualWages,
-        };
-
-        if (props.operationType === "add") {
-          monthlyStatisticsAdd(submitData).then(res => {
-            if (res.code === 200) {
-              ElMessage.success("鏂板鎴愬姛");
-              dialogVisible.value = false;
-              emit("close");
-            } else {
-              ElMessage.error(res.msg || "鏂板澶辫触");
-            }
-          });
-        } else if (props.operationType === "edit") {
-          monthlyStatisticsUpdate(submitData).then(res => {
-            if (res.code === 200) {
-              ElMessage.success("鏇存柊鎴愬姛");
-              dialogVisible.value = false;
-              emit("close");
-            } else {
-              ElMessage.error(res.msg || "鏇存柊澶辫触");
-            }
-          });
-        }
-      }
+const confirmAddPerson = () => {
+  const tree = personTreeRef.value;
+  if (!tree) {
+    addPersonVisible.value = false;
+    return;
+  }
+  const checked = tree.getCheckedNodes();
+  const staffNodes = checked.filter((n) => n.type === "staff");
+  const existIds = new Set(employeeList.value.map((e) => e.staffId || e.id));
+  staffNodes.forEach((node) => {
+    const id = node.staffId ?? node.id;
+    if (existIds.has(id)) return;
+    existIds.add(id);
+    employeeList.value.push({
+      staffOnJobId: id,
+      id,
+      staffName: node.label,
+      postName: node.postName ?? node.post ?? "",
+      deptName: node.deptName ?? "",
+      basicSalary: 0,
+      pieceSalary: 0,
+      hourlySalary: 0,
+      otherIncome: 0,
+      socialPersonal: 0,
+      fundPersonal: 0,
+      otherDeduct: 0,
+      salaryTax: 0,
+      grossSalary: 0,
+      deductSalary: 0,
+      netSalary: 0,
+      remark: "",
     });
+  });
+  addPersonVisible.value = false;
+};
+
+const removeEmployee = (row) => {
+  employeeList.value = employeeList.value.filter(
+    (e) => (e.staffOnJobId || e.id) !== (row.staffOnJobId || row.id)
+  );
+};
+
+const onEmployeeSelectionChange = (selection) => {
+  selectedEmployees.value = selection;
+};
+
+const handleBatchDelete = () => {
+  if (!selectedEmployees.value?.length) {
+    proxy.$modal.msgWarning("璇峰厛鍕鹃�夎鍒犻櫎鐨勫憳宸�");
+    return;
+  }
+  const ids = new Set(selectedEmployees.value.map((e) => e.staffOnJobId || e.id));
+  employeeList.value = employeeList.value.filter(
+    (e) => !ids.has(e.staffOnJobId || e.id)
+  );
+};
+
+const handleGenerate = () => {
+  if (!form.value.deptIds?.length) {
+    proxy.$modal.msgWarning("璇峰厛閫夋嫨閮ㄩ棬");
+    return;
+  }
+  if (!form.value.salaryMonth) {
+    proxy.$modal.msgWarning("璇峰厛閫夋嫨宸ヨ祫鏈堜唤");
+    return;
+  }
+  const payload = {
+    ids: form.value.deptIds,
+    date: form.value.salaryMonth,
   };
-
-  onMounted(() => {
-    loadUserList();
+  staffSalaryMainCalculateSalary(payload).then((res) => {
+    const list = Array.isArray(res?.data) ? res.data : [];
+    if (!list.length) {
+      proxy.$modal.msgWarning("鏈绠楀埌宸ヨ祫鏁版嵁");
+      return;
+    }
+    employeeList.value = list.map((e) => ({
+      ...e,
+      staffOnJobId: e.staffOnJobId ?? e.staffId ?? e.id,
+      staffName: e.staffName,
+      postName: e.postName,
+      deptName: e.deptName,
+      basicSalary: parseNum(e.basicSalary),
+      pieceSalary: parseNum(e.pieceSalary),
+      hourlySalary: parseNum(e.hourlySalary),
+      otherIncome: parseNum(e.otherIncome),
+      socialPersonal: parseNum(e.socialPersonal),
+      fundPersonal: parseNum(e.fundPersonal),
+      otherDeduct: parseNum(e.otherDeduct),
+      salaryTax: parseNum(e.salaryTax),
+      grossSalary: parseNum(e.grossSalary),
+      deductSalary: parseNum(e.deductSalary),
+      netSalary: parseNum(e.netSalary),
+      remark: e.remark ?? "",
+    }));
+    proxy.$modal.msgSuccess("鐢熸垚鎴愬姛");
   });
+};
 
-  defineExpose({
-    openDialog,
+const handleClear = () => {
+  proxy.$modal.confirm("纭畾娓呯┖褰撳墠鍛樺伐鍒楄〃鍚楋紵").then(() => {
+    employeeList.value = [];
+  }).catch(() => {});
+};
+
+const handleTaxForm = () => {
+  taxDialogVisible.value = true;
+};
+
+const submitForm = () => {
+  formRef.value?.validate((valid) => {
+    if (!valid) return;
+    saveData(3); // 纭鎻愪氦锛岀姸鎬佷负3锛堝緟瀹℃牳锛�
   });
+};
+
+const saveDraft = () => {
+  formRef.value?.validate((valid) => {
+    if (!valid) return;
+    saveData(1); // 淇濆瓨鑽夌锛岀姸鎬佷负1锛堣崏绋匡級
+  });
+};
+
+const saveData = (status) => {
+  const payload = {
+    id: form.value.id,
+    salaryTitle: form.value.salaryTitle,
+    deptIds: form.value.deptIds?.length ? form.value.deptIds.join(",") : "",
+    salaryMonth: form.value.salaryMonth,
+    remark: form.value.remark,
+    payBank: form.value.payBank,
+    auditUserId: form.value.auditUserId,
+    auditUserName: auditUserName.value,
+    totalSalary: totalSalary.value,
+    staffSalaryDetailList: employeeList.value.map((e) => ({
+      staffOnJobId: e.staffOnJobId ?? e.staffId ?? e.id,
+      staffName: e.staffName,
+      postName: e.postName ?? "",
+      deptName: e.deptName ?? "",
+      basicSalary: parseNum(e.basicSalary),
+      pieceSalary: parseNum(e.pieceSalary),
+      hourlySalary: parseNum(e.hourlySalary),
+      otherIncome: parseNum(e.otherIncome),
+      socialPersonal: parseNum(e.socialPersonal),
+      fundPersonal: parseNum(e.fundPersonal),
+      otherDeduct: parseNum(e.otherDeduct),
+      salaryTax: parseNum(e.salaryTax),
+      grossSalary: parseNum(e.grossSalary),
+      deductSalary: parseNum(e.deductSalary),
+      netSalary: parseNum(e.netSalary),
+      remark: e.remark ?? "",
+    })),
+  };
+  if (props.operationType === "add") {
+    staffSalaryMainAdd({ ...payload, status }).then(() => {
+      proxy.$modal.msgSuccess(status === 1 ? "鑽夌淇濆瓨鎴愬姛" : "鎻愪氦鎴愬姛");
+      closeDia();
+    });
+  } else {
+    staffSalaryMainUpdate({ ...payload, status }).then(() => {
+      proxy.$modal.msgSuccess(status === 1 ? "鑽夌淇濆瓨鎴愬姛" : "鎻愪氦鎴愬姛");
+      closeDia();
+    });
+  }
+};
+
+const closeDia = () => {
+  dialogVisible.value = false;
+  emit("close");
+};
+
+defineExpose({ openDialog });
 </script>
 
 <style scoped>
-  .dialog-footer {
-    text-align: right;
-  }
-</style>
\ No newline at end of file
+.form-dia-body {
+  padding: 0;
+}
+.card-title-line {
+  color: #f56c6c;
+  margin-right: 4px;
+}
+.form-card {
+  margin-bottom: 16px;
+}
+.form-card :deep(.el-card__header) {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  padding: 12px 16px;
+}
+.card-title {
+  font-weight: 500;
+}
+.card-collapse {
+  color: #999;
+  cursor: pointer;
+}
+.toolbar {
+  margin-bottom: 16px;
+  display: flex;
+  flex-wrap: wrap;
+  gap: 10px;
+}
+.employee-table-wrap {
+  position: relative;
+  min-height: 120px;
+}
+.table-empty {
+  text-align: center;
+  padding: 24px;
+  color: #999;
+  font-size: 14px;
+}
+.add-person-tree {
+  max-height: 360px;
+  overflow-y: auto;
+  padding: 8px 0;
+}
+.tax-desc {
+  margin-bottom: 12px;
+  font-size: 14px;
+  color: #606266;
+}
+.dialog-footer {
+  text-align: right;
+}
+.salary-total {
+  margin-top: 16px;
+  padding: 12px 16px;
+  background-color: #f5f7fa;
+  border-radius: 4px;
+  text-align: right;
+  font-size: 16px;
+}
+.salary-total .total-label {
+  color: #606266;
+  margin-right: 8px;
+}
+.salary-total .total-value {
+  color: #f56c6c;
+  font-weight: bold;
+  font-size: 18px;
+}
+</style>

--
Gitblit v1.9.3