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
import ResearchGroupAddModal from './components/ResearchGroupAddModal';
33
34
35
36
37
import ResearchGroupMemberRequestAddModal from './components/ResearchGroupMemberRequestAddModal';
import {
RESEARCH_GROUP_COLUMNS,
RESEARCH_GROUP_MEMBER_REQUEST_COLUMNS,
} from './constant';
38
39
40
import './index.less';
const PrepaidPage = () => {
const researchGroupActionRef = useRef<ActionType>();
41
const memberApplyActionRef = useRef<ActionType>();
42
43
const [researchGroupAddModalVisible, setResearchGroupAddModalVisible] =
useState(false);
44
45
46
const [importModalVisible, setImportModalVisible] = useState(false);
const [auditIds, setAuditIds] = useState<any[]>([]);
const [auditModalVisible, setAuditModalVisible] = useState(false);
曾国涛
authored
6 months ago
47
const [requestType, setRequestType] = useState(null);
48
49
50
51
const [
researchGroupMemberRequestAddModalVisible,
setResearchGroupMemberRequestAddModalVisible,
] = useState(false);
曾国涛
authored
12 months ago
52
const [auditType, setAuditType] = useState('');
53
// const [checkVisible, setCheckVisible] = useState(false);
54
55
56
57
58
59
60
const [accountInfo, setAccountInfo] = useState({
realName: '',
phone: '',
nowMoney: '',
uid: '',
});
const [accountInfoLoading, setAccountInfoLoading] = useState(false);
61
62
const [perms, setPerms] = useState<string[]>([]);
const [optRecordId, setOptRecordId] = useState<any>(null);
63
64
65
66
67
const reloadResearchGroupTable = () => {
researchGroupActionRef.current?.reload();
};
68
69
const reloadMemberApplyTable = () => {
memberApplyActionRef.current?.reload();
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
};
// 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>;
}
88
let tags = value.map((item: any) => {
89
90
91
92
93
94
95
96
97
98
99
100
101
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>
);
});
102
return <div className="whitespace-normal">{tags}</div>;
103
104
105
106
107
108
};
/**
* 获取预存账号信息
* @param accountId
*/
109
const loadAccountInfo = async (accountId: any, phone: any) => {
110
setAccountInfoLoading(true);
111
112
113
114
let res = await postCanrdApiUserDetail({
data: { uid: accountId, phone: phone },
});
if (res && res.result === RESPONSE_CODE.SUCCESS && res.data !== null) {
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
setAccountInfo(res.data);
} else {
setAccountInfo({
realName: '加载失败',
phone: '加载失败',
nowMoney: '加载失败',
uid: '加载失败',
});
}
setAccountInfoLoading(false);
};
const renderAccountsCell = (value: any) => {
if (!value) {
return <span></span>;
}
return (
133
<div className="whitespace-normal">
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
{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}>
163
164
165
166
167
<div>
{accountInfo.realName === ''
? '用户'
: accountInfo.realName}
</div>
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
</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={() => {
202
loadAccountInfo(accountId, accountPhone);
203
204
}}
>
205
{accountName === '' ? '用户' : accountName}
206
207
208
209
210
211
212
213
214
</Tag>
</Popconfirm>
);
})}
</div>
);
};
/**
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
* 删除课题组信息
* @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();
}
};
/**
* 加载课题组列表表格的各个列格式
244
245
246
247
248
*/
const researchGroupColumnsInit = () => {
let columns = RESEARCH_GROUP_COLUMNS.map((item) => {
let newItem = { ...item };
let dataIndex = item.dataIndex;
曾国涛
authored
12 months ago
249
250
251
252
253
254
if (!newItem.render) {
newItem.render = (text, record, index) => {
let textValue = record[dataIndex];
if (dataIndex.endsWith('Time')) {
textValue = formatDateTime(textValue);
}
255
曾国涛
authored
12 months ago
256
257
258
if (dataIndex === 'members') {
return renderMembersCell(textValue);
}
259
曾国涛
authored
12 months ago
260
261
262
if (dataIndex === 'accounts') {
return renderAccountsCell(textValue);
}
263
曾国涛
authored
12 months ago
264
265
266
if (dataIndex === 'index') {
textValue = index + 1;
}
267
曾国涛
authored
12 months ago
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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>
);
}
296
曾国涛
authored
12 months ago
297
298
299
return <EllipsisDiv text={textValue} />;
};
}
300
301
302
303
304
305
306
307
308
309
310
311
return newItem;
});
columns.push({
title: '操作',
valueType: 'option',
key: 'option',
fixed: 'right',
width: 120,
render: (text, record) => {
let btns = [];
312
if (perms?.includes('modify')) {
313
314
315
316
317
318
btns.push(
<Button
className="p-0"
key="modify"
type="link"
onClick={() => {
319
320
setResearchGroupAddModalVisible(true);
setOptRecordId(record?.id);
321
322
323
324
325
326
327
}}
>
编辑
</Button>,
);
}
328
if (perms?.includes('delete')) {
329
330
331
332
btns.push(
<ButtonConfirm
key="delete"
className="p-0"
333
title={'确认删除这个课题组吗?'}
334
335
text="删除"
onConfirm={async () => {
336
337
338
339
340
doDeleteResearchGroup([record.id]);
}}
/>,
);
}
曾国涛
authored
12 months ago
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
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>,
);
}
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
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
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
6 months ago
440
setRequestType(record?.requestType)
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
setOptRecordId(record?.id);
}}
>
编辑
</Button>,
);
}
if (record.permissions?.includes('delete')) {
btns.push(
<ButtonConfirm
key="delete"
className="p-0"
title={'确认删除这个申请吗?'}
text="删除"
onConfirm={async () => {
doDeleteRequest([record.id]);
458
459
460
461
}}
/>,
);
}
462
463
464
465
if (record.permissions?.includes('audit')) {
btns.push(
<Button
曾国涛
authored
9 months ago
466
key="audit"
467
468
469
470
className="p-0"
type="link"
onClick={async () => {
setAuditIds([record.id]);
曾国涛
authored
12 months ago
471
setAuditType('research_group_member_request_audit');
472
473
474
475
476
477
478
setAuditModalVisible(true);
}}
>
审核
</Button>,
);
}
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
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 },
});
502
setPerms(res.data.specialPath);
503
504
505
506
507
508
509
510
511
512
513
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 },
},
凌世锦
authored
about a year ago
514
515
516
// onChange(value) {
// console.log('value: ', value);
// },
517
518
519
520
521
522
523
524
525
526
527
528
529
530
}}
rowKey="id"
search={{
labelWidth: 'auto',
}}
options={{
setting: {
listsHeight: 400,
},
}}
form={{}}
dateFormatter="string"
headerTitle="课题组列表"
scroll={{ x: 1400 }}
531
532
toolBarRender={() => {
let btns = [];
533
if (perms?.includes('add')) {
534
535
536
537
538
539
540
541
542
543
544
545
546
547
btns.push(
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setResearchGroupAddModalVisible(true);
}}
type="primary"
>
新建
</Button>,
);
}
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
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
9 months ago
570
alwaysShowAlert: true,
571
572
573
574
575
}}
tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
let ids = selectedRows.map((item: any) => {
return item.id;
});
曾国涛
authored
9 months ago
576
577
578
579
580
let canAudit =
selectedRows.length > 0 &&
selectedRows.every((item) => {
return item.paths?.includes('ADD_AUDIT');
});
581
582
583
584
585
586
587
588
589
590
591
592
593
594
return (
<Space size={16}>
<ButtonConfirm
title="确认删除所选中的课题组信息吗?"
text="批量删除"
onConfirm={() => {
doDeleteResearchGroup(ids);
onCleanSelected();
}}
/>
<Button type="link" onClick={onCleanSelected}>
取消选中
</Button>
曾国涛
authored
9 months ago
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
{
<Button
key="audit"
type="link"
disabled={!canAudit}
onClick={async () => {
setAuditIds(ids);
setAuditModalVisible(true);
setAuditType('research_groups_add_audit');
}}
>
审核
</Button>
}
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
</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
6 months ago
664
key="abutton"
665
666
icon={<PlusOutlined />}
onClick={() => {
曾国涛
authored
6 months ago
667
setRequestType('ADD_ACCOUNT');
668
669
670
671
setResearchGroupMemberRequestAddModalVisible(true);
}}
type="primary"
>
曾国涛
authored
6 months ago
672
新增预存账号申请
673
674
</Button>,
);
曾国涛
authored
6 months ago
675
676
677
678
679
680
681
682
683
684
685
686
687
688
btns.push(
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setRequestType(null);
setResearchGroupMemberRequestAddModalVisible(true);
}}
type="primary"
>
新增成员申请
</Button>,
);
689
690
return btns;
}}
691
692
693
694
695
rowSelection={{
// 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
// 注释该行则默认不显示下拉选项
selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
defaultSelectedRowKeys: [],
曾国涛
authored
9 months ago
696
alwaysShowAlert: true,
697
698
699
700
701
}}
tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
let ids = selectedRows.map((item: any) => {
return item.id;
});
曾国涛
authored
9 months ago
702
703
704
705
706
let canAudit =
selectedRows.length > 0 &&
selectedRows.every((item) => {
return item.permissions?.includes('audit');
});
707
708
709
710
711
712
713
714
715
716
717
718
719
720
return (
<Space size={16}>
<ButtonConfirm
title="确认删除所选中的课题组信息吗?"
text="批量删除"
onConfirm={() => {
doDeleteRequest(ids);
onCleanSelected();
}}
/>
<Button
key="delete"
className="p-0"
type="link"
曾国涛
authored
9 months ago
721
disabled={!canAudit}
722
723
onClick={async () => {
setAuditIds(ids);
曾国涛
authored
9 months ago
724
setAuditType('research_group_member_request_audit');
725
726
727
728
729
730
731
732
733
734
735
setAuditModalVisible(true);
}}
>
批量审核
</Button>
<Button type="link" onClick={onCleanSelected}>
取消选中
</Button>
</Space>
);
}}
736
737
738
739
740
741
742
743
744
745
/>
),
},
];
return (
<div className="research-group-index">
<Tabs
defaultActiveKey="1"
items={tabsItems}
onChange={(value) => {
746
if (value === 1) {
747
748
reloadResearchGroupTable();
} else {
749
reloadMemberApplyTable();
750
751
752
753
754
755
756
757
}
}}
/>
{researchGroupAddModalVisible && (
<ResearchGroupAddModal
setVisible={(val: boolean) => {
setResearchGroupAddModalVisible(val);
758
759
760
if (!val) {
setOptRecordId(null);
}
761
}}
762
researchGroupId={optRecordId}
763
764
onClose={() => {
setResearchGroupAddModalVisible(false);
765
setOptRecordId(null);
766
767
768
769
770
771
772
reloadResearchGroupTable();
}}
/>
)}
{researchGroupMemberRequestAddModalVisible && (
<ResearchGroupMemberRequestAddModal
曾国涛
authored
6 months ago
773
774
775
776
777
778
779
780
781
setVisible={(val: boolean) => {
setResearchGroupMemberRequestAddModalVisible(val);
if (!val) {
setOptRecordId(null);
}
}}
requestId={optRecordId}
onClose={() => {
曾国涛
authored
6 months ago
782
setRequestType(null)
783
784
785
786
setResearchGroupMemberRequestAddModalVisible(false);
setOptRecordId(null);
reloadMemberApplyTable();
}}
曾国涛
authored
6 months ago
787
type={requestType}
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/>
)}
{auditModalVisible && (
<AuditModal
setVisible={(val: boolean) => {
setAuditModalVisible(val);
if (!val) {
setOptRecordId(null);
}
}}
ids={auditIds}
onClose={() => {
setAuditModalVisible(false);
setAuditIds([]);
reloadMemberApplyTable();
曾国涛
authored
12 months ago
804
researchGroupActionRef.current?.reload();
805
}}
曾国涛
authored
12 months ago
806
auditType={auditType}
807
808
809
810
811
812
813
814
/>
)}
{importModalVisible && (
<ImportModal
onClose={() => {
setImportModalVisible(false);
reloadMemberApplyTable();
815
816
817
818
819
820
821
822
}}
/>
)}
</div>
);
};
export default PrepaidPage;