ZN
4 天以前 b461c6527e3a85e9af59e7680e792bcb5ffb6b7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<template>
  <FormDialog
    v-model="dialogVisible"
    title="工资审核"
    width="900px"
    @close="handleClose"
  >
    <!-- 工资表基础信息 -->
    <el-card shadow="never" style="margin-bottom: 16px;">
      <template #header>
        <span>工资表信息</span>
      </template>
      <el-descriptions :column="3" border>
        <el-descriptions-item label="工资主题">{{ auditData?.salaryTitle || '-' }}</el-descriptions-item>
        <el-descriptions-item label="工资月份">{{ auditData?.salaryMonth || '-' }}</el-descriptions-item>
        <el-descriptions-item label="工资总额">¥ {{ formatMoney(auditData?.totalSalary) }}</el-descriptions-item>
        <el-descriptions-item label="支付银行">{{ auditData?.payBank || '-' }}</el-descriptions-item>
        <el-descriptions-item label="审核人">{{ auditData?.auditUserName || '-' }}</el-descriptions-item>
        <el-descriptions-item label="备注">{{ auditData?.remark || '-' }}</el-descriptions-item>
      </el-descriptions>
    </el-card>
 
    <!-- 员工工资明细 -->
      <el-card shadow="never" style="margin-bottom: 16px;">
        <template #header>
          <span>员工工资明细</span>
        </template>
        <div v-if="!employeeList || employeeList.length === 0" style="text-align: center; padding: 20px; color: #909399;">
          <div>暂无员工工资明细数据</div>
          <div style="font-size: 12px; margin-top: 5px;">员工明细数据需要在工资表生成或编辑时才会保存</div>
        </div>
        <div v-else>
          <el-table :data="employeeList" border max-height="300" style="width: 100%">
            <el-table-column prop="staffName" label="员工姓名" width="100" />
            <el-table-column prop="deptName" label="部门" width="120" />
            <el-table-column prop="basicSalary" label="基本工资" width="100" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.basicSalary) }}</template>
            </el-table-column>
            <el-table-column prop="pieceSalary" label="计件工资" width="100" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.pieceSalary) }}</template>
            </el-table-column>
            <el-table-column prop="hourlySalary" label="计时工资" width="100" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.hourlySalary) }}</template>
            </el-table-column>
            <el-table-column prop="otherIncome" label="其他收入" width="100" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.otherIncome) }}</template>
            </el-table-column>
            <el-table-column prop="socialPersonal" label="社保个人" width="100" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.socialPersonal) }}</template>
            </el-table-column>
            <el-table-column prop="fundPersonal" label="公积金个人" width="120" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.fundPersonal) }}</template>
            </el-table-column>
            <el-table-column prop="salaryTax" label="工资个税" width="100" align="right">
              <template #default="{ row }">¥ {{ formatMoney(row.salaryTax) }}</template>
            </el-table-column>
            <el-table-column prop="netSalary" label="实发工资" width="100" align="right" fixed="right">
              <template #default="{ row }">¥ {{ formatMoney(row.netSalary) }}</template>
            </el-table-column>
          </el-table>
          <div style="margin-top: 10px; text-align: right; font-weight: bold;">
            工资总额:¥ {{ formatMoney(totalSalary) }}
          </div>
        </div>
      </el-card>
 
    <!-- 审核操作 -->
    <el-form label-position="top">
      <el-form-item label="审核结果" required>
        <el-radio-group v-model="auditResult">
          <el-radio :value="4">通过</el-radio>
          <el-radio :value="2">不通过</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
 
    <template #footer>
      <el-button type="primary" :loading="loading" @click="handleConfirm">
        确定
      </el-button>
       <el-button @click="handleClose">取消</el-button>
    </template>
  </FormDialog>
</template>
 
<script setup>
import { ref, computed, reactive, toRefs, getCurrentInstance, watch } from "vue";
import { ElMessage } from "element-plus";
import Cookies from "js-cookie";
import FormDialog from "@/components/Dialog/FormDialog.vue";
import { staffSalaryMainUpdate } from "@/api/personnelManagement/staffSalaryMain.js";
 
const emit = defineEmits(["update:modelValue", "close", "success"]);
 
const props = defineProps({
  modelValue: { type: Boolean, default: false },
  row: { type: Object, default: () => ({}) },
});
 
const { proxy } = getCurrentInstance();
 
const dialogVisible = computed({
  get: () => props.modelValue,
  set: (val) => emit("update:modelValue", val),
});
 
const loading = ref(false);
const auditResult = ref(4); // 默认通过
const auditData = ref({});
const employeeList = ref([]);
 
// 监听row数据变化
watch(() => props.row, (newRow) => {
  if (newRow && Object.keys(newRow).length > 0) {
    loadAuditData(newRow);
  }
}, { immediate: true });
 
// 格式化金额
const formatMoney = (value) => {
  const num = Number(value) || 0;
  return num.toFixed(2);
};
 
// 计算工资总额
const totalSalary = computed(() => {
  return employeeList.value.reduce((sum, e) => {
    const salary = Number(e.netSalary) || 0;
    return sum + salary;
  }, 0);
});
 
// 加载审核数据
const loadAuditData = (row) => {
  auditData.value = row || {};
  auditResult.value = 4; // 默认选择通过
  
  // 加载员工工资明细数据
  if (row?.staffSalaryDetailList && Array.isArray(row.staffSalaryDetailList)) {
    employeeList.value = row.staffSalaryDetailList.map((e) => ({
      staffName: e.staffName ?? "",
      deptName: e.deptName ?? "",
      basicSalary: Number(e.basicSalary) || 0,
      pieceSalary: Number(e.pieceSalary) || 0,
      hourlySalary: Number(e.hourlySalary) || 0,
      otherIncome: Number(e.otherIncome) || 0,
      socialPersonal: Number(e.socialPersonal) || 0,
      fundPersonal: Number(e.fundPersonal) || 0,
      salaryTax: Number(e.salaryTax) || 0,
      netSalary: Number(e.netSalary) || 0,
    }));
  } else {
    console.log('没有找到员工明细数据');
    employeeList.value = [];
  }
};
 
// 打开弹窗
const openDialog = (row) => {
  loadAuditData(row);
  dialogVisible.value = true;
};
 
// 关闭弹窗
const handleClose = () => {
  dialogVisible.value = false;
  emit("close");
};
 
// 确认审核
const handleConfirm = () => {
  try {
    const row = auditData.value;
    if (!row?.id) {
      ElMessage.warning("数据异常,请重试");
      return;
    }
    
    const username = Cookies.get("username") || "";
    const userIdRaw = Cookies.get("userId");
    const auditUserId = userIdRaw ? Number(userIdRaw) : undefined;
    
    // 构建审核数据
    const submitData = {
      id: row.id,
      status: Number(auditResult.value) === 2 ? 2 : 4, // 2=不通过 4=通过(待发放)
      auditUserId,
      auditUserName: username,
    };
    loading.value = true;
    staffSalaryMainUpdate(submitData)
      .then(() => {
        ElMessage.success("审核成功");
        dialogVisible.value = false;
        emit("success");
      })
      .catch((error) => {
        console.error('审核失败:', error)
      })
      .finally(() => {
        loading.value = false;
      });
  } catch (error) {
    console.error('审核处理异常:', error);
    loading.value = false;
  }
};
 
defineExpose({ openDialog });
</script>
 
<style scoped>
:deep(.el-descriptions__label) {
  width: 100px;
}
</style>