TransferDetailDialog.tsx
6.35 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
import { useQuery } from '@tanstack/react-query';
import { UButton, UModal, UText, UTitle, UTooltip, useUMessage } from '@uj/ui';
import { withdrawApi, type WithdrawRow } from '@/api';
import {
PAY_MODE,
TRANSFER_STATUS,
WITHDRAWAL_SOURCE,
WITHDRAWAL_TYPE,
findChannelNode,
optionLabel,
operationLabel,
statusMeta,
} from '@/features/shared/dictionaries';
import { centsToYuan, dateTimeOr, EMPTY, numberOr, textOr } from '@/features/shared/format';
import { useChannelTree } from '@/features/shared/options';
import { DetailGrid, type DetailValue } from '@/features/shared/DetailCell';
export interface TransferDetailDialogProps {
open: boolean;
/** 老系统弹窗只传 id,内容由 getById 再查一次。 */
id?: string;
onClose: () => void;
}
/** 复制失败原因:老系统用 execCommand,这里用剪贴板 API 并按结果说话。 */
async function copyText(text: string): Promise<boolean> {
try {
await navigator.clipboard.writeText(text);
return true;
} catch {
return false;
}
}
/**
* 提现详情弹窗:三段内容与字段顺序逐字对齐老系统 detail.vue(订单信息 11 项、付款信息 13 项、
* 操作记录按条铺开),失败原因只在状态为「失败」时出现。
*/
export function TransferDetailDialog({ open, id, onClose }: TransferDetailDialogProps) {
const message = useUMessage();
const channels = useChannelTree(open);
const detail = useQuery({
queryKey: ['points', 'transfer', id ?? ''],
queryFn: () => withdrawApi.transferDetail(String(id)),
enabled: open && !!id,
});
const row = detail.data as WithdrawRow | undefined;
const orderCells: DetailValue[] = row
? [
{ label: '提现单号', value: textOr(row.outSettleOrderId), code: true },
{ label: '提现类型', value: optionLabel(WITHDRAWAL_TYPE, row.transferType) || EMPTY },
{ label: '提现方式', value: optionLabel(PAY_MODE, row.mode) || EMPTY },
{ label: '提现金额', value: centsToYuan(row.payAmount) },
{ label: '客户名称', value: textOr(row.customerName) },
{ label: '客户手机', value: textOr(row.customerPhone), code: true },
{ label: '提现积分', value: numberOr(row.integralAmount) },
{ label: '所属门店', value: textOr(row.merchantName) },
{ label: '平台方', value: textOr(row.realityMerchantName) },
{ label: '申请时间', value: dateTimeOr(row.createdDate) },
{ label: '来源', value: optionLabel(WITHDRAWAL_SOURCE, row.withdrawalSource) || EMPTY },
]
: [];
const paymentCells: DetailValue[] = row
? [
{ label: '收款人姓名', value: textOr(row.name) },
{ label: '收款人身份证', value: textOr(row.idCardNo), code: true },
{ label: '收款银行卡号', value: textOr(row.recvBankCardNo), code: true },
{ label: '收款银行', value: textOr(row.recvBank) },
{ label: '收款手机号', value: textOr(row.mobile), code: true },
{ label: '微信openid', value: textOr(row.customerOpenId), code: true },
{
label: '付款渠道',
// 接口只回渠道 code,名字要在渠道树里递归找(与列表同一份树)。
value: textOr(findChannelNode(channels.nodes, row.channel)?.name),
},
{ label: '付款主体', value: textOr(row.paymentEntityName) },
{ label: '代征主体', value: textOr(row.levyName) },
{ label: '银行渠道', value: textOr(row.levyChannelName) },
{ label: '结算金额', value: centsToYuan(row.settleAmount) },
{ label: '到账时间', value: dateTimeOr(row.receiptDate) },
{ label: '状态', value: '', tag: statusMeta(TRANSFER_STATUS, row.status) },
]
: [];
return (
<UModal title="详细信息" open={open} footer={null} width={900} onCancel={onClose}>
{detail.isError ? (
<UText type="danger">提现记录加载失败:{detail.error.message}</UText>
) : (
<div className="uj-points-detail">
<UTitle level={5}>订单信息</UTitle>
<DetailGrid cells={orderCells} />
<UTitle level={5}>付款信息</UTitle>
<DetailGrid cells={paymentCells} />
{Number(row?.status) === 4 ? (
<div className="uj-points-error-row">
<span className="uj-points-error-label">失败原因</span>
<UTooltip title={row?.errorMessage}>
<span className="uj-points-error-text">{textOr(row?.errorMessage)}</span>
</UTooltip>
<UButton
type="link"
onClick={() => {
void copyText(row?.errorMessage ?? '').then((ok) =>
message[ok ? 'success' : 'error'](ok ? '已复制' : '复制失败,请手动选择'),
);
}}
>
复制
</UButton>
</div>
) : null}
{row?.operationList?.length ? (
<>
<UTitle level={5}>操作记录</UTitle>
{row.operationList.map((record, index) => {
const isReject = Number(record.result) === 1;
const result = isReject
? { label: '驳回', color: 'red' }
: Number(record.result) === 2
? { label: '失败', color: 'default' }
: { label: '通过', color: 'green' };
return (
<DetailGrid
key={`${record.createdDate ?? ''}-${index}`}
cells={[
{ label: operationLabel(record.type, 'name') || '操作', tag: result },
{
label: isReject
? '操作人'
: operationLabel(record.type, 'person') || '操作人',
value: textOr(record.createdBy),
},
{
label: isReject
? '操作时间'
: operationLabel(record.type, 'time') || '操作时间',
value: dateTimeOr(record.createdDate),
},
{ label: '备注', value: textOr(record.remark) },
]}
/>
);
})}
</>
) : null}
</div>
)}
</UModal>
);
}