ApprovalActionModal.tsx
5.59 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
import { UAlert, UButton, UCheckbox, UForm, UFormItem, UInput, UModal, UTag } from '@uj/ui';
import type { ApprovalRow } from '@/api';
import type { StoreDictionaries } from '@/features/store/dictionaries';
import { dictionaryLabel, formatMoney } from '@/features/store/formatters';
import { rejectReasons } from '../tools/consts';
export type ApprovalActionType = 'pass' | 'reject' | 'batch' | 'revoke';
export interface ApprovalAction {
type: ApprovalActionType;
records: ApprovalRow[];
}
const titles: Record<ApprovalActionType, string> = {
pass: '确认通过',
reject: '打回审批',
batch: '批量审批确认',
revoke: '确认撤回',
};
const buttons: Record<ApprovalActionType, string> = {
pass: '确认通过',
reject: '确认打回',
batch: '确认批量通过',
revoke: '确认撤回',
};
function approvalResultMessage(records: ApprovalRow[]) {
const hasUnknownLevel = records.some(
({ currentLevel, totalLevel }) =>
typeof currentLevel !== 'number' ||
typeof totalLevel !== 'number' ||
!Number.isInteger(currentLevel) ||
!Number.isInteger(totalLevel) ||
currentLevel < 1 ||
totalLevel < currentLevel,
);
if (!records.length || hasUnknownLevel) {
return '通过当前审批节点后,系统将按记录的审批进度处理;完成全部审批节点后生效并进入门店列表。';
}
const finalCount = records.filter((row) => row.currentLevel === row.totalLevel).length;
if (finalCount === records.length) {
return '通过当前审批节点后,记录将立即生效并进入门店列表。';
}
if (finalCount > 0) {
return '本次审批包含不同审批阶段的记录:终审记录通过后将立即生效并进入门店列表;其余记录将继续后续审批,全部节点通过后生效。';
}
return '通过当前审批节点后,记录将继续后续审批;全部节点通过后才会生效并进入门店列表。';
}
interface Props {
action?: ApprovalAction;
spec?: StoreDictionaries;
pending: boolean;
confirmed: boolean;
reason: string;
error?: string;
onConfirmed: (value: boolean) => void;
onReason: (value: string) => void;
onCancel: () => void;
onConfirm: () => void;
}
export function ApprovalActionModal({
action,
spec,
pending,
confirmed,
reason,
error,
onConfirmed,
onReason,
onCancel,
onConfirm,
}: Props) {
const type = action?.type ?? 'pass';
const needsConfirmation = type === 'pass' || type === 'batch';
return (
<UModal
open={!!action}
title={titles[type]}
width={600}
okText={buttons[type]}
cancelText="取消"
onCancel={onCancel}
onOk={onConfirm}
confirmLoading={pending}
closable={!pending}
maskClosable={!pending}
keyboard={!pending}
cancelButtonProps={{ disabled: pending }}
okButtonProps={{
disabled: needsConfirmation && !confirmed,
danger: type === 'reject' || type === 'revoke',
}}
>
{type === 'pass' || type === 'batch' ? (
<UAlert
type="info"
showIcon
title="审批范围为门店+业务场景下的全部产品分类"
description={approvalResultMessage(action?.records ?? [])}
/>
) : type === 'revoke' ? (
<UAlert type="warning" showIcon title="撤回后记录将退出当前审批流程。" />
) : null}
<div className="store-confirm-records">
{action?.records.map((row) => (
<div className="store-confirm-record" key={row.listingId}>
<strong>{row.storeName}</strong>
<span className="store-subtext">商户号:{row.merchantNo}</span>
<div style={{ marginTop: 8 }}>
<UTag color="blue">{dictionaryLabel(spec?.businessScenes, row.businessScene)}</UTag>
<span>{row.categoryCount ?? row.productCategories?.length ?? 0} 个产品分类</span>
</div>
{needsConfirmation && (
<>
<div style={{ marginTop: 8 }}>运营成本合计:{formatMoney(row.costTotal)}</div>
<span className="store-subtext">
{row.productCategories
?.map((category) => dictionaryLabel(spec?.productCategories, category))
.join('、')}
</span>
</>
)}
</div>
))}
</div>
{type === 'reject' && (
<UForm layout="vertical">
<UFormItem label="打回原因" required>
<UInput.TextArea
aria-label="打回原因"
value={reason}
onChange={(event) => onReason(event.target.value)}
maxLength={200}
showCount
rows={4}
placeholder="请填写打回原因(最多 200 字)"
disabled={pending}
/>
</UFormItem>
<div className="store-row-actions">
{rejectReasons.map((value) => (
<UButton
key={value}
type="default"
size="small"
disabled={pending}
onClick={() => onReason(value)}
>
{value}
</UButton>
))}
</div>
</UForm>
)}
{needsConfirmation && (
<UCheckbox
checked={confirmed}
disabled={pending}
onChange={(event) => onConfirmed(event.target.checked)}
>
我已核对以上记录和数据,确认通过当前审批节点
</UCheckbox>
)}
{error && <UAlert style={{ marginTop: 12 }} type="error" showIcon title={error} />}
</UModal>
);
}