feat: 专项附加扣除编辑增加「复制上月」按钮

This commit is contained in:
selfrelease
2026-07-27 19:50:29 +08:00
parent 22424489d2
commit 0394164cfe
+34
View File
@@ -1105,6 +1105,21 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
}, },
}) })
// 查询上月专项附加扣除数据(用于「复制上月」功能)
const prevMonth = (() => {
const [y, m] = month.split('-').map(Number)
const d = new Date(y, m - 2, 1)
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`
})()
const { data: prevRecords = [] } = useQuery<any[]>({
queryKey: ['special-deduction', prevMonth],
queryFn: async () => {
const res = await api.get('/social/special-deduction/batch', { params: { month: prevMonth } }) as any
return res.data || []
},
})
const prevRecordMap = new Map(prevRecords.map((r: any) => [r.employeeId, r]))
const saveMutation = useMutation({ const saveMutation = useMutation({
mutationFn: (data: any) => api.post('/social/special-deduction', { ...data, month }), mutationFn: (data: any) => api.post('/social/special-deduction', { ...data, month }),
onSuccess: () => { onSuccess: () => {
@@ -1129,6 +1144,23 @@ 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 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 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)
return ( return (
@@ -1177,6 +1209,7 @@ 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>
@@ -1237,6 +1270,7 @@ 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>