import { useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import PageHeader from '@dukang/shared-ui/PageHeader'; import type { PartnerProxyOrderListItem } from '@dukang/shared-types'; import { request } from '../lib/api'; import { proxyOrderPayLabel, proxyOrderStatusColor, proxyOrderStatusLabel, } from '../lib/proxyOrderStatus'; import { toastError, toastSuccess } from '../lib/toast'; function fmtMoney(n: number) { return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } function fmtTime(value: string | undefined) { if (!value) return '—'; const d = new Date(value); if (Number.isNaN(d.getTime())) return value; const pad = (n: number) => String(n).padStart(2, '0'); return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`; } function deliveryLabel(order: PartnerProxyOrderListItem) { const t = String(order.deliveryType || '').toUpperCase(); if (t === 'ON_SITE_PICKUP') return '现场提货'; if (t === 'CROSS_CITY') return '跨城配送'; if (t === 'LOCAL') return '同城配送'; return '代下单'; } type TrackNode = { time?: string; status?: string; description?: string; }; type TrackResult = { nodes?: TrackNode[]; trackingNo?: string | null; provider?: string | null; manualQueryUrl?: string | null; }; export default function ProxyOrderDetailPage() { const { id } = useParams(); const navigate = useNavigate(); const [order, setOrder] = useState(null); const [error, setError] = useState(''); const [track, setTrack] = useState(null); const [trackError, setTrackError] = useState(''); const [paying, setPaying] = useState(false); useEffect(() => { document.title = '代下单详情'; }, []); useEffect(() => { if (!id) return; void request('PARTNER_H5', `/partner/proxy-orders/${id}`) .then(setOrder) .catch((e) => setError(e instanceof Error ? e.message : '加载失败')); }, [id]); useEffect(() => { if (!id || !order) return; const dt = String(order.deliveryType || '').toUpperCase(); if (dt === 'ON_SITE_PICKUP' || order.payStatus !== 'PAID') { setTrack(null); return; } void request('PARTNER_H5', `/partner/proxy-orders/${id}/track`, { silent: true }) .then(setTrack) .catch((e) => setTrackError(e instanceof Error ? e.message : '物流暂不可用')); }, [id, order]); async function continuePay() { if (!id) return; setPaying(true); try { await request('PARTNER_H5', `/partner/proxy-orders/${id}/pay/mock-confirm`, { method: 'POST', body: '{}', silent: true, }); toastSuccess('支付成功'); const refreshed = await request( 'PARTNER_H5', `/partner/proxy-orders/${id}`, ); setOrder(refreshed); } catch (e) { toastError(e instanceof Error ? e.message : '支付失败'); } finally { setPaying(false); } } const img = order?.imageResource?.url || ''; const isOnSite = String(order?.deliveryType || '').toUpperCase() === 'ON_SITE_PICKUP'; return (
navigate('/center/proxy-orders')} /> {error && (

{error}

)} {!order && !error &&

加载中…

} {order && (
NO. {order.orderNo} {proxyOrderStatusLabel(order.status)}
{!img && liquor}

{order.productName || '杜康好酒'}

{order.productSpec && (

{order.productSpec}

)}

×{order.quantity} · ¥{fmtMoney(Number(order.payAmount || 0))}

权益 ¥{fmtMoney(Number(order.benefitAmount || 0))}

客户信息

姓名:{order.receiverName || '—'}

手机:{order.receiverPhone || '—'}

地址:{order.receiverAddress || (isOnSite ? '现场提货' : '—')}

订单信息

配送方式:{deliveryLabel(order)}

下单时间:{fmtTime(order.createdAt)}

支付状态:{proxyOrderPayLabel(order.payStatus)}

订单状态:{proxyOrderStatusLabel(order.status)}

{order.payStatus === 'UNPAID' || order.status === 'PENDING_PAY' ? ( ) : null} {!isOnSite && order.payStatus === 'PAID' ? (

物流信息

{trackError ? (

{trackError}

) : !track ? (

加载物流…

) : ( <> {track.trackingNo ? (

运单号:{track.trackingNo} {track.provider ? `(${track.provider})` : ''}

) : null} {track.manualQueryUrl ? (

查看物流官网

) : null} {(track.nodes ?? []).length === 0 ? (

暂无物流轨迹(待总部发货后更新)

) : (
    {(track.nodes ?? []).map((n, i) => (
  • {fmtTime(n.time)}
    {n.description || n.status || '—'}
  • ))}
)} )}
) : null}
)}
); }