AuditDialog.tsx
3.1 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
import { useState } from 'react';
import { useMutation } from '@tanstack/react-query';
import { UInput, UModal, UText, useUMessage } from '@uj/ui';
import { withdrawApi } from '@/api';
import { errorMessage } from '@/features/shared/format';
/**
* 提现审核弹窗:老系统一个弹窗承担三种提交(审核、驳回、批量驳回),外加一键审核。
* kind 决定标题、字段文案与调哪个接口,页面只负责说「现在要点哪颗按钮」。
*/
export type AuditKind = 'approve' | 'reject' | 'batchReject' | 'allApprove';
export interface AuditDialogProps {
open: boolean;
kind: AuditKind;
/** 勾选或当前行的提现记录 id;一键审核不用它(按查询条件整批处理)。 */
ids: string[];
/** 一键审核要带上的查询条件(老系统的 tableSearchForm)。 */
filters?: Record<string, unknown>;
onClose: () => void;
/** 成功之后由页面刷新列表并清空勾选(老系统每个分支都 handleReset + clearSelect)。 */
onSuccess: () => void;
}
const TITLES: Record<AuditKind, string> = {
approve: '审核',
allApprove: '审核',
reject: '驳回',
batchReject: '驳回',
};
/** 三种提交的接口与入参逐字对回老系统的 comfirmCheck 分支。 */
async function submit(
kind: AuditKind,
ids: string[],
remark: string,
filters: Record<string, unknown>,
) {
if (kind === 'batchReject') return withdrawApi.rejectBatch({ ids, rejectReason: remark });
if (kind === 'reject') return withdrawApi.approveOne({ id: ids[0], remark, type: 2 });
if (kind === 'allApprove') return withdrawApi.approveAll({ ...filters, remark });
return withdrawApi.approveBatch({ ids, remark, type: 0 });
}
export function AuditDialog({ open, kind, ids, filters, onClose, onSuccess }: AuditDialogProps) {
const message = useUMessage();
const [remark, setRemark] = useState('');
const isReject = kind === 'reject' || kind === 'batchReject';
const mutation = useMutation({
mutationFn: () => {
if (isReject && !remark) throw new Error('请输入驳回原因');
return submit(kind, ids, remark, filters ?? {});
},
onSuccess: () => {
void message.success('操作成功');
setRemark('');
onSuccess();
},
onError: (error) => void message.error(errorMessage(error)),
});
return (
<UModal
title={TITLES[kind]}
open={open}
confirmLoading={mutation.isPending}
okText="确定"
onCancel={() => {
setRemark('');
onClose();
}}
onOk={() => mutation.mutate()}
>
<UText type="secondary" className="uj-points-dialog-label">
{isReject ? '驳回原因' : '备注'}
</UText>
<UInput.TextArea
rows={3}
maxLength={50}
showCount
value={remark}
placeholder={isReject ? '请输入驳回原因' : '请输入备注'}
onChange={(event) => setRemark(event.target.value)}
/>
{isReject ? null : (
<UText type="secondary" className="uj-points-dialog-hint">
审核通过后,转账业务单据自动流转至财务确认。
</UText>
)}
</UModal>
);
}