Blame view

src/pages/ResearchGroup/index.tsx 22.4 KB
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
47
48
49
50
  const [importModalVisible, setImportModalVisible] = useState(false);
  const [auditIds, setAuditIds] = useState<any[]>([]);
  const [auditModalVisible, setAuditModalVisible] = useState(false);
  const [
    researchGroupMemberRequestAddModalVisible,
    setResearchGroupMemberRequestAddModalVisible,
  ] = useState(false);
曾国涛 authored
51
  const [auditType, setAuditType] = useState('');
52
  // const [checkVisible, setCheckVisible] = useState(false);
53
54
55
56
57
58
59
  const [accountInfo, setAccountInfo] = useState({
    realName: '',
    phone: '',
    nowMoney: '',
    uid: '',
  });
  const [accountInfoLoading, setAccountInfoLoading] = useState(false);
60
61
  const [perms, setPerms] = useState<string[]>([]);
  const [optRecordId, setOptRecordId] = useState<any>(null);
62
63
64
65
66

  const reloadResearchGroupTable = () => {
    researchGroupActionRef.current?.reload();
  };
67
68
  const reloadMemberApplyTable = () => {
    memberApplyActionRef.current?.reload();
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  };

  // 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>;
    }
zhongnanhuang authored
87
    let tags = value.map((item: any) => {
88
89
90
91
92
93
94
95
96
97
98
99
100
      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>
      );
    });
zhongnanhuang authored
101
    return <div className="whitespace-normal">{tags}</div>;
102
103
104
105
106
107
  };

  /**
   * 获取预存账号信息
   * @param accountId
   */
108
  const loadAccountInfo = async (accountId: any, phone: any) => {
109
    setAccountInfoLoading(true);
110
111
112
113
    let res = await postCanrdApiUserDetail({
      data: { uid: accountId, phone: phone },
    });
    if (res && res.result === RESPONSE_CODE.SUCCESS && res.data !== null) {
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
      setAccountInfo(res.data);
    } else {
      setAccountInfo({
        realName: '加载失败',
        phone: '加载失败',
        nowMoney: '加载失败',
        uid: '加载失败',
      });
    }
    setAccountInfoLoading(false);
  };

  const renderAccountsCell = (value: any) => {
    if (!value) {
      return <span></span>;
    }

    return (
zhongnanhuang authored
132
      <div className="whitespace-normal">
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
        {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}>
162
163
164
165
166
                          <div>
                            {accountInfo.realName === ''
                              ? '用户'
                              : accountInfo.realName}
                          </div>
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
                        </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={() => {
201
                  loadAccountInfo(accountId, accountPhone);
202
203
                }}
              >
204
                {accountName === '' ? '用户' : accountName}
205
206
207
208
209
210
211
212
213
              </Tag>
            </Popconfirm>
          );
        })}
      </div>
    );
  };

  /**
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
239
240
241
242
   * 删除课题组信息
   * @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();
    }
  };

  /**
   * 加载课题组列表表格的各个列格式
243
244
245
246
247
   */
  const researchGroupColumnsInit = () => {
    let columns = RESEARCH_GROUP_COLUMNS.map((item) => {
      let newItem = { ...item };
      let dataIndex = item.dataIndex;
曾国涛 authored
248
249
250
251
252
253
      if (!newItem.render) {
        newItem.render = (text, record, index) => {
          let textValue = record[dataIndex];
          if (dataIndex.endsWith('Time')) {
            textValue = formatDateTime(textValue);
          }
254
曾国涛 authored
255
256
257
          if (dataIndex === 'members') {
            return renderMembersCell(textValue);
          }
258
曾国涛 authored
259
260
261
          if (dataIndex === 'accounts') {
            return renderAccountsCell(textValue);
          }
262
曾国涛 authored
263
264
265
          if (dataIndex === 'index') {
            textValue = index + 1;
          }
266
曾国涛 authored
267
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
          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>
            );
          }
295
曾国涛 authored
296
297
298
          return <EllipsisDiv text={textValue} />;
        };
      }
299
300
301
302
303
304
305
306
307
308
309
310

      return newItem;
    });

    columns.push({
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      width: 120,
      render: (text, record) => {
        let btns = [];
311
        if (perms?.includes('modify')) {
312
313
314
315
316
317
          btns.push(
            <Button
              className="p-0"
              key="modify"
              type="link"
              onClick={() => {
318
319
                setResearchGroupAddModalVisible(true);
                setOptRecordId(record?.id);
320
321
322
323
324
325
326
              }}
            >
              编辑
            </Button>,
          );
        }
327
        if (perms?.includes('delete')) {
328
329
330
331
          btns.push(
            <ButtonConfirm
              key="delete"
              className="p-0"
332
              title={'确认删除这个课题组吗?'}
333
334
              text="删除"
              onConfirm={async () => {
335
336
337
338
339
                doDeleteResearchGroup([record.id]);
              }}
            />,
          );
        }
曾国涛 authored
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
        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>,
          );
        }
356
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
        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);
                setOptRecordId(record?.id);
              }}
            >
              编辑
            </Button>,
          );
        }

        if (record.permissions?.includes('delete')) {
          btns.push(
            <ButtonConfirm
              key="delete"
              className="p-0"
              title={'确认删除这个申请吗?'}
              text="删除"
              onConfirm={async () => {
                doDeleteRequest([record.id]);
456
457
458
459
              }}
            />,
          );
        }
460
461
462
463

        if (record.permissions?.includes('audit')) {
          btns.push(
            <Button
464
              key="audit"
465
466
467
468
              className="p-0"
              type="link"
              onClick={async () => {
                setAuditIds([record.id]);
曾国涛 authored
469
                setAuditType('research_group_member_request_audit');
470
471
472
473
474
475
476
                setAuditModalVisible(true);
              }}
            >
              审核
            </Button>,
          );
        }
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
        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 },
            });
500
            setPerms(res.data.specialPath);
501
502
503
504
505
506
507
508
509
510
511
            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 },
            },
PurelzMgnead authored
512
513
514
            // onChange(value) {
            //   console.log('value: ', value);
            // },
515
516
517
518
519
520
521
522
523
524
525
526
527
528
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
          }}
          options={{
            setting: {
              listsHeight: 400,
            },
          }}
          form={{}}
          dateFormatter="string"
          headerTitle="课题组列表"
          scroll={{ x: 1400 }}
529
530
          toolBarRender={() => {
            let btns = [];
531
            if (perms?.includes('add')) {
532
533
534
535
536
537
538
539
540
541
542
543
544
545
              btns.push(
                <Button
                  key="button"
                  icon={<PlusOutlined />}
                  onClick={() => {
                    setResearchGroupAddModalVisible(true);
                  }}
                  type="primary"
                >
                  新建
                </Button>,
              );
            }
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
            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: [],
568
            alwaysShowAlert: true,
569
570
571
572
573
          }}
          tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
            let ids = selectedRows.map((item: any) => {
              return item.id;
            });
574
575
576
577
578
            let canAudit =
              selectedRows.length > 0 &&
              selectedRows.every((item) => {
                return item.paths?.includes('ADD_AUDIT');
              });
579
580
581
582
583
584
585
586
587
588
589
590
591
592
            return (
              <Space size={16}>
                <ButtonConfirm
                  title="确认删除所选中的课题组信息吗?"
                  text="批量删除"
                  onConfirm={() => {
                    doDeleteResearchGroup(ids);
                    onCleanSelected();
                  }}
                />

                <Button type="link" onClick={onCleanSelected}>
                  取消选中
                </Button>
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

                {
                  <Button
                    key="audit"
                    type="link"
                    disabled={!canAudit}
                    onClick={async () => {
                      setAuditIds(ids);
                      setAuditModalVisible(true);
                      setAuditType('research_groups_add_audit');
                    }}
                  >
                    审核
                  </Button>
                }
608
609
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
664
665
666
667
668
669
670
671
              </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
                key="button"
                icon={<PlusOutlined />}
                onClick={() => {
                  setResearchGroupMemberRequestAddModalVisible(true);
                }}
                type="primary"
              >
                新建
              </Button>,
            );
672
673
            return btns;
          }}
674
675
676
677
678
          rowSelection={{
            // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
            // 注释该行则默认不显示下拉选项
            selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
            defaultSelectedRowKeys: [],
679
            alwaysShowAlert: true,
680
681
682
683
684
          }}
          tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
            let ids = selectedRows.map((item: any) => {
              return item.id;
            });
685
686
687
688
689
            let canAudit =
              selectedRows.length > 0 &&
              selectedRows.every((item) => {
                return item.permissions?.includes('audit');
              });
690
691
692
693
694
695
696
697
698
699
700
701
702
703
            return (
              <Space size={16}>
                <ButtonConfirm
                  title="确认删除所选中的课题组信息吗?"
                  text="批量删除"
                  onConfirm={() => {
                    doDeleteRequest(ids);
                    onCleanSelected();
                  }}
                />
                <Button
                  key="delete"
                  className="p-0"
                  type="link"
704
                  disabled={!canAudit}
705
706
                  onClick={async () => {
                    setAuditIds(ids);
707
                    setAuditType('research_group_member_request_audit');
708
709
710
711
712
713
714
715
716
717
718
                    setAuditModalVisible(true);
                  }}
                >
                  批量审核
                </Button>
                <Button type="link" onClick={onCleanSelected}>
                  取消选中
                </Button>
              </Space>
            );
          }}
719
720
721
722
723
724
725
726
727
728
        />
      ),
    },
  ];
  return (
    <div className="research-group-index">
      <Tabs
        defaultActiveKey="1"
        items={tabsItems}
        onChange={(value) => {
729
          if (value === 1) {
730
731
            reloadResearchGroupTable();
          } else {
732
            reloadMemberApplyTable();
733
734
735
736
737
738
739
740
          }
        }}
      />

      {researchGroupAddModalVisible && (
        <ResearchGroupAddModal
          setVisible={(val: boolean) => {
            setResearchGroupAddModalVisible(val);
741
742
743
            if (!val) {
              setOptRecordId(null);
            }
744
          }}
745
          researchGroupId={optRecordId}
746
747
          onClose={() => {
            setResearchGroupAddModalVisible(false);
748
            setOptRecordId(null);
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
            reloadResearchGroupTable();
          }}
        />
      )}

      {researchGroupMemberRequestAddModalVisible && (
        <ResearchGroupMemberRequestAddModal
          setVisible={(val: boolean) => {
            setResearchGroupMemberRequestAddModalVisible(val);
            if (!val) {
              setOptRecordId(null);
            }
          }}
          requestId={optRecordId}
          onClose={() => {
            setResearchGroupMemberRequestAddModalVisible(false);
            setOptRecordId(null);
            reloadMemberApplyTable();
          }}
        />
      )}

      {auditModalVisible && (
        <AuditModal
          setVisible={(val: boolean) => {
            setAuditModalVisible(val);
            if (!val) {
              setOptRecordId(null);
            }
          }}
          ids={auditIds}
          onClose={() => {
            setAuditModalVisible(false);
            setAuditIds([]);
            reloadMemberApplyTable();
曾国涛 authored
784
            researchGroupActionRef.current?.reload();
785
          }}
曾国涛 authored
786
          auditType={auditType}
787
788
789
790
791
792
793
794
        />
      )}

      {importModalVisible && (
        <ImportModal
          onClose={() => {
            setImportModalVisible(false);
            reloadMemberApplyTable();
795
796
797
798
799
800
801
802
          }}
        />
      )}
    </div>
  );
};

export default PrepaidPage;