diff --git a/frontend/src/pages/Roster.tsx b/frontend/src/pages/Roster.tsx index 7648f57..93dcc40 100644 --- a/frontend/src/pages/Roster.tsx +++ b/frontend/src/pages/Roster.tsx @@ -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 }: {
- setForm({ ...form, hireDate: e.target.value })} /> + handleHireDateChange(e.target.value)} />
@@ -950,7 +963,7 @@ function RehireModal({ employee, onClose, onSubmit, loading, error }: { setForm({ ...form, signDate: e.target.value })} />
留空表示尚未签订
-
handleStartDateChange(e.target.value)} />
+
{form.startDate || '随入职日期'}
{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 }: {
{form.idCardNumber.length >= 17 ? form.gender : '由身份证号自动识别'}
-
setForm({ ...form, hireDate: e.target.value })} />
+
handleHireDateChange(e.target.value)} />
setForm({ ...form, monthlySalary: e.target.value })} placeholder="元" />
@@ -1168,7 +1194,7 @@ function AddEmployeeModal({ onClose, onSubmit, loading, error }: { setForm({ ...form, signDate: e.target.value })} />
留空表示尚未签订
-
handleStartDateChange(e.target.value)} />
+
{form.startDate || '随入职日期'}
{form.contractType === 'FIXED' && ( <>