广州市综治平台前端
xusd
2025-06-07 ee685c9f350ec9241107d4e8a05799768a0bce9a
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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-03-10 14:41:45
 * @LastEditTime: 2022-10-31 14:08:53
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: 案件材料展示Table
 * 附件类型对照
    NULL("22_00017-0","未分类"),
    AUDIO("22_00017-1", "音频"),
    VIDEO("22_00017-2", "视频"),
    IMAGE("22_00017-3", "图片"),
    WORD("22_00017-4", "Word文档"),
    EXCEL("22_00017-5", "Excel表格"),
    PDF("22_00017-6", "PDF"),
    TXT("22_00017-7", "txt文本"),
    ZIP("22_00017--8", "压缩文件"),
    POWERPOINT("22_00017-9", "PowerPoint"),
    UNKNOWN("22_00017-99", "其它文件");
 */
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Popconfirm, Image, Space, Typography, Tooltip } from 'antd';
import { PaperClipOutlined, DownloadOutlined, DeleteOutlined } from '@ant-design/icons';
import TableView from '../TableView';
import * as $$ from '../../utils/utility';
import './index.less';
 
const { Link } = Typography;
 
function deleteFile(fileId) {
    return $$.ax.request({ url: `fileInfo/deleteById?id=${fileId}`, type: 'get', service: 'sys' });
}
 
/**
 * isCheck, // 是否是查看模式
 * isList, // 单个案件类型模式
 * data, // 附件数据[{fileList:[]}]
 * handleSuccessDelFile, // 删除文件成功后回调
 * columnsContral: bool // 判断是否展示出所有的文件,包括未上传文件展示为0
 * description, // 空的说明文字
 */
const FilesTable = ({ isCheck = false, isList = false, data = [], handleSuccessDelFile, columnsContral, rowKey, description = '无数据' }) => {
    let appUrl = $$.appUrl;
 
    // 单个预览图片控制
    const [imgVisible, setImgVisible] = useState({ visible: false, src: '' });
 
    // 正常展示已存在的文件
    const columns = () => {
        let rows = {};
        let index = 0;
        data?.forEach((x) => {
            rows[index] = x.fileList.length;
            index = index + x.fileList.length;
        });
        let columnsArr = [
            {
                title: '序号',
                dataIndex: 'serialNumber',
                width: 50,
                onCell: (_, index) => ({ rowSpan: rows[index] || 0 }),
            },
            {
                title: '材料类型',
                dataIndex: 'ownerTypeName',
                onCell: (_, index) => ({ rowSpan: rows[index] || 0 }),
            },
            {
                title: '材料数量',
                dataIndex: 'num',
                width: 100,
                render: (_, __, index) => `${rows[index]}份`,
                onCell: (_, index) => ({ rowSpan: rows[index] || 0 }),
            },
            {
                title: '材料名称',
                dataIndex: 'name',
                render: (text, record) => <Link onClick={() => handleOpenFiles(record)}>{text}</Link>,
            },
            {
                title: '上传时间',
                dataIndex: 'createTime',
                render: (text) => $$.timeFormat(text),
            },
            {
                title: '操作',
                dataIndex: 'action',
                width: 150,
                render: (_, record, index) => {
                    return (
                        <Space size="middle">
                            <Link onClick={() => window.open(`/#/mediate/case/filesCheck?caseId=${record.ownerId}&fileId=${record.id}`)}>查看</Link>
                            <Link onClick={() => handleDownloadFiles(record)}>下载</Link>
                            {!isCheck && (
                                <Popconfirm title="确认删除该材料吗?" onConfirm={() => handleDeleteFile(record, index)}>
                                    <Link>删除</Link>
                                </Popconfirm>
                            )}
                        </Space>
                    );
                },
            },
        ];
        return columnsArr;
    };
 
    // 展示固定的文件包含未上传文件
    const columnsSec = () => {
        let rows = {};
        let index = 0;
        data?.forEach((x) => {
            rows[index] = x.fileList.length || 1;
            index = index + (x.fileList.length || 1);
        });
        let columnsArr = [
            { title: '序号', dataIndex: 'serialNumber', width: 50, onCell: (_, index) => ({ rowSpan: rows[index] || 0 }) },
            {
                title: '材料类型',
                dataIndex: 'ownerTypeName',
                render: (text, record) => {
                    return (
                        <>
                            {record.ownerType === '22_00018-302' ? (
                                <Tooltip title="已自动帮您上传调解协议书">
                                    <div>
                                        {text}
                                        <span className="leftRequired">*</span>
                                    </div>
                                </Tooltip>
                            ) : record.ownerType === '22_00018-402' ? (
                                <div>
                                    {text}
                                    <span className="leftRequired">*</span>
                                </div>
                            ) : (
                                <span>{text}</span>
                            )}
                        </>
                    );
                },
                onCell: (_, index) => ({ rowSpan: rows[index] || 0 }),
            },
            {
                title: '材料数量',
                dataIndex: 'num',
                width: 80,
                render: (text, _, index) => (parseInt(text) !== 0 ? `${rows[index]}份` : '0份'),
                onCell: (_, index) => ({ rowSpan: rows[index] || 0 }),
            },
            {
                title: '状态',
                dataIndex: 'status',
        width: 80,
                render: (text) => (parseInt(text) === 0 ? '未上传' : '已上传'),
            },
            {
                title: '材料名称',
                dataIndex: 'name',
                render: (text, record) => <Link onClick={() => handleOpenFiles(record)}>{text}</Link>,
            },
            {
                title: '上传时间',
                dataIndex: 'createTime',
                render: (text) => $$.timeFormat(text),
            },
            {
                title: '操作',
                dataIndex: 'action',
                width: 150,
                render: (_, record, index) => {
                    return (
                        <Space size="middle">
                            {parseInt(record?.num) !== 0 && (
                                <>
                                    <Link onClick={() => window.open(`${$$.isDebug ? '' : 'hgdyh/pc'}/bydyh/pc/index.html#/mediate/case/filesCheck?caseId=${record.ownerId}`)}>查看</Link>
                                    <Link onClick={() => handleDownloadFiles(record)}>下载</Link>
                                    {!isCheck && (
                                        <Popconfirm title="确认删除该材料吗?" onConfirm={() => handleDeleteFile(record, index)}>
                                            <Link>删除</Link>
                                        </Popconfirm>
                                    )}
                                </>
                            )}
                        </Space>
                    );
                },
            },
        ];
 
        return columnsArr;
    };
 
    // table数据处理便于展示
    const files = () => {
        let arr = [];
        data?.forEach((x, t) => {
            let fileList = x.fileList || [];
            if (fileList.length > 0) {
                fileList[0].serialNumber = t + 1;
            } else if (columnsContral) {
                fileList = {
                    serialNumber: t + 1,
                    ownerTypeName: x.ownerTypeName,
                    ownerType: x.ownerType,
                    name: '-',
                    num: 0,
                };
            }
            arr = arr.concat(fileList || []);
        });
        return arr;
    };
 
    // 删除文件
    async function handleDeleteFile(record, index) {
        global.setSpinning(true);
        const res = await deleteFile(record.id);
        global.setSpinning(false);
        if (res.type) {
            $$.infoSuccess({ content: '删除成功' });
            handleSuccessDelFile(record, index);
        }
    }
 
    // 查看单个文件
    function handleOpenFiles(record) {
        let file = record;
        const { response } = record;
        if (response) {
            file = response.data[0];
        }
        if (file.cat === '22_00017-3') {
            setImgVisible({ visible: true, src: `${appUrl.fileUrl}${appUrl.fileShowUrl}${file.id}` });
        } else if (file.cat === '22_00017-6' || file.cat === '22_00017-1' || file.cat === '22_00017-2') {
            window.open(`${appUrl.fileUrl}${appUrl.fileShowUrl}${file.id}`);
        } else {
            $$.info({ type: 'warning', content: '抱歉,暂不支持在线查看,已下载请查看' });
            window.open(`${appUrl.fileUrl}${appUrl.fileDownUrl}${file.id}`);
        }
    }
 
    // 下载单个文件
    function handleDownloadFiles(record) {
        let file = record;
        const { response } = record;
        if (response) {
            file = response.data[0];
        }
        window.open(`${appUrl.fileUrl}${appUrl.fileDownUrl}${file.id}`);
    }
 
    return (
        <>
            {isList ? (
                // 列表模式
                <div>
                    {data?.map((x, t) => {
                        return (
                            <div className="filesTable-fileLi" key={t}>
                                <PaperClipOutlined className="filesTable-fileLi-icon" />
                                <div className="filesTable-fileLi-name" onClick={() => handleOpenFiles(x)}>
                                    {x.name}
                                </div>
                                <Space size="middle">
                                    {!isCheck && (
                                        <span className="filesTable-fileLi-iconDelete" onClick={() => handleDeleteFile(x, t)}>
                                            <DeleteOutlined />
                                        </span>
                                    )}
                                    <span className="filesTable-fileLi-iconA" onClick={() => handleDownloadFiles(x)}>
                                        <DownloadOutlined />
                                    </span>
                                </Space>
                            </div>
                        );
                    })}
                    {(!data || data.length === 0) && $$.MyEmpty({ description })}
                </div>
            ) : (
                // table模式
                <TableView
                    columns={columnsContral ? columnsSec() : columns()}
                    dataSource={files()}
                    rowKey={rowKey || 'id'}
                    pagination={false}
                    scroll={{ y: 300 }}
                />
            )}
            <div style={{ display: 'none' }}>
                <Image
                    src={imgVisible.src}
                    preview={{
                        visible: imgVisible.visible,
                        src: imgVisible.src,
                        onVisibleChange: () => setImgVisible({ visible: false }),
                    }}
                />
            </div>
        </>
    );
};
 
FilesTable.propTypes = {
    isCheck: PropTypes.bool,
    isList: PropTypes.bool,
    data: PropTypes.array,
    handleSuccessDelFile: PropTypes.func,
    columnsContral: PropTypes.bool,
    description: PropTypes.string,
};
 
export default FilesTable;