feat: 专项附加扣除编辑增加「复制上月」按钮
This commit is contained in:
@@ -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({
|
||||
mutationFn: (data: any) => api.post('/social/special-deduction', { ...data, month }),
|
||||
onSuccess: () => {
|
||||
@@ -1129,6 +1144,23 @@ 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 calcTotal = (f: any) => (f.children || 0) + (f.elderly || 0) + (f.housing || 0) + (f.education || 0) + (f.infant || 0)
|
||||
|
||||
return (
|
||||
@@ -1177,6 +1209,7 @@ 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>
|
||||
@@ -1237,6 +1270,7 @@ 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