index.tsx
4.61 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
import { useMemo, useState } from 'react';
import { useMutation } from '@tanstack/react-query';
import { UAlert, UButton, UCard, UResult } from '@uj/ui';
import { DataTable, SearchForm, type RowActionSchema } from '@/components';
import { withdrawApi, type WithdrawRow } from '@/api';
import { PP } from '@/permissions/codes';
import { usePointsAccess } from '@/features/shared/access';
import { compactParams, errorMessage } from '@/features/shared/format';
import {
firstPage,
useActionMessage,
useList,
usePageClamp,
useRefresh,
} from '@/features/shared/queries';
import { PageShell } from '@/features/shared/PageShell';
import {
APPROVAL_TRANSFER_FIELDS,
buildApprovalTransferColumns,
} from '@/features/shared/approvalTransfer';
import type { PageParams } from '@/routes';
/** 只有「受理失败」这一状态的记录能再次打款(老系统在到账情况那一格里放按钮)。 */
const PAYABLE_AGAIN = '6';
/**
* 到账明细:一个批次里每一笔提现的到账情况。
*
* 「再次打款」在老系统是直接调用、只给一条提示,这里保持同样的动作强度,
* 成功后照老系统那样清掉筛选条件重新取数,避免刚发起的记录被旧条件挡住。
*/
export default function WithdrawArrival({ params }: { params: PageParams }) {
const { can } = usePointsAccess();
const allowed = can(PP.APPROVAL_VIEW);
const id = params.id ?? '';
const notices = useActionMessage();
const [filters, setFilters] = useState<Record<string, unknown>>({});
const [page, setPage] = useState(firstPage);
const refresh = useRefresh(['points', 'arrival', id]);
const list = useList<WithdrawRow>({
scope: ['points', 'arrival', id],
filters: { ...filters, approvalId: id },
page,
fetcher: withdrawApi.pageTransfers,
enabled: allowed && !!id,
});
usePageClamp(list.total, page, setPage);
const payAgain = useMutation({
mutationFn: (row: WithdrawRow) => withdrawApi.payAgain(row.id),
onSuccess: async () => {
void notices.success('再次打款成功');
setFilters({});
setPage(firstPage);
await refresh();
},
onError: (error) => notices.fail(error),
});
const columns = useMemo(() => buildApprovalTransferColumns('arrival'), []);
if (!allowed) {
return (
<UResult status="403" title="无积分提现审批访问权限" subTitle="请联系管理员确认账号权限。" />
);
}
if (!id) {
return (
<UResult
status="warning"
title="缺少批次标识"
subTitle="请从积分提现审批列表点击进入到账明细。"
/>
);
}
const rowActions: RowActionSchema<WithdrawRow>[] = [
{
label: '再次打款',
visible: (row) => can(PP.ARRIVAL_PAY_AGAIN) && String(row.status ?? '') === PAYABLE_AGAIN,
onClick: (row) => payAgain.mutate(row),
},
];
return (
<PageShell
fill
title="到账明细"
description="这一个批次逐笔提现的到账情况;受理失败的记录可以重新发起打款。"
back="withdraw"
>
<UCard className="uj-filter-card" size="small">
<SearchForm
fields={APPROVAL_TRANSFER_FIELDS}
initialValues={{ customerName: '', customerPhone: '' }}
onSearch={(values) => {
setFilters(compactParams(values));
setPage(firstPage);
}}
onReset={() => {
setFilters({});
setPage(firstPage);
}}
/>
</UCard>
{list.query.isError ? (
<UAlert
type="error"
showIcon
title="到账明细加载失败"
description={errorMessage(list.error)}
action={
<UButton type="link" onClick={() => void list.query.refetch()}>
重试
</UButton>
}
/>
) : null}
<UCard size="small" fill>
<DataTable<WithdrawRow>
columns={columns}
rowKey="id"
fillHeight
actionColumnWidth={110}
dataSource={list.records}
loading={list.query.isPending || list.query.isFetching || payAgain.isPending}
rowActions={rowActions}
toolbarTitle={`共 ${list.total} 条到账记录`}
pagination={{
current: page.current,
pageSize: page.size,
total: list.total,
showSizeChanger: true,
pageSizeOptions: [10, 20, 50, 100],
showTotal: (total) => `共 ${total} 条`,
onChange: (current, size) =>
setPage({ current: size === page.size ? current : 1, size }),
}}
/>
</UCard>
</PageShell>
);
}