index.tsx
3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { useQuery } from '@tanstack/react-query';
import { Skeleton, UAlert, UButton, UCard, UResult, UTitle } from '@uj/ui';
import { pointsApi } from '@/api';
import { PP } from '@/permissions/codes';
import { usePointsAccess } from '@/features/shared/access';
import { SETTLE_STATUS, optionLabel } from '@/features/shared/dictionaries';
import { numberOr, textOr } from '@/features/shared/format';
import { PageShell } from '@/features/shared/PageShell';
import type { PageParams } from '@/routes';
/** 详情字段的展示修饰:number = 按数字显示,code = 等宽字体(长单号)。 */
interface DetailField {
label: string;
key: string;
number?: boolean;
code?: boolean;
}
/** 详情字段与顺序逐字对齐老系统的 orderDetail.vue;空值一律显示占位符,不再显示 undefined。 */
const FIELDS: DetailField[] = [
{ label: '项目名称', key: 'bizRelName' },
{ label: '消费积分', key: 'integralValue', number: true },
{ label: '客户昵称', key: 'customerWechatName' },
{ label: '手机号', key: 'customerPhone', code: true },
{ label: '核销员工', key: 'verificationStaff' },
{ label: '结算状态', key: 'settlementStatusTxt' },
{ label: '核算日期', key: 'verificationTime' },
{ label: '订单编号', key: 'orderCode', code: true },
{ label: '操作人', key: 'updatedBy' },
{ label: '商户名称', key: 'merchantName' },
];
export default function OrderDetail({ params }: { params: PageParams }) {
const { can } = usePointsAccess();
const allowed = can(PP.ORDER_VIEW);
const id = params.id ?? '';
const detail = useQuery({
queryKey: ['points', 'order', id],
queryFn: () => pointsApi.orderDetail(id),
enabled: allowed && !!id,
});
if (!allowed) {
return (
<UResult status="403" title="无积分核销订单访问权限" subTitle="请联系管理员确认账号权限。" />
);
}
if (!id) {
return (
<UResult
status="warning"
title="缺少订单标识"
subTitle="请从积分核销订单列表点击进入查看。"
/>
);
}
const data = detail.data;
// 结算状态文案老系统在页面里由 settlementStatus 现算,这里同样不依赖接口的冗余字段。
const values: Record<string, string> = {
settlementStatusTxt: optionLabel(SETTLE_STATUS, data?.settlementStatus),
};
return (
<PageShell
title="核销订单详情"
description="这一笔积分核销的项目、客户与结算信息;返回后可在列表继续处理。"
back="list"
>
{detail.isError ? (
<UAlert
type="error"
showIcon
title="订单详情加载失败"
description={detail.error.message}
action={
<UButton type="link" onClick={() => void detail.refetch()}>
重试
</UButton>
}
/>
) : detail.isPending ? (
<Skeleton variant="detail" />
) : (
<UCard size="small">
<UTitle level={5}>订单信息</UTitle>
<dl className="uj-points-detail-grid">
{FIELDS.map((field) => {
const raw =
values[field.key] ?? (data as Record<string, unknown> | undefined)?.[field.key];
const text = field.number ? numberOr(raw) : textOr(raw);
return (
<div className="uj-points-detail-item" key={field.key}>
<dt>{field.label}</dt>
<dd className={field.code ? 'uj-code' : undefined} title={text}>
{text}
</dd>
</div>
);
})}
</dl>
</UCard>
)}
</PageShell>
);
}