index.tsx
6.57 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import ButtonConfirm from '@/components/ButtomConfirm';
import EllipsisDiv from '@/components/Div/EllipsisDiv';
import { RESPONSE_CODE } from '@/constants/enum';
import { postPrepaidDelete, postPrepaidList } from '@/services';
import { enumValueToLabel, formatDateTime } from '@/utils';
import { PlusOutlined } from '@ant-design/icons';
import { ActionType, ProTable } from '@ant-design/pro-components';
import { Button, Divider, Image, message } from 'antd';
import { cloneDeep } from 'lodash';
import React, { useRef, useState } from 'react';
import CheckModal from '../../Order/Order/components/CheckModal';
import { CHECK_TYPE } from '../../Order/constant';
import RechargePrepaymentModal from '../components/RechargePrepaymentModal';
import {
PREPAID_STATUS_OPTIONS,
SALES_RECHARGE_PREPAYMENT_COLUMNS,
} from '../constant';
import './index.less';
const PrepaidRechargePage = () => {
const prepaidActionRef = useRef<ActionType>();
const [rechargePrepaymentModalVisible, setRechargePrepaymentModalVisible] =
useState<boolean>(false);
const [currentOptPrepaymentObj, setCurrentOptPrepaymentObj] = useState(null);
const [checkVisible, setCheckVisible] = useState<boolean>(false);
const reloadPrepaidTable = () => {
prepaidActionRef.current?.reload();
};
/**
* 加载预存充值表格的各个列格式
*/
const prepaidColumnsInit = () => {
let columns = SALES_RECHARGE_PREPAYMENT_COLUMNS.map((item) => {
let newItem = { ...item };
let dataIndex = item.dataIndex;
newItem.render = (text, record) => {
let textValue = record[dataIndex];
if (dataIndex === 'status') {
textValue = enumValueToLabel(textValue, PREPAID_STATUS_OPTIONS);
}
if (dataIndex.endsWith('Time')) {
textValue = formatDateTime(textValue);
}
if (
dataIndex === 'proofImages' &&
textValue !== null &&
textValue !== undefined
) {
return (
<Image.PreviewGroup
className="mr-10"
preview={{
onChange: (current, prev) =>
console.log(`current index: ${current}, prev index: ${prev}`),
}}
>
{textValue.map((item, index) => (
<React.Fragment key={index}>
{index > 0 ? <Divider type="vertical" /> : ''}
<Image
className="max-h-[35px] max-w-[45px]"
src={item}
title={item}
/>{' '}
</React.Fragment>
))}
</Image.PreviewGroup>
);
}
return <EllipsisDiv text={textValue} />;
};
return newItem;
});
columns.push({
title: '操作',
valueType: 'option',
key: 'option',
fixed: 'right',
width: 120,
render: (text, record) => {
let btns = [];
let opts = record.operations;
if (opts?.includes('modify')) {
btns.push(
<Button
className="p-0"
key="modify"
type="link"
onClick={() => {
setRechargePrepaymentModalVisible(true);
setCurrentOptPrepaymentObj(cloneDeep(record));
}}
>
编辑
</Button>,
);
}
if (opts?.includes('audit')) {
btns.push(
<Button
className="p-0"
key="view"
type="link"
onClick={() => {
setCurrentOptPrepaymentObj(record);
setCheckVisible(true);
}}
>
审核
</Button>,
);
}
if (opts?.includes('delete')) {
btns.push(
<ButtonConfirm
key="delete"
className="p-0"
title={'确认删除这条预存记录吗?'}
text="删除"
onConfirm={async () => {
let res = await postPrepaidDelete({
data: { ids: [record.id] },
});
if (res && res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
reloadPrepaidTable();
}
}}
/>,
);
}
return btns;
},
});
return columns;
};
return (
<div className="prepaid-recharge">
<ProTable
columns={prepaidColumnsInit()}
actionRef={prepaidActionRef}
cardBordered
pagination={{
pageSize: 10,
}}
request={async (params) => {
const res = await postPrepaidList({
data: { ...params },
});
return {
data: res?.data?.data || [],
total: res?.data?.total || 0,
};
}}
columnsState={{
persistenceKey: 'pro-table-singe-prepaid',
persistenceType: 'localStorage',
defaultValue: {
option: { fixed: 'right', disable: true },
},
onChange(value) {
console.log('value: ', value);
},
}}
rowKey="id"
search={{
labelWidth: 'auto',
}}
options={{
setting: {
listsHeight: 400,
},
}}
form={{}}
dateFormatter="string"
headerTitle="预存充值"
scroll={{ x: 1400 }}
toolBarRender={() => [
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setCurrentOptPrepaymentObj(null);
setRechargePrepaymentModalVisible(true);
}}
type="primary"
>
新增充值
</Button>,
]}
/>
{rechargePrepaymentModalVisible && (
<RechargePrepaymentModal
visible={rechargePrepaymentModalVisible}
onCancel={() => {
setRechargePrepaymentModalVisible(false);
}}
onOk={() => {
setRechargePrepaymentModalVisible(false);
reloadPrepaidTable();
}}
record={currentOptPrepaymentObj}
/>
)}
{checkVisible && (
<CheckModal
visible={checkVisible}
onCancel={() => {
setCheckVisible(false);
}}
onOk={() => {
setCheckVisible(false);
reloadPrepaidTable();
}}
record={currentOptPrepaymentObj}
type={CHECK_TYPE.PREPAID}
/>
)}
</div>
);
};
export default PrepaidRechargePage;