WithdrawBatchDrawer.tsx
6.43 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { useEffect, useMemo, useRef, useState } from 'react';
import { UAlert, UButton, UCard, UDrawer, UResult, useUMessage } 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 } from '@/features/shared/format';
import { firstPage, useList, usePageClamp, useRefresh } from '@/features/shared/queries';
import { useConfirmAction } from '@/features/shared/useConfirmAction';
import {
APPROVAL_TRANSFER_FIELDS,
buildApprovalTransferColumns,
} from '@/features/shared/approvalTransfer';
/** 老系统这两段二次确认文案,一个管整个批次、一个管单条记录。 */
const DISBAND_TEXT =
'解散本批次,所有未驳回的积分提现记录将恢复「待审核」状态,如需重新生成批次,请选中后重新生成批次。';
const REMOVE_TEXT =
'移除该记录,该条积分提现记录将恢复「待审核」状态,如需重新生成批次,请选中后重新生成批次。';
export interface WithdrawBatchDrawerProps {
open: boolean;
id?: string;
onClose: () => void;
}
/**
* 批次编辑抽屉:一个审批批次里的提现记录,能解散整批、也能移出单条。
*
* 老系统(approveEdit.vue)在列表为空时用 $router.back() 退出本页,
* 那是任何一次筛空都会触发的;这里改成只有「批次本身已经没有记录」才关闭抽屉,
* 带筛选条件查不到时留在抽屉看空表。解散批次成功后直接关闭抽屉,不用等这一批从数据里消失。
*/
export function WithdrawBatchDrawer({ open, id, onClose }: WithdrawBatchDrawerProps) {
const { can } = usePointsAccess();
const message = useUMessage();
const allowed = can(PP.APPROVAL_VIEW);
const batchId = id ?? '';
const active = open && !!id;
const [filters, setFilters] = useState<Record<string, unknown>>({});
const [page, setPage] = useState(firstPage);
const refresh = useRefresh(['points', 'batch-transfers', batchId]);
const confirm = useConfirmAction(refresh);
const list = useList<WithdrawRow>({
scope: ['points', 'batch-transfers', batchId],
filters: { ...filters, approvalId: batchId },
page,
fetcher: withdrawApi.pageTransfers,
enabled: allowed && active,
});
usePageClamp(list.total, page, setPage);
const left = useRef(false);
const emptied =
active &&
!list.query.isPending &&
!list.query.isError &&
!Object.keys(filters).length &&
!list.records.length;
useEffect(() => {
if (!emptied || left.current) return;
left.current = true;
void message.info('本批次已没有提现记录');
onClose();
}, [emptied, message, onClose]);
// 换批次打开时重置「已自动退出」标记,避免上一批的空态把下一批的抽屉直接关掉。
useEffect(() => {
left.current = false;
}, [batchId]);
const columns = useMemo(() => buildApprovalTransferColumns('batch'), []);
const rowActions: RowActionSchema<WithdrawRow>[] = [
{
label: '移除',
danger: true,
// 权限走适配层的三态闸门,因此不用 RowActionSchema.permission(那条路要求后端已下发 points:*)。
visible: () => can(PP.APPROVAL_REMOVE),
onClick: (row) =>
confirm.confirm({
title: '移除提示',
content: REMOVE_TEXT,
danger: true,
run: () => withdrawApi.removeFromApproval({ type: 1, id: row.id }),
}),
},
];
return (
<UDrawer
title="编辑批次"
open={open}
onClose={onClose}
size={1200}
styles={{
body: {
display: 'flex',
flexDirection: 'column',
gap: 'var(--uj-space-module, 10px)',
},
}}
footer={
can(PP.APPROVAL_DISBAND) ? (
<UButton
danger
onClick={() =>
confirm.confirm({
title: '解散批次提示',
content: DISBAND_TEXT,
danger: true,
run: () => withdrawApi.removeFromApproval({ type: 2, id: batchId }),
then: onClose,
})
}
>
解散批次
</UButton>
) : null
}
>
{!allowed ? (
<UResult status="403" title="无积分提现审批访问权限" subTitle="请联系管理员确认账号权限。" />
) : !id ? (
<UResult
status="warning"
title="缺少批次标识"
subTitle="请从积分提现审批列表点击进入编辑。"
/>
) : (
<>
<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={list.error}
action={
<UButton type="link" onClick={() => void list.query.refetch()}>
重试
</UButton>
}
/>
) : null}
<UCard size="small">
<DataTable<WithdrawRow>
columns={columns}
rowKey="id"
actionColumnWidth={80}
dataSource={list.records}
loading={list.query.isPending || list.query.isFetching}
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>
{confirm.modal}
</>
)}
</UDrawer>
);
}
export default WithdrawBatchDrawer;