ApprovalPolicyPanels.tsx
6.43 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import type { TableColumnsType } from 'antd';
import { UTable } from '@uj/ui';
import type { StoreListingDetail, StoreListingItem } from '@/api';
import type { StoreDictionaries } from './dictionaries';
import { dictionaryLabel, formatMoney, formatPolicyValue } from './formatters';
import './approvalPolicy.css';
interface PanelProps {
detail: StoreListingDetail;
spec?: StoreDictionaries;
}
type PolicyPrefix = 'marketFee1' | 'marketFee2' | 'sunshine1' | 'sunshine2';
type PolicyRow = StoreListingItem & { displayKey: string };
function categoryCount(detail: StoreListingDetail): number | undefined {
if (
typeof detail.categoryCount === 'number' &&
Number.isSafeInteger(detail.categoryCount) &&
detail.categoryCount >= 0
) {
return detail.categoryCount;
}
if (!detail.items) return undefined;
return new Set(detail.items.map((item) => item.productCategory?.trim()).filter(Boolean)).size;
}
export function ApprovalPolicyPanel({
detail,
spec,
kind,
}: PanelProps & { kind: 'market' | 'sunshine' }) {
const market = kind === 'market';
const name = market ? '管理层市场费' : '一线阳光激励';
const prefixes: PolicyPrefix[] = market
? ['marketFee1', 'marketFee2']
: ['sunshine1', 'sunshine2'];
const columns: TableColumnsType<PolicyRow> = [
{
title: '产品分类',
key: 'category',
width: market ? 120 : 110,
fixed: 'left',
render: (_, item) => (
<span className="approval-policy-panel__category">
{dictionaryLabel(spec?.productCategories, item.productCategory)}
</span>
),
},
...prefixes.flatMap((prefix, index): TableColumnsType<PolicyRow> => [
...(prefix === 'sunshine1' || prefix === 'sunshine2'
? [
{
title: '开启线上积分',
key: `${prefix}OnlinePoint`,
width: 100,
render: (_: unknown, item: PolicyRow) =>
dictionaryLabel(spec?.onlinePointFlags, item[`${prefix}OnlinePoint`]),
},
]
: []),
{
title: `${market ? '市场费' : '激励'}${index + 1}计算模式`,
key: `${prefix}CalcMode`,
width: market ? 110 : 100,
render: (_, item) => dictionaryLabel(spec?.calcModes, item[`${prefix}CalcMode`]),
},
{
title: '计算方式',
key: `${prefix}CalcWay`,
width: market ? 90 : 80,
render: (_, item) => dictionaryLabel(spec?.calcWays, item[`${prefix}CalcWay`]),
},
{
title: `${market ? '市场费' : '激励费'}${index + 1}`,
key: `${prefix}Value`,
width: 80,
align: 'right',
render: (_, item) => (
<span className="approval-policy-panel__value">
{formatPolicyValue(item[`${prefix}Value`], item[`${prefix}Unit`] ?? undefined)}
</span>
),
},
]),
];
const rows = (detail.items || []).map((item, index) => ({
...item,
displayKey: `${item.itemId ?? 'item'}-${index}`,
}));
const count = categoryCount(detail);
return (
<section className="approval-policy-panel" aria-label={`${name}政策`}>
<div className="approval-policy-panel__table">
<UTable<PolicyRow>
rowKey="displayKey"
size="small"
pagination={false}
columns={columns}
dataSource={rows}
scroll={{ x: 'max-content' }}
/>
</div>
<p className="approval-policy-panel__note">
本页签展示本审批记录({detail.storeName || '—'} ·{' '}
{dictionaryLabel(spec?.businessScenes, detail.businessScene)})下
{count === undefined ? '的产品分类' : ` ${count} 个产品分类`}的{name}
政策,仅展示,不参与逐项勾选。
</p>
{!market && (
<p className="approval-policy-panel__note">
「开启线上积分」按记录中的是否值展示,激励费按各项政策的计算方式与单位展示。
</p>
)}
</section>
);
}
interface CostRow {
key: string;
name: string;
value: string;
description: string;
total?: boolean;
}
export function ApprovalCostPanel({ detail, spec }: PanelProps) {
// The heading supplies the currency unit. All digits still come from the shared formatter.
const amount = (value: StoreListingDetail['costTotal']) => formatMoney(value).replace(/^¥/, '');
const rows: CostRow[] = [
{
key: 'decoration',
name: '装修、设备总投入',
value: amount(detail.costDecoration),
description: '门店装修与设备投入',
},
{
key: 'monthly',
name: '当月产生(房租、水电、耗材等)',
value: amount(detail.costMonthly),
description: '门店当月房租、水电、耗材等费用',
},
{
key: 'labor',
name: '人工成本',
value: amount(detail.costLabor),
description: '门店人工成本',
},
{
key: 'total',
name: '运营成本合计',
value: amount(detail.costTotal),
description: '门店维度的运营成本合计',
total: true,
},
{
key: 'categories',
name: '本场景产品分类行数',
value: String(categoryCount(detail) ?? '—'),
description: dictionaryLabel(spec?.businessScenes, detail.businessScene),
},
];
const columns: TableColumnsType<CostRow> = [
{
title: '项目',
dataIndex: 'name',
key: 'name',
width: 240,
render: (value: string) => <span className="approval-cost-panel__name">{value}</span>,
},
{
title: '金额(元)',
dataIndex: 'value',
key: 'value',
width: 130,
align: 'right',
render: (value: string, row) =>
row.total ? <strong className="approval-cost-panel__total">{value}</strong> : value,
},
{
title: '说明',
dataIndex: 'description',
key: 'description',
className: 'approval-cost-panel__description',
},
];
return (
<section className="approval-policy-panel approval-cost-panel" aria-label="运营成本明细">
<div className="approval-policy-panel__table">
<UTable<CostRow>
rowKey="key"
size="small"
pagination={false}
columns={columns}
dataSource={rows}
scroll={{ x: 'max-content' }}
/>
</div>
<p className="approval-policy-panel__note">
运营成本为门店维度,不随产品分类数或业务场景数重复累计。
</p>
</section>
);
}