<template>
|
<view class="hazard-source-detail">
|
<PageHeader :title="isEdit ? '编辑薪资台账' : '新增薪资台账'"
|
@back="goBack" />
|
<u-form @submit="handleSubmit"
|
ref="formRef"
|
label-width="110">
|
<!-- 薪资信息 -->
|
<u-cell-group title="薪资信息">
|
<u-form-item label="统计月份"
|
prop="payDate"
|
required
|
border-bottom>
|
<u-input v-model="form.payDate"
|
placeholder="请选择月份"
|
@click="showDatePicker"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showDatePicker"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="员工姓名"
|
prop="staffId"
|
required
|
border-bottom>
|
<u-input v-model="form.staffName"
|
placeholder="请选择员工"
|
@click="showStaffSheet"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showStaffSheet"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="基本工资"
|
prop="basicSalary"
|
required
|
border-bottom>
|
<u-input v-model="form.basicSalary"
|
type="number"
|
placeholder="请输入基本工资" />
|
</u-form-item>
|
<u-form-item label="计件工资"
|
prop="pieceworkSalary"
|
border-bottom>
|
<u-input v-model="form.pieceworkSalary"
|
type="number"
|
placeholder="请输入计件工资" />
|
</u-form-item>
|
<u-form-item label="计时工资"
|
prop="hourlySalary"
|
border-bottom>
|
<u-input v-model="form.hourlySalary"
|
type="number"
|
placeholder="请输入计时工资" />
|
</u-form-item>
|
<u-form-item label="其他收入"
|
prop="otherIncome"
|
border-bottom>
|
<u-input v-model="form.otherIncome"
|
type="number"
|
placeholder="请输入其他收入" />
|
</u-form-item>
|
<u-form-item label="社保个人"
|
prop="socialSecurityIndividuals"
|
border-bottom>
|
<u-input v-model="form.socialSecurityIndividuals"
|
type="number"
|
placeholder="请输入社保个人" />
|
</u-form-item>
|
<u-form-item label="公积金个人"
|
prop="providentFundIndividuals"
|
border-bottom>
|
<u-input v-model="form.providentFundIndividuals"
|
type="number"
|
placeholder="请输入公积金个人" />
|
</u-form-item>
|
<u-form-item label="个人所得税"
|
prop="personalIncomeTax"
|
border-bottom>
|
<u-input v-model="form.personalIncomeTax"
|
type="number"
|
placeholder="请输入个人所得税" />
|
</u-form-item>
|
<u-form-item label="其他扣款"
|
prop="otherDeductions"
|
border-bottom>
|
<u-input v-model="form.otherDeductions"
|
type="number"
|
placeholder="请输入其他扣款" />
|
</u-form-item>
|
<u-form-item label="备注"
|
prop="remark"
|
border-bottom>
|
<u-textarea v-model="form.remark"
|
placeholder="请输入备注"
|
:rows="3"
|
:autoHeight="true" />
|
</u-form-item>
|
</u-cell-group>
|
<!-- 提交按钮 -->
|
<view class="footer-btns">
|
<u-button class="cancel-btn"
|
@click="goBack">取消</u-button>
|
<u-button class="sign-btn"
|
type="primary"
|
@click="handleSubmit"
|
:loading="loading">{{ isEdit ? '更新' : '保存' }}</u-button>
|
</view>
|
</u-form>
|
<!-- 员工选择器 -->
|
<up-action-sheet :show="staffSheetVisible"
|
:actions="staffOptions"
|
@select="handleStaffSelect"
|
@close="staffSheetVisible = false"
|
title="选择员工" />
|
<!-- 日期选择器 -->
|
<up-datetime-picker :show="datePickerVisible"
|
v-model="currentDate"
|
@confirm="onDateConfirm"
|
@cancel="datePickerVisible = false"
|
mode="month" />
|
</view>
|
</template>
|
|
<script setup>
|
// 替换 toast 方法
|
defineOptions({ name: "monthly-statistics-detail" });
|
const showToast = message => {
|
uni.showToast({
|
title: message,
|
icon: "none",
|
});
|
};
|
|
import { ref, onMounted } from "vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import {
|
monthlyStatisticsAdd,
|
monthlyStatisticsUpdate,
|
staffOnJobList,
|
} from "@/api/personnelManagement/monthlyStatistics";
|
import dayjs from "dayjs";
|
import { onLoad } from "@dcloudio/uni-app";
|
|
// 表单数据
|
const form = ref({
|
id: "",
|
payDate: "",
|
staffId: "",
|
staffName: "",
|
basicSalary: 0,
|
pieceworkSalary: 0,
|
hourlySalary: 0,
|
otherIncome: 0,
|
socialSecurityIndividuals: 0,
|
providentFundIndividuals: 0,
|
personalIncomeTax: 0,
|
otherDeductions: 0,
|
payableWages: 0,
|
deductibleWages: 0,
|
actualWages: 0,
|
remark: "",
|
});
|
|
// 页面状态
|
const loading = ref(false);
|
const formRef = ref(null);
|
const isEdit = ref(false);
|
|
// 员工选择器
|
const staffSheetVisible = ref(false);
|
const staffOptions = ref([]);
|
const staffList = ref([]);
|
const showStaffSheet = () => {
|
if (staffOptions.value.length === 0) {
|
loadStaffList();
|
} else {
|
staffSheetVisible.value = true;
|
}
|
};
|
const handleStaffSelect = item => {
|
const staff = staffList.value.find(s => s.id === item.value);
|
if (staff) {
|
form.value.staffId = staff.id;
|
form.value.staffName = staff.staffName;
|
}
|
staffSheetVisible.value = false;
|
};
|
const loadStaffList = () => {
|
staffOnJobList().then(res => {
|
if (res.code === 200) {
|
staffList.value = res.data || [];
|
staffOptions.value = staffList.value.map(item => ({
|
value: item.id,
|
name: item.staffName,
|
subname: `工号: ${item.staffNo}`,
|
}));
|
staffSheetVisible.value = true;
|
}
|
});
|
};
|
|
// 日期选择器
|
const datePickerVisible = ref(false);
|
const currentDate = ref(Date.now());
|
const showDatePicker = () => {
|
datePickerVisible.value = true;
|
};
|
const onDateConfirm = e => {
|
form.value.payDate = dayjs(e.value).format("YYYY-MM");
|
currentDate.value = e.value;
|
datePickerVisible.value = false;
|
};
|
|
// 返回上一页
|
const goBack = () => {
|
// 返回时清除本地存储的数据
|
uni.removeStorageSync("monthlyStatistics");
|
uni.navigateBack();
|
};
|
|
// 提交表单
|
const handleSubmit = async () => {
|
if (!form.value.payDate) {
|
showToast("请选择统计月份");
|
return;
|
}
|
|
if (!form.value.staffId) {
|
showToast("请选择员工");
|
return;
|
}
|
|
if (!form.value.basicSalary) {
|
showToast("请输入基本工资");
|
return;
|
}
|
|
// 计算应发工资、应扣工资和实发工资
|
const payableWages =
|
Number(form.value.basicSalary) +
|
Number(form.value.pieceworkSalary) +
|
Number(form.value.hourlySalary) +
|
Number(form.value.otherIncome);
|
const deductibleWages =
|
Number(form.value.socialSecurityIndividuals) +
|
Number(form.value.providentFundIndividuals) +
|
Number(form.value.personalIncomeTax) +
|
Number(form.value.otherDeductions);
|
const actualWages = payableWages - deductibleWages;
|
|
const submitData = {
|
...form.value,
|
payableWages,
|
deductibleWages,
|
actualWages,
|
};
|
|
try {
|
loading.value = true;
|
|
if (isEdit.value) {
|
const { code } = await monthlyStatisticsUpdate(submitData);
|
if (code === 200) {
|
showToast("更新成功");
|
setTimeout(() => {
|
goBack();
|
}, 500);
|
} else {
|
loading.value = false;
|
showToast("更新失败,请重试");
|
}
|
} else {
|
const { code } = await monthlyStatisticsAdd(submitData);
|
if (code === 200) {
|
showToast("保存成功");
|
setTimeout(() => {
|
goBack();
|
}, 500);
|
} else {
|
loading.value = false;
|
showToast("保存失败,请重试");
|
}
|
}
|
} catch (e) {
|
loading.value = false;
|
console.error("提交失败:", e);
|
showToast("提交失败,请重试");
|
}
|
};
|
|
onLoad(() => {
|
// 编辑薪资台账时,从本地存储获取数据
|
const monthlyStatistics = uni.getStorageSync("monthlyStatistics");
|
if (monthlyStatistics.id) {
|
form.value = monthlyStatistics;
|
isEdit.value = true;
|
} else {
|
isEdit.value = false;
|
}
|
});
|
|
onMounted(() => {
|
// 设置默认时间
|
if (!isEdit.value) {
|
form.value.payDate = dayjs().format("YYYY-MM");
|
currentDate.value = Date.now();
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
.hazard-source-detail {
|
min-height: 100vh;
|
background: #f8f9fa;
|
padding-bottom: 5rem;
|
}
|
|
.footer-btns {
|
position: fixed;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
background: #fff;
|
display: flex;
|
justify-content: space-around;
|
align-items: center;
|
padding: 0.75rem 0;
|
box-shadow: 0 -0.125rem 0.5rem rgba(0, 0, 0, 0.05);
|
z-index: 1000;
|
}
|
|
.cancel-btn {
|
font-weight: 400;
|
font-size: 1rem;
|
color: #666;
|
background: #f5f5f5;
|
border: 1px solid #ddd;
|
width: 45%;
|
height: 2.5rem;
|
border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
|
}
|
|
.sign-btn {
|
font-weight: 500;
|
font-size: 1rem;
|
color: #fff;
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
border: none;
|
width: 45%;
|
height: 2.5rem;
|
border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
|
}
|
</style>
|