index.tsx
5.94 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
import { useEffect, useMemo, useRef, useState } from 'react';
import { UAlert, UButton, UCard, 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 { goTo } from '@/features/shared/navigate';
import { PageShell } from '@/features/shared/PageShell';
import {
APPROVAL_TRANSFER_FIELDS,
buildApprovalTransferColumns,
} from '@/features/shared/approvalTransfer';
import type { PageParams } from '@/routes';
/** 老系统这两段二次确认文案,一个管整个批次、一个管单条记录。 */
const DISBAND_TEXT =
'解散本批次,所有未驳回的积分提现记录将恢复「待审核」状态,如需重新生成批次,请选中后重新生成批次。';
const REMOVE_TEXT =
'移除该记录,该条积分提现记录将恢复「待审核」状态,如需重新生成批次,请选中后重新生成批次。';
/**
* 批次编辑:一个审批批次里的提现记录,能解散整批、也能移出单条。
*
* 老系统(approveEdit.vue)在列表为空时用 $router.back() 退出本页,
* 那是任何一次筛空都会触发的;这里改成只有「批次本身已经没有记录」才回列表,
* 带筛选条件查不到时留在本页看空表。解散批次成功后直接回列表,不用等这一批从数据里消失。
*/
export default function WithdrawBatch({ params }: { params: PageParams }) {
const { can } = usePointsAccess();
const message = useUMessage();
const allowed = can(PP.APPROVAL_VIEW);
const id = params.id ?? '';
const [filters, setFilters] = useState<Record<string, unknown>>({});
const [page, setPage] = useState(firstPage);
const refresh = useRefresh(['points', 'batch-transfers', id]);
const confirm = useConfirmAction(refresh);
const list = useList<WithdrawRow>({
scope: ['points', 'batch-transfers', id],
filters: { ...filters, approvalId: id },
page,
fetcher: withdrawApi.pageTransfers,
enabled: allowed && !!id,
});
usePageClamp(list.total, page, setPage);
const left = useRef(false);
const emptied =
!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('本批次已没有提现记录');
goTo('withdraw');
}, [emptied, message]);
const columns = useMemo(() => buildApprovalTransferColumns('batch'), []);
if (!allowed) {
return (
<UResult status="403" title="无积分提现审批访问权限" subTitle="请联系管理员确认账号权限。" />
);
}
if (!id) {
return (
<UResult
status="warning"
title="缺少批次标识"
subTitle="请从积分提现审批列表点击进入编辑。"
/>
);
}
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 (
<PageShell
fill
title="编辑批次"
description="这一个提现批次里的提现记录;解散整批或移出单条,被移出的记录会回到待审核。"
back="withdraw"
actions={
can(PP.APPROVAL_DISBAND) ? (
<UButton
danger
onClick={() =>
confirm.confirm({
title: '解散批次提示',
content: DISBAND_TEXT,
danger: true,
run: () => withdrawApi.removeFromApproval({ type: 2, id }),
then: () => goTo('withdraw'),
})
}
>
解散批次
</UButton>
) : null
}
>
<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" fill>
<DataTable<WithdrawRow>
columns={columns}
rowKey="id"
fillHeight
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}
</PageShell>
);
}