columns.tsx
5.74 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
import type { DataTableColumnsType } from '@/components/DataTable';
import { UTag, UTooltip } from '@uj/ui';
import { StatusTag } from '@/components/StatusTag';
import type { ApprovalRow, ApproveTab } from '@/api';
import type { StoreDictionaries } from '@/features/store/dictionaries';
import { dictionaryLabel, formatDateTime, formatMoney } from '@/features/store/formatters';
import '../approveTable.css';
function formatSubmitTime(value?: string | null): string {
const text = formatDateTime(value);
const match =
/^\d{4}-(\d{2}-\d{2}) (\d{2}:\d{2})(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/.exec(text);
return match ? `${match[1]} ${match[2]}` : text;
}
export function buildApproveColumns(
tab: ApproveTab,
spec?: StoreDictionaries,
): DataTableColumnsType<ApprovalRow> {
const columns: DataTableColumnsType<ApprovalRow> = [
{
title: '门店名称',
dataIndex: 'storeName',
width: tab === 'mine' ? 230 : 220,
fixed: 'left',
render: (value) => <strong>{value}</strong>,
},
{
title: '门店商户号',
dataIndex: 'merchantNo',
width: tab === 'mine' ? 120 : 110,
render: (value) => <span className="store-approve-merchant">{value || '—'}</span>,
},
{
title: '产品分类',
key: 'categories',
width: tab === 'todo' ? 170 : 200,
render: (_, row) => {
const categories = row.productCategories ?? [];
const count = row.categoryCount ?? categories.length;
const categoryNames = categories
.filter((category) => category.trim())
.map((category) => dictionaryLabel(spec?.productCategories, category));
return (
<UTooltip
trigger={['hover', 'focus']}
title={
categoryNames.length ? (
<ul className="store-approve-category-list" aria-label="全部产品分类">
{categoryNames.map((name, index) => (
<li key={`${name}-${index}`}>{name}</li>
))}
</ul>
) : undefined
}
>
<span
className="store-approve-categories"
tabIndex={categoryNames.length ? 0 : undefined}
>
{categoryNames[0] ? (
<span className="store-approve-tag">{categoryNames[0]}</span>
) : (
'—'
)}
{count > 1 && <span className="store-approve-category-count">等 {count} 个分类</span>}
</span>
</UTooltip>
);
},
},
{
title: '业务场景',
dataIndex: 'businessScene',
width: tab === 'todo' ? 200 : tab === 'done' ? 150 : 160,
render: (value) => (
<span className="store-approve-tag">{dictionaryLabel(spec?.businessScenes, value)}</span>
),
},
];
if (tab === 'todo')
columns.push(
{
title: '运营成本合计',
dataIndex: 'costTotal',
width: 110,
align: 'right',
render: (value) => (
<span className="store-approve-money">
{formatMoney(value).replace(/^¥/, '').replace(/\.00$/, '')}
</span>
),
},
{
title: '提交人 / 时间',
width: 150,
render: (_, row) => (
<>
{row.submitUserName || '—'}
<span className="store-approve-submit-time">{formatSubmitTime(row.submitTime)}</span>
</>
),
},
{
title: '停留时长',
width: 86,
render: (_, row) => {
const hours = row.pendingHours;
if (typeof hours !== 'number' || !Number.isFinite(hours) || hours < 0) return '—';
const level =
row.timeoutLevel ?? (hours > 48 ? 'DANGER' : hours > 24 ? 'WARNING' : 'NORMAL');
const tone =
level === 'DANGER'
? 'danger'
: level === 'WARNING'
? 'warning'
: level === 'NORMAL'
? 'normal'
: 'unknown';
return (
<span className={`store-approve-stay store-approve-stay--${tone}`}>{hours} 小时</span>
);
},
},
);
if (tab === 'done')
columns.push(
{
title: '我的动作',
width: 110,
render: (_, row) => (
<UTag
color={row.myAction === 'PASS' ? 'blue' : row.myAction === 'REJECT' ? 'red' : undefined}
>
{row.myActionLabel ||
({ PASS: '通过', REJECT: '打回' }[row.myAction ?? ''] ?? row.myAction ?? '—')}
</UTag>
),
},
{ title: '处理时间', dataIndex: 'handleTime', width: 150, render: formatDateTime },
{
title: '处理意见',
key: 'handleOpinion',
width: 220,
line: 2,
render: (_, row) => row.handleOpinion || row.rejectReason || '—',
},
{ title: '记录状态', width: 100, render: (_, row) => <StatusTag status={row.status} /> },
);
if (tab === 'mine')
columns.push(
{ title: '状态', width: 130, render: (_, row) => <StatusTag status={row.status} /> },
{
title: '审批进度',
width: 150,
render: (_, row) =>
row.status === 'PENDING'
? (row.totalLevel ?? 2) === 1 || row.currentLevel === 2
? '待优加财务经理审批'
: '待优加商务经理审批'
: row.status === 'REJECTED'
? '退回发起人'
: row.status === 'REVOKED'
? '发起人已撤回'
: row.status === 'APPROVED'
? '已完成'
: '—',
},
{ title: '提交时间', dataIndex: 'submitTime', width: 170, render: formatDateTime },
);
return columns;
}