feat: 专项附加扣除改为批量复制上月所有人的数据

This commit is contained in:
selfrelease
2026-07-27 19:53:19 +08:00
parent 0394164cfe
commit 67ebb2b26f
+40 -19
View File
@@ -1144,22 +1144,35 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
} : { children: 0, elderly: 0, housing: 0, education: 0, infant: 0, remark: '' })
}
/** 复制上月数据到编辑表单 */
const copyFromPrevMonth = (empId: string) => {
const prev = prevRecordMap.get(empId)
if (prev) {
setEditForm({
children: prev.children || 0,
elderly: prev.elderly || 0,
housing: prev.housing || 0,
education: prev.education || 0,
infant: prev.infant || 0,
remark: prev.remark || '',
})
} else {
toast.info(`${prevMonth} 无该员工的扣除记录`)
}
}
/** 批量复制上月数据到当月 */
const batchCopyMutation = useMutation({
mutationFn: async () => {
let copied = 0
for (const prev of prevRecords) {
await api.post('/social/special-deduction', {
employeeId: prev.employeeId,
month,
children: prev.children || 0,
elderly: prev.elderly || 0,
housing: prev.housing || 0,
education: prev.education || 0,
infant: prev.infant || 0,
remark: prev.remark || '',
})
copied++
}
return copied
},
onSuccess: (copied: number) => {
queryClient.invalidateQueries({ queryKey: ['special-deduction'] })
if (copied > 0) {
toast.success(`已复制 ${copied}${prevMonth} 的扣除数据到 ${month}`)
} else {
toast.info(`${prevMonth} 无可复制的扣除数据`)
}
},
onError: () => toast.error('复制上月数据失败'),
})
const calcTotal = (f: any) => (f.children || 0) + (f.elderly || 0) + (f.housing || 0) + (f.education || 0) + (f.infant || 0)
@@ -1167,7 +1180,17 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
<Card>
<div className="flex items-center justify-between mb-3">
<h2 className="text-sm font-medium"> {month}</h2>
<Input type="month" value={month} onChange={(e) => setMonth(e.target.value)} className="!w-32" />
<div className="flex items-center gap-2">
<Button
size="sm"
variant="secondary"
onClick={() => batchCopyMutation.mutate()}
disabled={batchCopyMutation.isPending || prevRecords.length === 0}
>
{batchCopyMutation.isPending ? '复制中...' : `复制上月(${prevMonth})`}
</Button>
<Input type="month" value={month} onChange={(e) => setMonth(e.target.value)} className="!w-32" />
</div>
</div>
{isLoading ? (
@@ -1209,7 +1232,6 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
<td className="py-1">
<div className="flex gap-1">
<Button size="sm" className="!h-7 !px-2" onClick={() => saveMutation.mutate({ employeeId: r.employeeId, ...editForm })} disabled={saveMutation.isPending}></Button>
<Button size="sm" variant="secondary" className="!h-7 !px-2" onClick={() => copyFromPrevMonth(r.employeeId)} disabled={!prevRecordMap.has(r.employeeId)}></Button>
<Button size="sm" variant="secondary" className="!h-7 !px-2" onClick={() => { setEditing(null); setEditForm(null) }}></Button>
</div>
</td>
@@ -1270,7 +1292,6 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
</div>
<div className="flex gap-2">
<Button size="sm" onClick={() => saveMutation.mutate({ employeeId: editing, ...editForm })} disabled={saveMutation.isPending}></Button>
<Button size="sm" variant="secondary" onClick={() => copyFromPrevMonth(editing)} disabled={!prevRecordMap.has(editing)}></Button>
<Button size="sm" variant="secondary" onClick={() => { setEditing(null); setEditForm(null) }}></Button>
</div>
</div>