import { ReloadOutlined } from '@ant-design/icons' import { useQuery } from '@tanstack/react-query' import { Input, Modal, Select, Space, Tag, Typography } from 'antd' import { useState } from 'react' import PercentTable from '@/components/common/PercentTable' import { fetchAdminConsignmentMatchLogs } from '@/services/admin/consignment' import type { ConsignmentMatchLogItem } from '@/types/consignment-match-log' import { formatDateTime } from '@/utils/date-time' const { Text } = Typography const TRIGGER_LABELS: Record = { auto: '自动匹配', manual: '手动匹配', rematch: '重新匹配', } const RESULT_LABELS: Record = { matched: { label: '已匹配', color: 'green' }, failed: { label: '失败', color: 'red' }, skipped: { label: '跳过', color: 'default' }, } const PAGE_SIZE = 20 export default function ConsignmentMatchLogsModal({ open, onClose, }: { open: boolean onClose: () => void }) { const [page, setPage] = useState(1) const [triggerType, setTriggerType] = useState() const [result, setResult] = useState() const [keyword, setKeyword] = useState('') const [keywordInput, setKeywordInput] = useState('') const logsQuery = useQuery({ queryKey: ['admin-consignment-match-logs', page, triggerType, result, keyword], queryFn: () => fetchAdminConsignmentMatchLogs({ page, pageSize: PAGE_SIZE, triggerType, result, keyword: keyword || undefined, }), enabled: open, }) const data = logsQuery.data?.data const items = data?.items || [] const total = Number(data?.total || 0) const columns = [ { title: '时间', dataIndex: 'createdAt', width: 160, render: (value: string) => (value ? formatDateTime(value) : '-'), }, { title: '工单', dataIndex: 'workOrderNo', width: 150, render: (_: string, record: ConsignmentMatchLogItem) => record.workOrderNo || (record.workOrderId ? `#${record.workOrderId}` : '-'), }, { title: '触发', dataIndex: 'triggerType', width: 100, render: (value: string) => ( {TRIGGER_LABELS[value] || value} ), }, { title: '结果', dataIndex: 'result', width: 90, render: (value: string) => { const config = RESULT_LABELS[value] || { label: value, color: 'default' } return {config.label} }, }, { title: '候选 / 成功', width: 100, render: (_: unknown, record: ConsignmentMatchLogItem) => `${record.candidateCount} / ${record.matchedCount}`, }, { title: '原因', dataIndex: 'reasonText', render: (value: string, record: ConsignmentMatchLogItem) => (
{value || '-'} {record.reasonCode ? ( {record.reasonCode} ) : null}
), }, { title: '操作人', dataIndex: 'actorId', width: 120, render: (value: string, record: ConsignmentMatchLogItem) => record.actorType === 'system' ? '系统' : value || '-', }, { title: '耗时', dataIndex: 'durationMs', width: 80, render: (value: number) => `${Number(value || 0)} ms`, }, ] return ( { setResult(value) setPage(1) }} options={[ { value: 'matched', label: '已匹配' }, { value: 'failed', label: '失败' }, { value: 'skipped', label: '跳过' }, ]} /> setKeywordInput(event.target.value)} onSearch={(value) => { setKeyword(value.trim()) setPage(1) }} /> 共 {total} 条 void logsQuery.refetch()} /> size="small" rowKey="logId" loading={logsQuery.isFetching} dataSource={items} columns={columns} scroll={{ x: 820 }} pagination={{ current: page, pageSize: PAGE_SIZE, total, showSizeChanger: false, onChange: (nextPage) => setPage(nextPage), }} /> ) }