Blame view

src/pages/ResearchGroup/index.tsx 20.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);
51
  // const [checkVisible, setCheckVisible] = useState(false);
52
53
54
55
56
57
58
  const [accountInfo, setAccountInfo] = useState({
    realName: '',
    phone: '',
    nowMoney: '',
    uid: '',
  });
  const [accountInfoLoading, setAccountInfoLoading] = useState(false);
59
60
  const [perms, setPerms] = useState<string[]>([]);
  const [optRecordId, setOptRecordId] = useState<any>(null);
61
62
63
64
65

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

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

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

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

    return (
zhongnanhuang authored
131
      <div className="whitespace-normal">
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
        {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}>
                          <div>{accountInfo.realName}</div>
                        </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={() => {
196
                  loadAccountInfo(accountId, accountPhone);
197
198
199
200
201
202
203
204
205
206
207
208
                }}
              >
                {accountName}
              </Tag>
            </Popconfirm>
          );
        })}
      </div>
    );
  };

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

  /**
   * 加载课题组列表表格的各个列格式
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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
295
296
297
298
299
300
301
302
303
   */
  const researchGroupColumnsInit = () => {
    let columns = RESEARCH_GROUP_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 = [];
304
        if (perms?.includes('modify')) {
305
306
307
308
309
310
          btns.push(
            <Button
              className="p-0"
              key="modify"
              type="link"
              onClick={() => {
311
312
                setResearchGroupAddModalVisible(true);
                setOptRecordId(record?.id);
313
314
315
316
317
318
319
              }}
            >
              编辑
            </Button>,
          );
        }
320
        if (perms?.includes('delete')) {
321
322
323
324
          btns.push(
            <ButtonConfirm
              key="delete"
              className="p-0"
325
              title={'确认删除这个课题组吗?'}
326
327
              text="删除"
              onConfirm={async () => {
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
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
                doDeleteResearchGroup([record.id]);
              }}
            />,
          );
        }
        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]);
433
434
435
436
              }}
            />,
          );
        }
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452

        if (record.permissions?.includes('audit')) {
          btns.push(
            <Button
              key="delete"
              className="p-0"
              type="link"
              onClick={async () => {
                setAuditIds([record.id]);
                setAuditModalVisible(true);
              }}
            >
              审核
            </Button>,
          );
        }
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
        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 },
            });
476
            setPerms(res.data.specialPath);
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
            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 }}
505
506
          toolBarRender={() => {
            let btns = [];
507
            if (perms?.includes('add')) {
508
509
510
511
512
513
514
515
516
517
518
519
520
521
              btns.push(
                <Button
                  key="button"
                  icon={<PlusOutlined />}
                  onClick={() => {
                    setResearchGroupAddModalVisible(true);
                  }}
                  type="primary"
                >
                  新建
                </Button>,
              );
            }
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
            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: [],
          }}
          tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
            let ids = selectedRows.map((item: any) => {
              return item.id;
            });
            return (
              <Space size={16}>
                <ButtonConfirm
                  title="确认删除所选中的课题组信息吗?"
                  text="批量删除"
                  onConfirm={() => {
                    doDeleteResearchGroup(ids);
                    onCleanSelected();
                  }}
                />

                <Button type="link" onClick={onCleanSelected}>
                  取消选中
                </Button>
              </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>,
            );
627
628
            return btns;
          }}
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
          rowSelection={{
            // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
            // 注释该行则默认不显示下拉选项
            selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
            defaultSelectedRowKeys: [],
          }}
          tableAlertOptionRender={({ selectedRows, onCleanSelected }) => {
            let ids = selectedRows.map((item: any) => {
              return item.id;
            });
            return (
              <Space size={16}>
                <ButtonConfirm
                  title="确认删除所选中的课题组信息吗?"
                  text="批量删除"
                  onConfirm={() => {
                    doDeleteRequest(ids);
                    onCleanSelected();
                  }}
                />
                <Button
                  key="delete"
                  className="p-0"
                  type="link"
                  onClick={async () => {
                    setAuditIds(ids);
                    setAuditModalVisible(true);
                  }}
                >
                  批量审核
                </Button>
                <Button type="link" onClick={onCleanSelected}>
                  取消选中
                </Button>
              </Space>
            );
          }}
666
667
668
669
670
671
672
673
674
675
        />
      ),
    },
  ];
  return (
    <div className="research-group-index">
      <Tabs
        defaultActiveKey="1"
        items={tabsItems}
        onChange={(value) => {
676
          if (value === 1) {
677
678
            reloadResearchGroupTable();
          } else {
679
            reloadMemberApplyTable();
680
681
682
683
684
685
686
687
          }
        }}
      />

      {researchGroupAddModalVisible && (
        <ResearchGroupAddModal
          setVisible={(val: boolean) => {
            setResearchGroupAddModalVisible(val);
688
689
690
            if (!val) {
              setOptRecordId(null);
            }
691
          }}
692
          researchGroupId={optRecordId}
693
694
          onClose={() => {
            setResearchGroupAddModalVisible(false);
695
            setOptRecordId(null);
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
            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();
          }}
        />
      )}

      {importModalVisible && (
        <ImportModal
          onClose={() => {
            setImportModalVisible(false);
            reloadMemberApplyTable();
740
741
742
743
744
745
746
747
          }}
        />
      )}
    </div>
  );
};

export default PrepaidPage;