import { useEffect, useState } from 'react'; import { Clock3, Eye, Search } from 'lucide-react'; import { adminApi, type ReportRecord } from '@/api/adminApi'; import { Breadcrumb, Button, DateRangeInput, Input, Modal, Pagination, Select, Table, Tag, type DateRangeValue, type TableColumn } from '@/components/ui'; const statusTone: Record = { pending: 'neutral', waiting_material: 'warning', waiting_review: 'warning', reporting: 'warning', exporting: 'info', partial: 'warning', success: 'success', completed: 'success', failed: 'danger', rejected: 'danger', }; const statusLabel: Record = { pending: '待报备', waiting_material: '待补充资料', waiting_review: '待重新审核', reporting: '报备中', exporting: '导出中', partial: '部分通过', approved: '已通过', success: '成功', completed: '已完成', failed: '失败', rejected: '已驳回', abandoned: '已废弃', imported: '已导入', deleted: '已删除', }; const actionLabel: Record = { create: '创建报备任务', manual_status_change: '人工修改状态', export: '导出报备资料', receipt_import: '导入回执', audit_approved_create: '引流审核通过后创建', audit_approved_reset: '引流审核通过后重置', audit_resubmit_freeze: '引流修改后冻结', audit_rejected_freeze: '引流审核驳回后冻结', drainage_deleted: '引流信息删除', }; const sourceEntryLabel: Record = { enterprise_signature: '企业签名修改', report_task: '报备任务修改', channel_report: '通道信息修改', system: '系统自动处理', legacy: '历史记录(入口未记录)', }; function translateStatus(value?: string | null) { if (!value) return '-'; return statusLabel[value] ?? value; } function recordSource(record: ReportRecord) { if (record.sourceEntry) return sourceEntryLabel[record.sourceEntry] ?? record.sourceEntry; return record.action === 'manual_status_change' ? '历史记录(入口未记录)' : '系统自动处理'; } function RecordDetailModal({ record, onClose }: { record: ReportRecord; onClose: () => void }) { const isDrainage = record.task?.reportType === 'drainage'; const target = isDrainage ? record.task?.drainageInfo?.siteName ?? record.task?.drainageInfo?.url : record.task?.signature?.name; return ( 关闭} onClose={onClose} open size="xl" title={

报备记录详情

{record.id}

}>
报备任务号{record.taskId}
通道{record.channel?.name ?? '-'}
报备类型{isDrainage ? '引流信息' : '签名'}
报备对象{target ?? '-'}
动作{actionLabel[record.action] ?? record.action}
修改入口{recordSource(record)}
状态前{translateStatus(record.statusBefore)}
状态后{translateStatus(record.statusAfter)}
失败/备注原因{record.reason ?? '-'}

状态历史

{record.createdAt ?? '-'}{actionLabel[record.action] ?? record.action}{record.reason ?? `修改入口:${recordSource(record)}`}
); } export function AdminReportRecordsPage() { const [records, setRecords] = useState([]); const [keyword, setKeyword] = useState(''); const [dateRange, setDateRange] = useState({}); const [reportType, setReportType] = useState('all'); const [detail, setDetail] = useState(null); const [error, setError] = useState(''); const [page, setPage] = useState(1); const [total, setTotal] = useState(0); const pageSize = 10; function loadData(targetPage = page) { adminApi.listReportRecordsPage({ keyword: keyword || undefined, reportType: reportType === 'all' ? undefined : reportType as 'signature' | 'drainage', createdAtFrom: dateRange.start || undefined, createdAtTo: dateRange.end || undefined, page: targetPage, pageSize, }) .then((result) => { setRecords(result.items); setTotal(result.total); setError(''); }) .catch((failure: Error) => setError(failure.message || '报备记录加载失败')); } useEffect(() => { loadData(page); }, [page]); const columns: Array> = [ { key: 'task', title: '报备任务号', width: '190px', render: (record) => {record.taskId} }, { key: 'channel', title: '通道名称', width: '180px', render: (record) => record.channel?.name ?? '-' }, { key: 'targetType', title: '变更主体', width: '110px', render: (record) => {record.task?.reportType === 'drainage' ? '引流信息' : '签名'} }, { key: 'target', title: '主体内容', width: '260px', render: (record) => record.task?.reportType === 'drainage' ?
{record.task?.signature?.name ?? '-'}{record.task?.drainageInfo?.siteName ?? '-'}{record.task?.drainageInfo?.url ?? '-'}{record.task?.drainageInfo?.remark ? {record.task.drainageInfo.remark} : null}
:
{record.task?.signature?.name ?? '-'}{record.task?.signature?.purpose ? {record.task.signature.purpose} : null}
}, { key: 'source', title: '修改入口', width: '150px', render: (record) => recordSource(record) }, { key: 'action', title: '动作', width: '170px', render: (record) => actionLabel[record.action] ?? record.action }, { key: 'status', title: '状态变化', width: '210px', render: (record) => {`${translateStatus(record.statusBefore)} → ${translateStatus(record.statusAfter)}`} }, { key: 'time', title: '记录时间', width: '190px', render: (record) => record.createdAt ?? '-' }, { key: 'reason', title: '备注', width: '320px', render: (record) => {record.reason ?? '-'} }, { key: 'actions', title: '操作', align: 'right', width: '120px', render: (record) => }, ]; return (

报备记录

{error ?

{error}

: null}
setKeyword(event.target.value)} placeholder="请输入报备任务号、通道、动作或备注" value={keyword} />