feat: 专项附加扣除改为批量复制上月所有人的数据
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user