ListingDetailOverview.tsx
5.14 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { CloseOutlined } from '@ant-design/icons';
import { UButton } from '@uj/ui';
import type { StoreListingDetail } from '@/api';
import { STORE_STATUS, type StoreStatus } from '@/config/storeStatus';
import type { StoreDictionaries } from './dictionaries';
import { dictionaryLabel } from './formatters';
import './listingDetail.css';
const EMPTY = '—';
function categoryCount(detail: StoreListingDetail): string {
if (
typeof detail.categoryCount === 'number' &&
Number.isSafeInteger(detail.categoryCount) &&
detail.categoryCount >= 0
) {
return `${detail.categoryCount} 个`;
}
if (!detail.items) return EMPTY;
const categories = detail.items
.map((item) => item.productCategory?.trim())
.filter((category): category is string => !!category);
return `${new Set(categories).size} 个`;
}
function currentVersion(detail: StoreListingDetail): string {
const versions = (detail.changeHistory || [])
.map((change) => change.versionNo)
.filter(
(version): version is number =>
typeof version === 'number' && Number.isSafeInteger(version) && version > 0,
);
return versions.length
? `v${versions.reduce((latest, version) => Math.max(latest, version))}`
: EMPTY;
}
/** Format the API's calendar fields as text, preserving its original time zone. */
function effectiveDate(detail: StoreListingDetail, includeTime = false): string {
const value = detail.effectiveTime?.trim() || detail.approveTime?.trim();
const match = value?.match(/^(\d{4}-\d{2}-\d{2})(?:[T ](\d{2}:\d{2}))?/);
if (!match) return EMPTY;
return includeTime && match[2] ? `${match[1]} ${match[2]}` : match[1];
}
function ListingStatus({ detail }: { detail: StoreListingDetail }) {
const knownStatus = Object.hasOwn(STORE_STATUS, detail.status || '')
? STORE_STATUS[detail.status as StoreStatus]
: undefined;
const tone =
detail.status === 'APPROVED'
? 'approved'
: detail.status === 'PENDING'
? 'pending'
: detail.status === 'REJECTED'
? 'rejected'
: 'neutral';
return (
<span className={`listing-detail-status listing-detail-status--${tone}`}>
<span className="listing-detail-status__dot" aria-hidden="true" />
{detail.statusLabel?.trim() || knownStatus?.label || EMPTY}
</span>
);
}
export function ListingDetailHeader({
detail,
spec,
onClose,
}: {
detail: StoreListingDetail;
spec?: StoreDictionaries;
onClose: () => void;
}) {
return (
<section className="listing-detail-header" aria-label="门店概览">
<div className="listing-detail-header__top">
<h2>{detail.storeName?.trim() || EMPTY}</h2>
<div className="listing-detail-header__actions">
<ListingStatus detail={detail} />
<UButton
type="text"
className="listing-detail-header__close"
aria-label="关闭"
icon={<CloseOutlined />}
onClick={onClose}
/>
</div>
</div>
<dl className="listing-detail-meta">
<div>
<dt>商户号</dt>
<dd>{detail.merchantNo?.trim() || EMPTY}</dd>
</div>
<div>
<dt>业务场景</dt>
<dd>{dictionaryLabel(spec?.businessScenes, detail.businessScene?.trim())}</dd>
</div>
<div>
<dt>产品分类</dt>
<dd>{categoryCount(detail)}</dd>
</div>
<div>
<dt>上架时间</dt>
<dd>{effectiveDate(detail)}</dd>
</div>
<div>
<dt>当前版本</dt>
<dd>{currentVersion(detail)}</dd>
</div>
</dl>
</section>
);
}
export function ListingStoreInfo({
detail,
spec,
}: {
detail: StoreListingDetail;
spec?: StoreDictionaries;
}) {
const scene = detail.businessScene?.trim();
return (
<section className="listing-store-info" aria-label="门店信息">
<h3 className="listing-store-info__title">门店信息</h3>
<dl className="listing-store-info__fields">
<div>
<dt>门店名称</dt>
<dd>{detail.storeName?.trim() || EMPTY}</dd>
</div>
<div>
<dt>门店商户号</dt>
<dd>{detail.merchantNo?.trim() || EMPTY}</dd>
</div>
<div>
<dt>业务场景</dt>
<dd>
{scene ? (
<span className="listing-store-info__scene">
{dictionaryLabel(spec?.businessScenes, scene)}
</span>
) : (
EMPTY
)}
<span className="listing-store-info__hint">
同一门店的每个业务场景均覆盖全部产品分类
</span>
</dd>
</div>
<div>
<dt>产品分类数</dt>
<dd>
<span>{categoryCount(detail)}</span>
<span className="listing-store-info__hint">完整清单见「产品与场景」页签</span>
</dd>
</div>
<div>
<dt>上架状态</dt>
<dd>
<ListingStatus detail={detail} />
</dd>
</div>
<div>
<dt>生效时间</dt>
<dd>{effectiveDate(detail, true)}</dd>
</div>
</dl>
</section>
);
}