1
2
3
4
5
6
import ButtonConfirm from '@/components/ButtomConfirm';
import EllipsisDiv from '@/components/Div/EllipsisDiv';
import { RESPONSE_CODE } from '@/constants/enum';
import {} from '@/pages/Invoice/constant';
import {
postCanrdApiUserDetail,
7
8
postResearchGroupMemberRequestsDelete,
postResearchGroupMemberRequestsList,
9
postResearchGroupsDelete,
10
11
12
13
14
15
16
17
18
19
20
21
postResearchGroupsList,
} from '@/services';
import { formatDateTime } from '@/utils';
import { PlusOutlined } from '@ant-design/icons';
import { ActionType, ProTable } from '@ant-design/pro-components';
import {
Button,
Col,
Divider,
Image,
Popconfirm,
Row,
22
Space,
23
Spin,
24
Table,
25
26
27
28
29
Tabs,
Tag,
message,
} from 'antd';
import React, { useRef, useState } from 'react';
30
31
import AuditModal from './components/AuditModal';
import ImportModal from './components/ImportModal';
32
33
import PointsExchangeModal from './components/PointsExchangeModal';
import PointsExchangeRecordsModal from './components/PointsExchangeRecordsModal';
34
import ResearchGroupAddModal from './components/ResearchGroupAddModal';
35
36
37
38
39
import ResearchGroupMemberRequestAddModal from './components/ResearchGroupMemberRequestAddModal';
import {
RESEARCH_GROUP_COLUMNS,
RESEARCH_GROUP_MEMBER_REQUEST_COLUMNS,
} from './constant';
40
41
42
import './index.less';
const PrepaidPage = () => {
const researchGroupActionRef = useRef<ActionType>();
43
const memberApplyActionRef = useRef<ActionType>();
44
45
const [researchGroupAddModalVisible, setResearchGroupAddModalVisible] =
useState(false);
46
47
48
const [importModalVisible, setImportModalVisible] = useState(false);
const [auditIds, setAuditIds] = useState<any[]>([]);
const [auditModalVisible, setAuditModalVisible] = useState(false);
曾国涛
authored
4 months ago
49
const [requestType, setRequestType] = useState(null);
50
51
52
53
const [
researchGroupMemberRequestAddModalVisible,
setResearchGroupMemberRequestAddModalVisible,
] = useState(false);
曾国涛
authored
10 months ago
54
const [auditType, setAuditType] = useState('');
55
// const [checkVisible, setCheckVisible] = useState(false);
56
57
58
59
60
61
62
const [accountInfo, setAccountInfo] = useState({
realName: '',
phone: '',
nowMoney: '',
uid: '',
});
const [accountInfoLoading, setAccountInfoLoading] = useState(false);
63
64
const [perms, setPerms] = useState<string[]>([]);
const [optRecordId, setOptRecordId] = useState<any>(null);
65
66
67
68
69
70
71
const [pointsExchangeModalVisible, setPointsExchangeModalVisible] =
useState<boolean>(false);
const [
pointsExchangeRecordsModalVisible,
setPointsExchangeRecordsModalVisible,
] = useState<boolean>(false);
const [currentRecord, setCurrentRecord] = useState<any>(null);
72
73
74
75
76
const reloadResearchGroupTable = () => {
researchGroupActionRef.current?.reload();
};
77
78
const reloadMemberApplyTable = () => {
memberApplyActionRef.current?.reload();
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
};
// const getTableCellText = (target: any) => {
// if (!target) {
// return '';
// }
// if (target.props) {
// return target.props.text;
// }
// return target;
// };
const renderMembersCell = (value: any) => {
if (!value) {
return <span></span>;
}
97
let tags = value.map((item: any) => {
98
99
100
101
102
103
104
105
106
107
108
109
110
let memberName = item.memberName;
let memberPhone = item.memberPhone;
return (
<Tag
className="mt-1 mb-0"
key={item.id}
color="cyan"
title={memberName + ' | ' + memberPhone}
>
{memberName}
</Tag>
);
});
111
return <div className="whitespace-normal">{tags}</div>;
112
113
114
115
116
117
};
/**
* 获取预存账号信息
* @param accountId
*/
118
const loadAccountInfo = async (accountId: any, phone: any) => {
119
setAccountInfoLoading(true);
120
121
122
123
let res = await postCanrdApiUserDetail({
data: { uid: accountId, phone: phone },
});
if (res && res.result === RESPONSE_CODE.SUCCESS && res.data !== null) {
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
setAccountInfo(res.data);
} else {
setAccountInfo({
realName: '加载失败',
phone: '加载失败',
nowMoney: '加载失败',
uid: '加载失败',
});
}
setAccountInfoLoading(false);
};
const renderAccountsCell = (value: any) => {
if (!value) {
return <span></span>;
}
return (
142
<div className="whitespace-normal">
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
{value.map((item: any) => {
let accountPhone = item.accountPhone;
let accountName = item.accountName;
let accountId = item.accountId;
return (
<Popconfirm
key={item.id}
title="账号详情"
description={
<div className="w-[170px]">
{accountInfoLoading ? (
<div>
<Spin />
</div>
) : (
<div>
<Row gutter={4}>
<Col span={10}>
<div>编号:</div>
</Col>
<Col span={14}>
<div>{accountInfo.uid}</div>
</Col>
</Row>
<Row gutter={4}>
<Col span={10}>
<div>名称:</div>
</Col>
<Col span={14}>
172
173
174
175
176
<div>
{accountInfo.realName === ''
? '用户'
: accountInfo.realName}
</div>
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
</Col>
</Row>
<Row gutter={4}>
<Col span={10}>
<div>手机号:</div>
</Col>
<Col span={14}>
<EllipsisDiv text={accountInfo.phone} />
</Col>
</Row>
<Row gutter={4}>
<Col span={10}>
<div>余额:</div>
</Col>
<Col span={14}>
<div>{accountInfo.nowMoney}</div>
</Col>
</Row>
</div>
)}
</div>
}
cancelButtonProps={{
hidden: true,
}}
okButtonProps={{
hidden: true,
}}
>
<Tag
className="mt-1 mb-0 hover:cursor-pointer"
color="geekblue"
title={accountName + ' | ' + accountPhone}
onClick={() => {
211
loadAccountInfo(accountId, accountPhone);
212
213
}}
>
214
{accountName === '' ? '用户' : accountName}
215
216
217
218
219
220
221
222
223
</Tag>
</Popconfirm>
);
})}
</div>
);
};
/**
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
* 删除课题组信息
* @param ids
*/
const doDeleteResearchGroup = async (ids: any[]) => {
let res = await postResearchGroupsDelete({
data: { ids: ids },
});
if (res && res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
reloadResearchGroupTable();
}
};
/**
* 删除课题组信息
* @param ids
*/
const doDeleteRequest = async (ids: any[]) => {
let res = await postResearchGroupMemberRequestsDelete({
data: { ids: ids },
});
if (res && res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
reloadMemberApplyTable();
}
};
/**
* 加载课题组列表表格的各个列格式
253
254
255
256
257
*/
const researchGroupColumnsInit = () => {
let columns = RESEARCH_GROUP_COLUMNS.map((item) => {
let newItem = { ...item };
let dataIndex = item.dataIndex;
曾国涛
authored
10 months ago
258
259
260
261
262
263
if (!newItem.render) {
newItem.render = (text, record, index) => {
let textValue = record[dataIndex];
if (dataIndex.endsWith('Time')) {
textValue = formatDateTime(textValue);
}
264
曾国涛
authored
10 months ago
265
266
267
if (dataIndex === 'members') {
return renderMembersCell(textValue);
}
268
曾国涛
authored
10 months ago
269
270
271
if (dataIndex === 'accounts') {
return renderAccountsCell(textValue);
}
272
曾国涛
authored
10 months ago
273
274
275
if (dataIndex === 'index') {
textValue = index + 1;
}
276
曾国涛
authored
10 months ago
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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>
);
}
305
曾国涛
authored
10 months ago
306
307
308
return <EllipsisDiv text={textValue} />;
};
}
309
310
311
312
313
314
315
316
317
return newItem;
});
columns.push({
title: '操作',
valueType: 'option',
key: 'option',
fixed: 'right',
318
width: 240,
319
320
render: (text, record) => {
let btns = [];
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// Add Points Exchange button if there are accounts
btns.push(
<Button
className="p-0"
key="points-exchange"
type="link"
onClick={() => {
setCurrentRecord(record);
setPointsExchangeModalVisible(true);
}}
>
积分兑换
</Button>,
);
btns.push(
<Button
className="p-0"
key="points-records"
type="link"
onClick={() => {
setCurrentRecord(record);
setPointsExchangeRecordsModalVisible(true);
}}
>
积分兑换记录
</Button>,
);
351
if (perms?.includes('modify')) {
352
353
354
355
356
357
btns.push(
<Button
className="p-0"
key="modify"
type="link"
onClick={() => {
358
359
setResearchGroupAddModalVisible(true);
setOptRecordId(record?.id);
360
361
362
363
364
365
366
}}
>
编辑
</Button>,
);
}
367
if (perms?.includes('delete')) {
368
369
370
371
btns.push(
<ButtonConfirm
key="delete"
className="p-0"
372
title={'确认删除这个课题组吗?'}
373
374
text="删除"
onConfirm={async () => {
375
376
377
378
379
doDeleteResearchGroup([record.id]);
}}
/>,
);
}
曾国涛
authored
10 months ago
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
if (record.paths?.includes('ADD_AUDIT')) {
btns.push(
<Button
key="audit"
className="p-0"
type="link"
onClick={async () => {
setAuditIds([record.id]);
setAuditModalVisible(true);
setAuditType('research_groups_add_audit');
}}
>
审核
</Button>,
);
}
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
return btns;
},
});
return columns;
};
/**
* 加载申请列表表格的各个列格式
*/
const memberApplyColumnsInit = () => {
let columns = RESEARCH_GROUP_MEMBER_REQUEST_COLUMNS.map((item) => {
let newItem = { ...item };
let dataIndex = item.dataIndex;
newItem.render = (text, record, index) => {
let textValue = record[dataIndex];
if (dataIndex.endsWith('Time')) {
textValue = formatDateTime(textValue);
}
if (dataIndex === 'members') {
return renderMembersCell(textValue);
}
if (dataIndex === 'accounts') {
return renderAccountsCell(textValue);
}
if (dataIndex === 'index') {
textValue = index + 1;
}
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 = [];
if (record.permissions?.includes('modify')) {
btns.push(
<Button
className="p-0"
key="modify"
type="link"
onClick={() => {
setResearchGroupMemberRequestAddModalVisible(true);
曾国涛
authored
4 months ago
479
setRequestType(record?.requestType);
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
setOptRecordId(record?.id);
}}
>
编辑
</Button>,
);
}
if (record.permissions?.includes('delete')) {
btns.push(
<ButtonConfirm
key="delete"
className="p-0"
title={'确认删除这个申请吗?'}
text="删除"
onConfirm={async () => {
doDeleteRequest([record.id]);
497
498
499
500
}}
/>,
);
}
501
502
503
504
if (record.permissions?.includes('audit')) {
btns.push(
<Button
曾国涛
authored
8 months ago
505
key="audit"
506
507
508
509
className="p-0"
type="link"
onClick={async () => {
setAuditIds([record.id]);
曾国涛
authored
10 months ago
510
setAuditType('research_group_member_request_audit');
511
512
513
514
515
516
517
setAuditModalVisible(true);
}}
>
审核
</Button>,
);
}
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
return btns;
},
});
return columns;
};
const tabsItems = [
{
key: 1,
label: '课题组列表',
children: (
<ProTable
columns={researchGroupColumnsInit()}
actionRef={researchGroupActionRef}
cardBordered
pagination={{
pageSize: 10,
}}
request={async (params) => {
const res = await postResearchGroupsList({
data: { ...params },
});
541
setPerms(res.data.specialPath);
542
543
544
545
546
547
548
549
550
551
552
return {
data: res?.data?.data || [],
total: res?.data?.total || 0,
};
}}
columnsState={{
persistenceKey: 'pro-table-singe-research-group',
persistenceType: 'localStorage',
defaultValue: {
option: { fixed: 'right', disable: true },
},
553
554
555
// onChange(value) {
// console.log('value: ', value);
// },
556
557
558
559
560
561
562
563
564
565
566
567
568
569
}}
rowKey="id"
search={{
labelWidth: 'auto',
}}
options={{
setting: {
listsHeight: 400,
},
}}
form={{}}
dateFormatter="string"
headerTitle="课题组列表"
scroll={{ x: 1400 }}
570
571
toolBarRender={() => {
let btns = [];
572
if (perms?.includes('add')) {
573
574
575
576
577
578
579
580
581
582
583
584
585
586
btns.push(
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setResearchGroupAddModalVisible(true);
}}
type="primary"
>
新建
</Button>,
);
}
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
if (perms?.includes('import')) {
btns.push(
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setImportModalVisible(true);
}}
type="primary"
>
批量导入
</Button>,
);
}
return btns;
}}
rowSelection={{
// 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
// 注释该行则默认不显示下拉选项
selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
defaultSelectedRowKeys: [],
曾国涛
authored
8 months ago
609
alwaysShowAlert: true,
610
611
612
613
614
}}
tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
let ids = selectedRows.map((item: any) => {
return item.id;
});
曾国涛
authored
8 months ago
615
616
617
618
619
let canAudit =
selectedRows.length > 0 &&
selectedRows.every((item) => {
return item.paths?.includes('ADD_AUDIT');
});
620
621
622
623
624
625
626
627
628
629
630
631
632
633
return (
<Space size={16}>
<ButtonConfirm
title="确认删除所选中的课题组信息吗?"
text="批量删除"
onConfirm={() => {
doDeleteResearchGroup(ids);
onCleanSelected();
}}
/>
<Button type="link" onClick={onCleanSelected}>
取消选中
</Button>
曾国涛
authored
8 months ago
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
{
<Button
key="audit"
type="link"
disabled={!canAudit}
onClick={async () => {
setAuditIds(ids);
setAuditModalVisible(true);
setAuditType('research_groups_add_audit');
}}
>
审核
</Button>
}
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
</Space>
);
}}
/>
),
},
{
key: 2,
label: '申请列表',
children: (
<ProTable
columns={memberApplyColumnsInit()}
actionRef={memberApplyActionRef}
cardBordered
pagination={{
pageSize: 10,
}}
request={async (params) => {
const res = await postResearchGroupMemberRequestsList({
data: { ...params },
});
setPerms(res.data.specialPath);
return {
data: res?.data?.data || [],
total: res?.data?.total || 0,
};
}}
columnsState={{
persistenceKey: 'pro-table-singe-research-group',
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={() => {
let btns = [];
btns.push(
<Button
曾国涛
authored
4 months ago
703
key="abutton"
704
705
icon={<PlusOutlined />}
onClick={() => {
曾国涛
authored
4 months ago
706
setRequestType('ADD_ACCOUNT');
707
708
709
710
setResearchGroupMemberRequestAddModalVisible(true);
}}
type="primary"
>
曾国涛
authored
4 months ago
711
新增预存账号
712
713
</Button>,
);
曾国涛
authored
4 months ago
714
btns.push(
曾国涛
authored
4 months ago
715
716
717
718
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
曾国涛
authored
4 months ago
719
setRequestType('ADD_MEMBER');
曾国涛
authored
4 months ago
720
721
722
723
724
725
setResearchGroupMemberRequestAddModalVisible(true);
}}
type="primary"
>
新增成员
</Button>,
曾国涛
authored
4 months ago
726
727
);
728
729
return btns;
}}
730
731
732
733
734
rowSelection={{
// 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
// 注释该行则默认不显示下拉选项
selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
defaultSelectedRowKeys: [],
曾国涛
authored
8 months ago
735
alwaysShowAlert: true,
736
737
738
739
740
}}
tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
let ids = selectedRows.map((item: any) => {
return item.id;
});
曾国涛
authored
8 months ago
741
742
743
744
745
let canAudit =
selectedRows.length > 0 &&
selectedRows.every((item) => {
return item.permissions?.includes('audit');
});
746
747
748
749
750
751
752
753
754
755
756
757
758
759
return (
<Space size={16}>
<ButtonConfirm
title="确认删除所选中的课题组信息吗?"
text="批量删除"
onConfirm={() => {
doDeleteRequest(ids);
onCleanSelected();
}}
/>
<Button
key="delete"
className="p-0"
type="link"
曾国涛
authored
8 months ago
760
disabled={!canAudit}
761
762
onClick={async () => {
setAuditIds(ids);
曾国涛
authored
8 months ago
763
setAuditType('research_group_member_request_audit');
764
765
766
767
768
769
770
771
772
773
774
setAuditModalVisible(true);
}}
>
批量审核
</Button>
<Button type="link" onClick={onCleanSelected}>
取消选中
</Button>
</Space>
);
}}
775
776
777
778
779
780
781
782
783
784
/>
),
},
];
return (
<div className="research-group-index">
<Tabs
defaultActiveKey="1"
items={tabsItems}
onChange={(value) => {
785
if (value === 1) {
786
787
reloadResearchGroupTable();
} else {
788
reloadMemberApplyTable();
789
790
791
792
793
794
795
796
}
}}
/>
{researchGroupAddModalVisible && (
<ResearchGroupAddModal
setVisible={(val: boolean) => {
setResearchGroupAddModalVisible(val);
797
798
799
if (!val) {
setOptRecordId(null);
}
800
}}
801
researchGroupId={optRecordId}
802
803
onClose={() => {
setResearchGroupAddModalVisible(false);
804
setOptRecordId(null);
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
reloadResearchGroupTable();
}}
/>
)}
{researchGroupMemberRequestAddModalVisible && (
<ResearchGroupMemberRequestAddModal
setVisible={(val: boolean) => {
setResearchGroupMemberRequestAddModalVisible(val);
if (!val) {
setOptRecordId(null);
}
}}
requestId={optRecordId}
onClose={() => {
曾国涛
authored
4 months ago
820
setRequestType(null);
821
822
823
824
setResearchGroupMemberRequestAddModalVisible(false);
setOptRecordId(null);
reloadMemberApplyTable();
}}
曾国涛
authored
4 months ago
825
type={requestType}
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
/>
)}
{auditModalVisible && (
<AuditModal
setVisible={(val: boolean) => {
setAuditModalVisible(val);
if (!val) {
setOptRecordId(null);
}
}}
ids={auditIds}
onClose={() => {
setAuditModalVisible(false);
setAuditIds([]);
reloadMemberApplyTable();
曾国涛
authored
10 months ago
842
researchGroupActionRef.current?.reload();
843
}}
曾国涛
authored
10 months ago
844
auditType={auditType}
845
846
847
848
849
850
851
852
/>
)}
{importModalVisible && (
<ImportModal
onClose={() => {
setImportModalVisible(false);
reloadMemberApplyTable();
853
854
855
}}
/>
)}
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
{pointsExchangeModalVisible && currentRecord && (
<PointsExchangeModal
setVisible={setPointsExchangeModalVisible}
record={currentRecord}
onClose={() => {
reloadResearchGroupTable();
}}
/>
)}
{pointsExchangeRecordsModalVisible && currentRecord && (
<PointsExchangeRecordsModal
setVisible={setPointsExchangeRecordsModalVisible}
record={currentRecord}
onClose={() => {}}
/>
)}
874
875
876
877
878
</div>
);
};
export default PrepaidPage;