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

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