import { useState } from 'react' import { toast } from 'sonner' import { useMutation } from '@tanstack/react-query' import { socialInsuranceApi } from '../../lib/api-services' import { Input } from '../../components/ui/Input' const fmt = (n: number) => (n || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) /** 月度办理社保行组件(可展开查看各险种明细,支持修改基数) */ export function MonthlyRow({ item: i, type, onCorrected }: { item: any; type: 'add' | 'sub' | 'normal'; onCorrected?: () => void }) { const [expanded, setExpanded] = useState(false) const [editing, setEditing] = useState(false) const [editBase, setEditBase] = useState(i.base?.toString() || '') const typeLabel = type === 'add' ? (i.changeType === 'CITY_CHANGE' ? '新增(城市变更)' : '新增') : type === 'sub' ? (i.changeType === 'CITY_CHANGE' ? '减员(城市变更)' : '减员') : '正常' const typeClass = type === 'add' ? 'bg-green-50 text-safe' : type === 'sub' ? 'bg-red-50 text-danger' : 'bg-gray-100 text-gray-500' const d = i.detail const correctMutation = useMutation({ mutationFn: (data: { base: number }) => socialInsuranceApi.correctRecord('social', i.recordId, data), onSuccess: () => { setEditing(false) toast.success('基数已修改') onCorrected?.() }, onError: () => toast.error('修改失败'), }) const handleSaveBase = () => { const val = Number(editBase) || 0 if (val <= 0) { toast.error('基数必须大于0'); return } correctMutation.mutate({ base: val }) } return ( <> setExpanded(!expanded)}> {i.name} {d && {expanded ? '▾' : '▸'}} {i.department} {typeLabel} {editing ? ( e.stopPropagation()} className="inline-flex items-center gap-1"> setEditBase(e.target.value)} autoFocus /> ) : ( ¥{fmt(i.base)} {i.recordId && type !== 'sub' && ( )} )} {d ? `¥${fmt(d.totalOrg)}` : '-'} {d ? `¥${fmt(d.totalEmp)}` : '-'} {d ? `¥${fmt(d.total)}` : '-'} {type === 'add' ? `${i.startMonth} →` : type === 'sub' ? `→ ${i.endMonth}` : `${i.startMonth} ~ ${i.endMonth || '在保'}`} {expanded && d && ( {d.items.map((item: any) => ( ))}
险种 企业比例 个人比例 企业缴纳 个人缴纳
{item.name} {item.orgRate}% {item.empRate > 0 ? `${item.empRate}%` : '-'} ¥{fmt(item.orgAmount)} {item.empAmount > 0 ? `¥${fmt(item.empAmount)}` : '-'}
)} ) } /** 月度办理公积金行组件(支持修改基数) */ export function MonthlyHousingRow({ item: i, type, onCorrected }: { item: any; type: 'add' | 'sub' | 'normal'; onCorrected?: () => void }) { const [editing, setEditing] = useState(false) const [editBase, setEditBase] = useState(i.base?.toString() || '') const typeLabel = type === 'add' ? (i.changeType === 'CITY_CHANGE' ? '新增(城市变更)' : '新增') : type === 'sub' ? (i.changeType === 'CITY_CHANGE' ? '减员(城市变更)' : '减员') : '正常' const typeClass = type === 'add' ? 'bg-green-50 text-safe' : type === 'sub' ? 'bg-red-50 text-danger' : 'bg-gray-100 text-gray-500' const d = i.detail const correctMutation = useMutation({ mutationFn: (data: { base: number }) => socialInsuranceApi.correctRecord('housing', i.recordId, data), onSuccess: () => { setEditing(false) toast.success('基数已修改') onCorrected?.() }, onError: () => toast.error('修改失败'), }) const handleSaveBase = () => { const val = Number(editBase) || 0 if (val <= 0) { toast.error('基数必须大于0'); return } correctMutation.mutate({ base: val }) } return ( {i.name} {i.department} {typeLabel} {editing ? ( setEditBase(e.target.value)} autoFocus /> ) : ( ¥{fmt(i.base)} {i.recordId && type !== 'sub' && ( )} )} {d ? `¥${fmt(d.orgAmount)}` : '-'} {d ? `¥${fmt(d.empAmount)}` : '-'} {d ? `¥${fmt(d.total)}` : '-'} {type === 'add' ? `${i.startMonth} →` : type === 'sub' ? `→ ${i.endMonth}` : `${i.startMonth} ~ ${i.endMonth || '在保'}`} ) }