广州市综治平台前端
xusd
1 days ago e8071c7d6f7aa6ac0d5522c59a52ee5e187a4b16
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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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
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
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
import React, { Fragment, useEffect, useState, useRef } from 'react';
import * as $$ from '@/utils/utility';
import ArcoUpload from '@/components/ArcoUpload';
import NewFileCheck from './NewFileCheck';
import { Row, Col, Button, Typography, Space } from 'antd';
import { Form, Modal } from '@arco-design/web-react';
import {
  applyMaterials,
  applyMaterials_active,
  evidenceMaterials,
  evidenceMaterials_active,
} from '@/assets/images';
import { CheckOutlined, } from '@ant-design/icons';
import TableView from '@/components/TableView';
import downloadFile from "@/utils/download"
 
const { Link, Text } = Typography;
const appUrl = $$.appUrl;
 
function delFile(id) {
  return $$.ax.request({ url: `fileInfo/deleteFileById`, type: 'get', service: 'sys', data: { id } });
}
 
function deleteFileByIdApi(data) {
  return $$.ax.request({ url: `fileInfo/deleteFileByIds`, type: 'get', service: 'sys', data });
}
 
//表格数据
const staticTableData = [
  {
    ownerType: "22_00018-101",
    ownerTypeName: "申请材料",
    size: 0,
    fileNames: "-",
    updateTime: '',
    id: 1,
  },
  {
    ownerType: "22_00018-102",
    ownerTypeName: "证据材料",
    size: 0,
    fileNames: "-",
    updateTime: '',
    id: 2,
  },
]
 
/**
 * mainId*,//就是caseId,事件id
 * fileInfoList*, //文件列表
 * isReview,//是否查看,查看的话就不能删除上传,只能查看下载
 */
 
export default function FileTable(props) {
  const formRef = useRef();
  const [filesCheck, setFilesCheck] = useState(false);
  const [uploadVisible, setUpLoadVisible] = useState(false);
  const [tableData, setTableData] = useState(staticTableData);
  // 当前弹窗的ownerType
  const [sourceType, setSourceType] = useState();
  // 当前弹窗的文件对象
  const [fileMap, setFileMap] = useState({});
  const [fileInfoList, setFileInfoList] = useState([]);
 
  // 列配置
  const fakeColumns = [
    {
      title: '序号',
      dataIndex: 'caseNo',
      key: 'caseNo',
      width: 100,
      render: (text, record, index) => <span>{index + 1}</span>,
    },
    {
      title: '材料类型',
      dataIndex: 'ownerTypeName',
      key: 'ownerTypeName',
      width: 100,
    },
    {
      title: '材料数量',
      dataIndex: 'size',
      key: 'size',
      width: 180,
      render: (text) => <span>{text}份</span>,
 
    },
    {
      title: '材料名称',
      dataIndex: 'fileNames',
      key: 'fileNames',
      width: 180,
 
    },
    {
      title: '最新上传时间',
      dataIndex: 'updateTime',
      key: 'updateTime',
      width: 180,
    },
    {
      title: '操作',
      dataIndex: 'perClassName',
      key: 'perClassName',
      width: props.isReview ? 80 : 140,
      fixed: 'right',
      render: (text, record, index) => (
        <Space size="middle">
          {!props.isReview && <Link onClick={() => {
            console.log(record);
            setSourceType(record.ownerType)
            setUpLoadVisible(true)
            setFileInfoList(record.fileList)
            setTimeout(() => {
              formRef.current.setFieldValue('file', record.fileList)
            }, 0)
          }}>
            上传
          </Link>}
          {record.fileList?.length > 0 && (
            <Link onClick={() => {
              setSourceType(record.ownerType)
              setFilesCheck(true)
            }}>
              查看
            </Link>
          )}
          {record.fileList?.length > 0 && !props.isReview && !props.isEdit && <Link onClick={() => {
            if (record.fileList && record.fileList.length != 0) {
              console.log('record.fileList', record.fileList);
 
              let ids = record.fileList?.map(item => item.id).join(',')
              handleDelete(ids, record, index)
            } else {
              $$.info({ type: 'warning', content: '还没上传关于该材料的文件!' });
            }
          }}>
            删除
          </Link>}
          {record.fileList?.length > 0 && (<Link onClick={() => {
            if (record.fileList && record.fileList.length != 0) {
              let ids = record.fileList?.map(item => item.id).join(',')
              handleDownlod(ids)
            } else {
              $$.info({ type: 'warning', content: '还没上传关于该材料的文件!' });
            }
          }}>
            下载
          </Link>)}
 
        </Space>
      )
    },
    // 更多列配置...
  ];
  const fileType = [
    { value: '22_00018-101', label: '申请材料' },
    { value: '22_00018-102', label: '证据材料' },
  ]
 
  useEffect(() => {
    console.log(props.fileInfoList);
    if (props.fileInfoList && props.fileInfoList.length != 0) {
      //证明材料
      const applyFile = props.fileInfoList.find(item => item.ownerType == "22_00018-101")
      //证据材料
      const evidenceFile = props.fileInfoList.find(item => item.ownerType == "22_00018-102")
      setFileMap({
        '22_00018-101': applyFile?.fileList || [],
        '22_00018-102': evidenceFile?.fileList || []
      })
      const newList = tableData.map(item => {
        if (item.ownerType == '22_00018-101' && applyFile && applyFile.fileList) {
          return {
            ...item,
            size: applyFile.fileList?.length || 0,
            fileNames: applyFile.fileList?.map(item => item.name).join(','),
            updateTime: applyFile.fileList?.length > 0 ? $$.timeFormat(applyFile.fileList[applyFile.fileList.length - 1].updateTime) : '',
            fileList: applyFile.fileList.map(item => {
              return {
                ...item,
                uid: item.id,
                // name: item.trueName
              }
            })
          }
        }
        if (item.ownerType == '22_00018-102' && evidenceFile && evidenceFile.fileList) {
          return {
            ...item,
            size: evidenceFile.fileList?.length || 0,
            fileNames: evidenceFile.fileList?.map(item => item.name).join(','),
            updateTime: evidenceFile.fileList?.length > 0 ? $$.timeFormat(evidenceFile.fileList[evidenceFile.fileList.length - 1].updateTime) : '',
            fileList: evidenceFile.fileList.map(item => {
              return {
                ...item,
                uid: item.id,
                // name: item.trueName
              }
            })
          }
        }
        return item
      })
      setTableData(newList)
    }
  }, [props.fileInfoList])
 
  //上传弹窗判断用哪种种图标
  const personIconType = (v) => {
    switch (v) {
      case '22_00018-101':
        return [applyMaterials, applyMaterials_active,
        ];
      case '22_00018-102':
        return [evidenceMaterials, evidenceMaterials_active];
    }
  }
 
  //删除文件
  const handleDelFile = async (id) => {
    const res = await delFile(id)
    if (res.type) {
      $$.infoSuccess({ content: '删除成功!' });
      const data = fileMap[sourceType]?.filter(i => i.id !== id);
      console.log('data', data);
      const newList = tableData.map(item => {
        if (item.ownerType == sourceType) {
          return {
            ...item,
            size: data.length,
            fileNames: data?.map(item => item.name).join(','),
            updateTime: data.length > 0 && $$.timeFormat(data[data.length - 1].updateTime),
            id: item.id,
            fileList: data?.map(item => {
              return {
                ...item,
                // name: item.trueName,
                uid: item.id,
              }
            }),
          }
        } else {
          return item
        }
      })
      console.log('newList1111', newList);
      // console.log('fileMap', fileMap);
      // console.log('sourceType', sourceType);
      setTableData(newList)
      // setFileMap({ ...fileMap, [item.ownerType]: [] })
    }
  }
 
  //上传弹窗完成后的事件
  const handleUpload = () => {
    const newList = tableData.map(item => {
      if (item.ownerType == '22_00018-101') {
        const data = fileMap['22_00018-101'] || [];
        return {
          ...item,
          size: data.length,
          fileNames: data.map(item => item.name).join(','),
          updateTime: data.length > 0 ? $$.timeFormat(data[data.length - 1].updateTime) : '',
          id: item.id,
          fileList: data.map(item => {
            return {
              ...item,
              // name: item.trueName,
              uid: item.id,
            }
          }),
        }
      } else {
        const data1 = fileMap['22_00018-102'] || [];
        return {
          ...item,
          size: data1.length,
          fileNames: data1.map(item => item.name).join(','),
          updateTime: data1.length > 0 ? $$.timeFormat(data1[data1.length - 1].updateTime) : '',
          id: item.id,
          fileList: data1.map(item => {
            return {
              ...item,
              // name: item.trueName,
              uid: item.id,
            }
          }),
        }
      }
    })
    //回传文件数据的时候使用
    if (props.handleSaveList) {
      props.handleSaveList(newList)
    }
    setTableData(newList)
    setUpLoadVisible(false);
  };
 
  //根据sourceType生成组件
  const formType = (type) => {
 
    if (type === '22_00018-101') {
      //申请材料
      return (
        <div className='uploadFile'>
          <Col span={24} className='doubleFile'>
            <ArcoUpload
              params={{
                action: `${appUrl.fileUrl}/${appUrl.sys}/api/web/fileInfo/upload?mainId=${props.mainId}&&ownerId=${props.mainId}&ownerType=22_00018-101`,
              }}
              field='file'
              label=''
              editData={{
                file: fileMap['22_00018-101'] || []
              }}
              handleDelFile={handleDelFile}
              onFileListChange={(v) => {
                let newList = v?.map(item => {
                  if (item.response) {
                    return item.response.data[0]
                  } else {
                    return item
                  }
                })
                setFileMap({
                  ...fileMap,
                  '22_00018-101': newList.filter(i => i.ownerType === '22_00018-101')
                });
 
              }}
            />
            {fileMap['22_00018-101']?.length > 0 && <div style={{ position: 'absolute', top: '86px', left: '16px', color: '#86909C' }}>申请材料累计上传:<span style={{ color: '#1A6FB8' }}>{fileMap['22_00018-101']?.length}</span></div>}
          </Col>
        </div>
      )
    }
    if (type === '22_00018-102') {
      //证据材料
      return (
        <div className='uploadFile'>
          <Col span={24} className='doubleFile'>
            <ArcoUpload
              params={{
                action: `${appUrl.fileUrl}/${appUrl.sys}/api/web/fileInfo/upload?mainId=${props.mainId}&&ownerId=${props.mainId}&ownerType=22_00018-102`,
              }}
              field='file'
              label=''
              editData={{
                file: fileMap['22_00018-102'] || []
              }}
              handleDelFile={handleDelFile}
              onFileListChange={(v) => {
                let newList = v?.map(item => {
                  if (item.response) {
                    return item.response.data[0]
                  } else {
                    return item
                  }
                })
                setFileMap({
                  ...fileMap,
                  '22_00018-102': newList.filter(i => i.ownerType === '22_00018-102')
                })
              }}
            />
            {fileMap[['22_00018-102']]?.length > 0 && <div style={{ position: 'absolute', top: '86px', left: '16px', color: '#86909C' }}>证据材料累计上传:<span style={{ color: '#1A6FB8' }}>{fileMap['22_00018-102']?.length}</span></div>}
          </Col>
        </div>
      )
    }
  }
 
  //删除
  const handleDelete = (ids, record, index) => {
    Modal.confirm({
      title: '删除确认',
      content: '确认全部删除该材料?',
      onOk: async () => {
        const res = await deleteFileByIdApi({ ids })
        if (res.type) {
          $$.infoSuccess({ content: '删除成功!' });
          const newList = tableData.map((item, idx) => {
            if (index === idx) {
              return {
                fileNames: "-",
                id: record.id,
                ownerType: record.ownerType,
                ownerTypeName: record.ownerTypeName,
                size: 0,
                updateTime: ""
              };
            } else {
              return item
            }
          })
          console.log('newList1111', newList);
          console.log('fileMap', fileMap);
          console.log('sourceType', sourceType);
          setTableData(newList)
          setFileMap({ ...fileMap, [record.ownerType]: [] })
        }
      },
    });
  }
 
  //下载
  const handleDownlod = async (ids) => {
    await downloadFile(`${appUrl.fileUrl}/${appUrl.sys}/api/web/fileInfo/down/batch`, { ids })
  }
 
 
 
  return (
    <Fragment>
      <TableView
        key={tableData}
        columns={fakeColumns}
        dataSource={tableData}
        size="small"
        rowKey="ownerType"
        bordered={true}
        scroll={{ x: 1300 }}
        tableHeight={137}
      />
      <Modal
        // style={{ width: '512px' }}
        style={{ width: '1200px' }}
        visible={uploadVisible}
        onCancel={() => setUpLoadVisible(false)}
        footer={null}
        title='上传材料'
        centered
        mountOnEnter={false}
        unmountOnExit={true}
        maskClosable={false}
        focusLock={false}
      >
        <div style={{ paddingTop: '8px' }}>
          <Row gutter={[30, 24]}>
            {fileType.map((x, t) => {
              return (
                <Col span={12} key={t}>
                  <div
                    onClick={() => {
                      if (x.value !== sourceType) {
                        setSourceType(x.value);
                        formRef.current.setFieldValue('file', fileMap[x.value] || [])
                      }
                    }}
                    className={`casePerfection-cardTab-tab ${x.value === sourceType && 'casePerfection-cardTab-tabActive'}`}
                  >
                    <img src={x.value === sourceType ? personIconType(x.value)?.[1] : personIconType(x.value)?.[0]} alt="" style={{ width: '40px', height: '40px' }} />
                    <div style={{ fontWeight: 400 }} className="casePerfection-cardTab-tab-name">{x.label}</div>
                    {x.value === sourceType && (
                      <>
                        <div className="casePerfection-cardTab-tab-triangle" />
                        <CheckOutlined className="casePerfection-cardTab-tab-check" />
                      </>
                    )}
                  </div>
                </Col>
              );
            })}
            <Col span={24}>
              <Form
                ref={formRef}
                layout='vertical'
                requiredSymbol={false}
                initialValues={{
                }}//默认值
                style={{ position: 'relative' }}
              >
                <Row gutter={[32, 0]}>{formType(sourceType)}</Row>
              </Form>
            </Col>
            <Button type="primary" style={{ marginLeft: '16px' }} onClick={() => handleUpload()}>上传完成</Button>
          </Row>
        </div>
 
      </Modal>
      <Modal
        style={{ width: '1200px' }}
        visible={filesCheck}
        onCancel={() => setFilesCheck(false)}
        footer={null}
        title='查看事件材料'
        centered
        unmountOnExit={true}
        maskClosable={false}
      >
        <div style={{ marginTop: '-16px' }}>
          <NewFileCheck menuList={tableData} sourceType={sourceType} />
        </div>
      </Modal>
    </Fragment >
  )
}