优化: 合同开始日期随入职日期自动同步

1. 添加员工和重新入职:入职日期变更时自动同步合同开始日期和结束日期
2. 合同开始日期改为只读显示(始终等于入职日期)
3. 花名册列表增加离职日期列:已离职显示日期,待离职显示预计日期
4. 重新入职弹窗对齐添加员工:移除孕期/医疗期/工伤,合同双向计算,试用期校验
5. 后端 rehireEmployee 重置特殊状态为 false
This commit is contained in:
freedakgmail
2026-07-23 18:34:12 +08:00
parent dad43931cf
commit eb58bc4b09
+30 -4
View File
@@ -879,6 +879,19 @@ function RehireModal({ employee, onClose, onSubmit, loading, error }: {
setForm({ ...form, endDate, contractYears: Math.max(1, Math.round(months / 12)) })
}
// 入职日期变更 → 同步合同开始日期 + 重算结束日期
const handleHireDateChange = (hireDate: string) => {
if (form.contractType === 'FIXED' && form.contractYears > 0 && hireDate) {
const start = new Date(hireDate)
const end = new Date(start)
end.setFullYear(end.getFullYear() + form.contractYears)
end.setDate(end.getDate() - 1)
setForm({ ...form, hireDate, startDate: hireDate, endDate: end.toISOString().slice(0, 10) })
} else {
setForm({ ...form, hireDate, startDate: hireDate })
}
}
// 开始日期变更 → 重新计算结束日期
const handleStartDateChange = (startDate: string) => {
if (form.contractType === 'FIXED' && form.contractYears > 0 && startDate) {
@@ -932,7 +945,7 @@ function RehireModal({ employee, onClose, onSubmit, loading, error }: {
</div>
<div>
<Label> *</Label>
<Input type="date" value={form.hireDate} onChange={(e) => setForm({ ...form, hireDate: e.target.value })} />
<Input type="date" value={form.hireDate} onChange={(e) => handleHireDateChange(e.target.value)} />
</div>
<div className="border-t pt-3">
<Label></Label>
@@ -950,7 +963,7 @@ function RehireModal({ employee, onClose, onSubmit, loading, error }: {
<Input type="date" value={form.signDate} onChange={(e) => setForm({ ...form, signDate: e.target.value })} />
<div className="text-xs text-gray-400 mt-0.5"></div>
</div>
<div><Label> *</Label><Input type="date" value={form.startDate} onChange={(e) => handleStartDateChange(e.target.value)} /></div>
<div><Label></Label><div className="text-xs text-gray-600 py-1.5">{form.startDate || '随入职日期'}</div></div>
</div>
{form.contractType === 'FIXED' && (
<>
@@ -1022,6 +1035,19 @@ function AddEmployeeModal({ onClose, onSubmit, loading, error }: {
contractYears: 3, probationMonths: 0, probationSalary: 0,
})
// 入职日期变更 → 同步合同开始日期 + 重算结束日期
const handleHireDateChange = (hireDate: string) => {
if (form.contractType === 'FIXED' && form.contractYears > 0 && hireDate) {
const start = new Date(hireDate)
const end = new Date(start)
end.setFullYear(end.getFullYear() + form.contractYears)
end.setDate(end.getDate() - 1)
setForm({ ...form, hireDate, startDate: hireDate, endDate: end.toISOString().slice(0, 10) })
} else {
setForm({ ...form, hireDate, startDate: hireDate })
}
}
// 根据身份证号自动计算性别(第17位:奇数=男,偶数=女)
const handleIdCardChange = (idCard: string) => {
let gender = form.gender
@@ -1148,7 +1174,7 @@ function AddEmployeeModal({ onClose, onSubmit, loading, error }: {
<div><Label></Label><div className="text-xs text-gray-600 py-1.5">{form.idCardNumber.length >= 17 ? form.gender : '由身份证号自动识别'}</div></div>
</div>
<div className="grid grid-cols-2 gap-3">
<div><Label> *</Label><Input type="date" value={form.hireDate} onChange={(e) => setForm({ ...form, hireDate: e.target.value })} /></div>
<div><Label> *</Label><Input type="date" value={form.hireDate} onChange={(e) => handleHireDateChange(e.target.value)} /></div>
<div><Label> *</Label><Input type="number" value={form.monthlySalary} onChange={(e) => setForm({ ...form, monthlySalary: e.target.value })} placeholder="元" /></div>
</div>
<div className="grid grid-cols-2 gap-3">
@@ -1168,7 +1194,7 @@ function AddEmployeeModal({ onClose, onSubmit, loading, error }: {
<Input type="date" value={form.signDate} onChange={(e) => setForm({ ...form, signDate: e.target.value })} />
<div className="text-xs text-gray-400 mt-0.5"></div>
</div>
<div><Label> *</Label><Input type="date" value={form.startDate} onChange={(e) => handleStartDateChange(e.target.value)} /></div>
<div><Label></Label><div className="text-xs text-gray-600 py-1.5">{form.startDate || '随入职日期'}</div></div>
</div>
{form.contractType === 'FIXED' && (
<>