Files
order_site/apps/frontend/src/components/admin/ConsignmentPendingMatchModal.tsx
T
zhaoxing e39f640dac feat(consignment): 统一寄卖匹配看板口径并收口占用与重匹配
- 看板与引擎统一数量、模板规格、正向规格信号判定,纳入 internal_matching/unassigned

- 库存侧改走新引擎匹配,移除旧 /fulfill 手动入口与旧弹窗

- 验收时将 reserved allocation 收口为 consumed,补份额级收口

- 拼单重新匹配通过 material 排除全部原库存/原卖家

- 开发/测试环境放宽迁移顺序校验,生产保持严格;修正集成测试份额报酬口径
2026-11-12 15:17:09 +08:00

334 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useQuery } from '@tanstack/react-query'
import { ReloadOutlined } from '@ant-design/icons'
import { Alert, Button, Checkbox, Empty, Input, Modal, Space, Tag, Typography } from 'antd'
import type { TableColumnsType } from 'antd'
import { useState } from 'react'
import PercentTable from '@/components/common/PercentTable'
import { fetchPendingPistolMatches } from '@/services/admin/consignment'
import type { PendingPistolMatchPair } from '@/types/consignment'
import { formatDateTime } from '@/utils/date-time'
const { Text } = Typography
function resolveScoreTag(pair: PendingPistolMatchPair) {
if (pair.quantitySufficient === false) return { color: 'orange', label: '数量不足' }
if (pair.matchType === 'exact') {
return pair.autoMatchable === false
? { color: 'gold', label: '需人工' }
: { color: 'green', label: '精确' }
}
if (pair.matchType === 'conflict') return { color: 'default', label: '不匹配' }
if (pair.autoMatchable) return { color: 'blue', label: '可自动' }
if (pair.score >= 90) return { color: 'blue', label: '非精确' }
if (pair.score >= 70) return { color: 'orange', label: '非精确' }
return { color: 'gold', label: '需核对' }
}
function resolveOrderStatusTag(status?: string) {
if (status === 'internal_matching') return { color: 'purple', label: '内部匹配中' }
if (status === 'unassigned') return { color: 'default', label: '待分配' }
return { color: 'blue', label: '待抢单' }
}
export default function ConsignmentPendingMatchModal({
open,
onClose,
categoryId,
categoryName,
}: {
open: boolean
onClose: () => void
/** 只统计该寄卖分类;不传 = 全部 */
categoryId?: number | null
categoryName?: string
}) {
const [keyword, setKeyword] = useState('')
const [includeConflicts, setIncludeConflicts] = useState(false)
const query = useQuery({
queryKey: ['admin-pending-pistol-matches', categoryId ?? null, keyword, includeConflicts],
queryFn: () =>
fetchPendingPistolMatches({
categoryId: categoryId ?? undefined,
keyword,
includeConflicts,
limit: 300,
}),
enabled: open,
refetchOnWindowFocus: false,
retry: false,
})
const data = query.data?.data
const pairs = data?.pairs || []
const columns: TableColumnsType<PendingPistolMatchPair> = [
{
title: '匹配打分',
key: 'score',
width: 90,
render: (_, record) => {
const tag = resolveScoreTag(record)
return (
<Space direction="vertical" size={3} style={{ width: '100%' }}>
<span style={{ fontSize: 18, fontWeight: 700, lineHeight: 1 }}>{record.score}</span>
<Tag color={tag.color} style={{ marginInlineEnd: 0 }}>
{tag.label}
</Tag>
</Space>
)
},
},
{
title: '订单信息',
key: 'order',
width: 280,
render: (_, record) => (
<Space direction="vertical" size={2} style={{ width: '100%' }}>
<Space size={4} align="center">
<Text type="secondary" style={{ fontSize: 11 }}>
工单
</Text>
{record.workOrderNo ? (
<Text
copyable={{ text: record.workOrderNo }}
style={{ fontSize: 12, fontWeight: 600, whiteSpace: 'nowrap' }}
>
{record.workOrderNo}
</Text>
) : (
<Text type="secondary">-</Text>
)}
</Space>
<Space size={4} align="center">
<Text type="secondary" style={{ fontSize: 11 }}>
平台
</Text>
{record.platformOrderId ? (
<Text
copyable={{ text: record.platformOrderId }}
style={{ fontSize: 11, whiteSpace: 'nowrap' }}
>
{record.platformOrderId}
</Text>
) : (
<Text type="secondary">-</Text>
)}
</Space>
<Text type="secondary" style={{ fontSize: 11 }}>
录单 {record.workOrderCreatedAt ? formatDateTime(record.workOrderCreatedAt) : '-'}
</Text>
<Space size={4} wrap>
<Tag
color={resolveOrderStatusTag(record.workOrderStatus).color}
style={{ marginInlineEnd: 0 }}
>
{resolveOrderStatusTag(record.workOrderStatus).label}
</Tag>
{Number(record.totalQuantity || 1) > 1 ? (
<Text type="secondary" style={{ fontSize: 11 }}>
拼单剩余 {record.remainingQuantity ?? 0} / {record.totalQuantity} 份
</Text>
) : null}
</Space>
{Number(record.requiredQuantity || 0) > 0 ? (
<Text
type={record.quantitySufficient === false ? 'danger' : 'secondary'}
style={{ fontSize: 11 }}
>
{record.sharingEnabled
? `拼单还需 ${record.requiredQuantity} 份 / 该库存剩 ${record.availableQuantity ?? '-'} 件`
: `需求 ${record.requiredQuantity} 件 / 该库存剩 ${record.availableQuantity ?? '-'} 件`}
{record.quantitySufficient === false ? '(整单汇总不足)' : ''}
</Text>
) : null}
</Space>
),
},
{
title: '商品名',
key: 'productName',
width: 220,
render: (_, record) => (
<Text ellipsis={{ tooltip: record.productName }} style={{ maxWidth: '100%' }}>
{record.productName || '-'}
</Text>
),
},
{
title: '寄售信息',
key: 'consignment',
width: 280,
render: (_, record) => (
<Space direction="vertical" size={2} style={{ width: '100%' }}>
<Space size={4} align="center">
<Text type="secondary" style={{ fontSize: 11 }}>
寄售
</Text>
<Text
copyable={{ text: record.consignmentNo || record.inventoryNo }}
style={{ fontSize: 12, fontWeight: 600, whiteSpace: 'nowrap' }}
>
{record.consignmentNo || record.inventoryNo || '-'}
</Text>
</Space>
{record.inventoryNo && record.inventoryNo !== record.consignmentNo ? (
<Space size={4} align="center">
<Text type="secondary" style={{ fontSize: 11 }}>
仓库
</Text>
<Text
copyable={{ text: record.inventoryNo }}
style={{ fontSize: 11, whiteSpace: 'nowrap' }}
>
{record.inventoryNo}
</Text>
</Space>
) : null}
<Text type="secondary" style={{ fontSize: 11 }}>
入库 {record.inventoryInboundAt ? formatDateTime(record.inventoryInboundAt) : '-'}
</Text>
</Space>
),
},
{
title: '寄售物品',
key: 'itemName',
width: 220,
render: (_, record) => (
<Text ellipsis={{ tooltip: record.itemName }} style={{ maxWidth: '100%' }}>
{record.itemName || '-'}
</Text>
),
},
{
title: '匹配说明',
key: 'reason',
width: 300,
render: (_, record) => (
<Space direction="vertical" size={2}>
<Text style={{ fontSize: 12 }}>{record.reason || '-'}</Text>
{record.conflicts.length > 0 ? (
<Text type="danger" style={{ fontSize: 11 }}>
{record.conflicts.join(';')}
</Text>
) : null}
{(record.matchDetails || [])
.filter((detail) => detail.status !== 'match' && detail.status !== 'ignored')
.slice(0, 4)
.map((detail) => (
<Text key={detail.key} type="secondary" style={{ fontSize: 11 }}>
{detail.label}:订单「{detail.orderValue || '-'}」/ 库存「
{detail.inventoryValue || '-'}」
</Text>
))}
</Space>
),
},
]
return (
<Modal
title={
categoryName
? `匹配 · ${categoryName} 待匹配订单 × 在库现货`
: '匹配 · 待匹配订单 × 在库现货'
}
open={open}
width="min(1320px, 94vw)"
footer={null}
destroyOnHidden
onCancel={onClose}
>
<Space direction="vertical" size={12} style={{ width: '100%' }}>
<Alert
type="info"
showIcon
message={
categoryName
? `只统计「${categoryName}」分类下的待匹配订单 × 在库待匹配现货,不直接改单。`
: '按寄卖配置匹配全部待匹配订单 × 在库待匹配现货,不直接改单。'
}
description="有寄卖配置的订单按该分类的规格逐项判定(精确 / 非精确 / 不匹配);内部匹配中、待分配、待抢单的工单都会纳入。数量不足或没有正向规格信号的非精确项会单独标记,自动匹配不会选中。"
/>
<Space wrap size={12}>
{categoryName ? <Tag color="blue">分类:{categoryName}</Tag> : null}
<Tag>待匹配 {data?.pendingOrderCount ?? 0} 单</Tag>
<Tag>在库待匹配 {data?.inStockInventoryCount ?? 0} 件</Tag>
<Tag color="blue">匹配组合 {data?.pairCount ?? 0} 条</Tag>
<Tag color="green">精确 {data?.exactCount ?? 0}</Tag>
<Tag color="orange">非精确 {data?.partialCount ?? 0}</Tag>
<Tag color="purple">数量不足 {data?.quantityShortCount ?? 0}</Tag>
<Tag color="cyan">可自动 {data?.autoMatchableCount ?? 0}</Tag>
{includeConflicts ? <Tag>不匹配 {data?.conflictCount ?? 0}</Tag> : null}
</Space>
<Space wrap size={12}>
<Input.Search
allowClear
placeholder="搜索平台号 / 工单号 / 商品名 / 寄售单号 / 寄售物品"
style={{ width: 420 }}
onSearch={(value) => setKeyword(value.trim())}
/>
<Checkbox
checked={includeConflicts}
onChange={(event) => setIncludeConflicts(event.target.checked)}
>
显示 0 分不匹配项
</Checkbox>
<Button
icon={<ReloadOutlined />}
loading={query.isFetching}
onClick={() => void query.refetch()}
>
刷新
</Button>
</Space>
{query.isError ? (
<Alert
type="error"
showIcon
message="读取匹配结果失败"
description={query.error instanceof Error ? query.error.message : '请稍后重试'}
/>
) : null}
{data?.truncated ? (
<Alert
type="warning"
showIcon
message={`结果较多,仅展示前 ${pairs.length} 条,请用搜索缩小范围`}
/>
) : null}
<PercentTable<PendingPistolMatchPair>
rowKey={(record) => `${record.workOrderId}-${record.inventoryId}`}
size="small"
loading={query.isFetching}
dataSource={pairs}
columns={columns}
scroll={{ y: 460 }}
pagination={{
pageSize: 20,
showSizeChanger: false,
showTotal: (total) => `共 ${total} 条`,
}}
locale={{
emptyText: (
<Empty
description={
includeConflicts
? '当前分类下没有可展示的配对'
: '当前分类下没有可匹配组合;可勾选「显示 0 分不匹配项」查看冲突'
}
/>
),
}}
/>
</Space>
</Modal>
)
}