董国庆
昨天 95ac9029c648194c35dda58daaa17b9160bcb69d
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
import { buildProTableDataSource, sendRequest, showDelConfirm } from '@/utils/antdUtils';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { Button, Card, Select, Space, Descriptions, Divider, Steps, message, Modal, Form, Input, Upload, Popconfirm } from 'antd';
import { useRef, useState, useEffect } from 'react';
import { Access, useAccess } from 'umi'
import { history, useLocation } from "@umijs/max"
import { getDetail, editProgress, deleteProgress } from './service';
import moment from 'moment';
import './index.less';
import {downLoad, customRequest } from '@/utils/utils';
import { PlusOutlined } from '@ant-design/icons';
 
const Account = () => {
    const actionRef = useRef();
    const addViewRef = useRef();
    const [current, setCurrent] = useState(0);
    const [detail, setDetail] = useState({});
    const searchParams = new URLSearchParams(useLocation().search);
    const id = searchParams.get('id');
    const [editModalVisible, setEditModalVisible] = useState(false);
    const [editProgressData, setEditProgressData] = useState(null);
    const [editForm] = Form.useForm();
    const [loading, setLoading] = useState(false);
    const [imgFileList, setImgFileList] = useState([]);
    const [videoFileList, setVideoFileList] = useState([]);
    const [previewVisible, setPreviewVisible] = useState(false);
    const [previewImage, setPreviewImage] = useState('');
    const [previewType, setPreviewType] = useState('image'); // 'image' or 'video'
    const uploadConfig = {
        name: 'file',
        action: 'https://huacheng.psciio.com/api/huacheng-communitybackstage/communitypartybuilding/uploadimage',
        headers: {
            Authorization: 'Bearer ' + localStorage.getItem('token'),
        },
    };
 
    useEffect(() => {
        getDetail({ id: id }).then((res) => {
            setDetail(res.data);
        });
    }, []);
 
    const items = [
        {
            key: '1',
            label: '述求状态',
            children: ['正在办理', '延期办理', '超时办理', '已办结', '待审核', '上报待审核'][detail.status] || '已办结',
        },
        {
            key: '2',
            label: '述求号',
            children: detail.serialNumber,
        },
        {
            key: '3',
            label: '',
            children: '',
        },
        {
            key: '4',
            label: '',
            children: '',
        },
        {
            key: '5',
            label: '发生时间',
            children: moment(detail.time).format('YYYY-MM-DD HH:mm:ss'),
        },
        {
            key: '6',
            label: '问题类型',
            children: detail.problemType,
        },
        {
            key: '7',
            label: '群众姓名',
            children: detail.name,
        },
        {
            key: '8',
            label: '联系电话',
            children: detail.contactNumber,
        },
        {
            key: '9',
            label: '发生地点',
            children: detail.location,
        },
        {
            key: '10',
            label: '详细地址',
            children: detail.detailedAddress,
        },
        {
            key: '11',
            label: '录入人',
            children: detail.reportUserName,
        },
        {
            key: '12',
            label: '联系电话',
            children: detail.reportUserPhone,
        },
        {
            key: '13',
            label: '问题描述',
            children: detail.descriptionContent,
            span: 4,
        },
        {
            key: '14',
            label: '上传图片',
            children: <>
                {detail.images && (detail.images || '').split(',').map((item, index) => (
                    <img width={80} height={80} src={item} key={index} alt="example" />
                ))}
            </>,
            span: 4,
        },
        {
            key: '15',
            label: '上传视频',
            children: <>
                {detail.videos && (detail.videos || '').split(',').map((item, index) => (
                    <video width={280} src={item} key={index} controls></video>
                ))}
            </>,
            span: 4,
        },
    ];
 
    // 上传前校验
    const beforeUpload = (file) => {
        return new Promise((resolve, reject) => {
            if (file.name.includes(',')) {
                message.warning('上传文件不能包含英文逗号(,)');
                return Upload.LIST_IGNORE;
            }
            setLoading(true);
            resolve(file);
        });
    };
 
    // 图片上传change
    const handleImgChange = ({ file, fileList: newFileList }) => {
        if (file.status === 'error' || (file.status === 'done' && file.response && file.response.code !== 200)) {
            setLoading(false);
            setImgFileList([]);
            message.error('上传失败');
            editForm.setFieldValue('imgUrl', []);
            return;
        }
        if (file.status === 'done' && file.response && file.response.code === 200) {
            setLoading(false);
            message.success('上传成功');
        }
        let urls = newFileList.map(item => {
            if (item.status === 'done' && item.response && item.response.data) {
                item.url = item.response.data;
            }
            return item.url || item.url;
        }).filter(Boolean);
        setImgFileList(newFileList);
        editForm.setFieldValue('imgUrl', urls);
    };
 
    // 视频上传change
    const handleVideoChange = ({ file, fileList: newFileList }) => {
        if (file.status === 'error' || (file.status === 'done' && file.response && file.response.code !== 200)) {
            setLoading(false);
            setVideoFileList([]);
            message.error('上传失败');
            editForm.setFieldValue('videoUrl', []);
            return;
        }
        if (file.status === 'done' && file.response && file.response.code === 200) {
            setLoading(false);
            message.success('上传成功');
        }
        let urls = newFileList.map(item => {
            if (item.status === 'done' && item.response && item.response.data) {
                item.url = item.response.data;
            }
            return item.url || item.url;
        }).filter(Boolean);
        setVideoFileList(newFileList);
        editForm.setFieldValue('videoUrl', urls);
    };
 
    // 办理进度编辑提交
    const handleEditProgress = async () => {
        try {
            setLoading(true);
            console.log('editProgressData', editProgressData);
            
            const values = await editForm.validateFields();
            await editProgress({
                complaintId: id,
                describe: values.describe,
                id: editProgressData.id,
                imgUrl: (values.imgUrl || []).join(','),
                video: (values.videoUrl || []).join(',')
            });
            message.success('编辑成功');
            setEditModalVisible(false);
            getDetail({ id }).then((res) => setDetail(res.data));
        } catch (e) {
            // 校验或请求失败
        } finally {
            setLoading(false);
        }
    };
 
    // 办理进度删除
    const handleDeleteProgress = async (progressId) => {
        try {
            await deleteProgress({ id: progressId });
            message.success('删除成功');
            getDetail({ id }).then((res) => setDetail(res.data));
        } catch (e) {
            message.error('删除失败');
        }
    };
 
    // 在弹窗打开时同步 fileList
    useEffect(() => {
        if (editModalVisible && editProgressData) {
            setImgFileList((editProgressData.imgUrl ? editProgressData.imgUrl.split(',') : []).map((url, idx) => ({ uid: idx, url, status: 'done' })));
            setVideoFileList((editProgressData.video ? editProgressData.video.split(',') : []).map((url, idx) => ({ uid: idx, url, status: 'done' })));
            editForm.setFieldsValue({
                describe: editProgressData.describe,
                imgUrl: editProgressData.imgUrl ? editProgressData.imgUrl.split(',') : [],
                videoUrl: editProgressData.video ? editProgressData.video.split(',') : [],
            });
        }
        if (!editModalVisible) {
            setImgFileList([]);
            setVideoFileList([]);
        }
    }, [editModalVisible, editProgressData]);
 
    return (
        <div>
            <PageContainer className={'appeal-management-detail'} header={{ breadcrumb: {} }} title="述求详情" >
                <Card>
                    <Descriptions column={4} title="基础信息" items={items} />
                    <Divider />
                    <div>
                        <Descriptions title="办理进度" column={1}>
                            {detail.complaintProgresses?.length > 0 ? detail.complaintProgresses.map((item, index) => (
                                <Descriptions.Item key={index}>
                                    <Card style={{ width: '800px', position: 'relative' }} title={item.createByName} extra={moment(item.createTime).format('YYYY-MM-DD HH:mm:ss')}>
                                        <Descriptions column={1} >
                                            <Descriptions.Item>{item.describe}</Descriptions.Item>
                                            <Descriptions.Item label={'上传图片'}>
                                                {item.imgUrl && (item.imgUrl || '').split(',').map((img, idx) => (
                                                    <img width={80} style={{ marginRight: '10px' }} height={80} src={img} key={idx} alt="example" />
                                                ))}
                                            </Descriptions.Item>
                                            <Descriptions.Item label={'上传视频'}>
                                                {item.video && item.video.split(',').map((video, idx) => (
                                                    <video width={280} style={{ marginRight: '10px' }} src={video} key={idx} controls></video>
                                                ))}
                                            </Descriptions.Item>
                                        </Descriptions>
                                        <div style={{ position: 'absolute', right: 24, bottom: 16 }}>
                                            <Button size="small" type="primary" style={{ marginRight: 8 }} onClick={() => {
                                                setEditProgressData(item);
                                                setEditModalVisible(true);
                                                editForm.setFieldsValue({
                                                    describe: item.describe,
                                                    imgUrl: item.imgUrl ? item.imgUrl.split(',') : [],
                                                    videoUrl: item.video ? item.video.split(',') : [],
                                                });
                                            }}>编辑</Button>
                                            <Popconfirm title="确定要删除该办理进度吗?" onConfirm={() => handleDeleteProgress(item.id)} okText="确定" cancelText="取消">
                                                <Button size="small" danger>删除</Button>
                                            </Popconfirm>
                                        </div>
                                    </Card>
                                </Descriptions.Item>
                            )) : <Descriptions.Item span={4} >暂无办理进度</Descriptions.Item>}
                        </Descriptions>
                    </div>
 
                    <Divider />
                    {detail.complaintFlows?.length > 0 && <><Descriptions title="述求流转" >
 
                        <Descriptions.Item span={4}>
                            <div style={{ width: '100%', overflowX: 'auto' }}   >
                                <Steps size="small"  >
                                    {detail.complaintFlows && detail.complaintFlows.map((item, index) => (
                                        <Steps.Item status={'process'} key={index} title={item.name} description={<span>{item.type == 1 ? '下派' : '上报'} <span>{moment(item.createTime).format('YYYY-MM-DD HH:mm:ss')}</span> </span>} />
                                    ))}
                                </Steps>
                            </div>
                        </Descriptions.Item>
                    </Descriptions>
                        <Divider /></>}
                    {[3, 4].includes(detail.status) &&
                        <Descriptions title="办结情况" >
                            <Descriptions.Item span={4}>
                                <Card style={{ width: '800px' }} extra={<div style={{ width: '750px', display: 'flex', justifyContent: 'space-between' }}>
                                    <span>办结时间:{moment(detail.completionTime).format('YYYY-MM-DD HH:mm:ss')}</span>
                                    <span>办结人员:{detail.completionUsername}</span>
                                    <span>联系电话:{detail.completionUserPhone}</span>
                                </div>}>
                                    <Descriptions column={1} >
                                        <Descriptions.Item>
                                            {detail.completionDescription}
                                        </Descriptions.Item>
                                        <Descriptions.Item label={'上传图片'}>
                                            {detail.completionImages && detail.completionImages.split(',').map((item, index) => (
                                                <img width={80} height={80} style={{ marginRight: '10px' }} src={item} key={index} alt="example" />
                                            ))}
                                        </Descriptions.Item>
                                        <Descriptions.Item label={'上传视频'}>
                                            {detail.completionVideos && detail.completionVideos.split(',').map((item, index) => (
                                                <video width={280} style={{ marginRight: '10px' }} src={item} key={index} controls></video>
                                            ))}
                                        </Descriptions.Item>
                                    </Descriptions>
                                </Card>
                            </Descriptions.Item>
                        </Descriptions>}
                    {detail.complaintComment &&
                        <Descriptions title="办结评价" style={{ marginTop: '20px' }} >
                            <Descriptions.Item span={4}> 
                                <Card style={{ width: '800px' }} extra={<div style={{ width: '750px', display: 'flex', justifyContent: 'flex-start' }}>
                                    <span>评价打分:{['不满意', '一般', '满意', '非常满意'][detail.complaintComment?.rate]}</span>
                                </div>}>
                                    <Descriptions column={1} >
                                        <Descriptions.Item>
                                            {detail.complaintComment?.content}
                                        </Descriptions.Item>
                                        <Descriptions.Item label={'上传图片'}>
                                            {detail.complaintComment?.imgUrl && detail.complaintComment?.imgUrl.split(',').map((item, index) => (
                                                <img width={80} height={80} style={{ marginRight: '10px' }} src={item} key={index} alt="example" />
                                            ))}
                                        </Descriptions.Item>
                                        <Descriptions.Item label={'上传视频'}>
                                            {detail.complaintComment?.video && detail.complaintComment?.video.split(',').map((item, index) => (
                                                <video width={280} style={{ marginRight: '10px' }} src={item} key={index} controls></video>
                                            ))}
                                        </Descriptions.Item>
                                    </Descriptions>
                                </Card>
                            </Descriptions.Item>
                        </Descriptions>
                    }
 
 
                    <div style={{ marginTop: '20px', display: 'flex', justifyContent: 'center' }}>
                        <Button onClick={() => {
                            try {
                                history.go(-1);
                            } catch (error) {
                                message.error('返回失败,请重试');
                                console.error('Navigation error:', error);
                            }
                        }} style={{ marginRight: '20px' }}  >关闭</Button>
                        <Button type="primary" onClick={() => {
                            try {
                                downLoad(`/api/huacheng-sangeshenbian/complaint/download-file/${id}/1`, '社区问题单导出.docx');
                                // TODO: Implement export functionality
                                message.success('导出成功');
                            } catch (error) {
                                message.error('导出失败,请重试');
                                console.error('Export error:', error);
                            }
                        }} style={{ marginRight: '20px' }}>社区问题单导出</Button>
                        <Button type="primary" onClick={() => {
                                try {
                                downLoad(`/api/huacheng-sangeshenbian/complaint/download-file/${id}/2`, '问题处理单导出.docx');
                                // TODO: Implement export functionality
                                message.success('导出成功');
                            } catch (error) {
                                message.error('导出失败,请重试');
                                console.error('Export error:', error);
                            }
                        }} style={{ marginRight: '20px' }}>问题处理单导出</Button>
                        <Button type="primary" onClick={() => {
                            try {
                                downLoad(`/api/huacheng-sangeshenbian/complaint/download-file/${id}/3`, '协调通知单导出.docx');
                                // TODO: Implement export functionality
                                message.success('导出成功');
                            } catch (error) {
                                message.error('导出失败,请重试');
                                console.error('Export error:', error);
                            }
                        }} >协调通知单导出</Button>
                    </div>
                </Card>
 
                <Modal
                    title="编辑办理进度"
                    open={editModalVisible}
                    onCancel={() => setEditModalVisible(false)}
                    onOk={handleEditProgress}
                    confirmLoading={loading}
                    destroyOnClose
                    width={600}
                >
                    <Form form={editForm} layout="vertical" initialValues={{ describe: '', imgUrl: [], videoUrl: [] }}>
                        <Form.Item name="describe" label="办理进度描述" rules={[{ required: true, message: '请输入办理进度描述' }]}> 
                            <Input.TextArea rows={4} maxLength={500} showCount />
                        </Form.Item>
                        <Form.Item name="imgUrl" label="图片:">
                            <Upload
                                {...uploadConfig}
                                listType="picture-card"
                                maxCount={9}
                                beforeUpload={beforeUpload}
                                onChange={handleImgChange}
                                onRemove={() => {
                                    setImgFileList([]);
                                    editForm.setFieldValue('imgUrl', []);
                                }}
                                showUploadList={{ showPreviewIcon: true }}
                                accept="image/*"
                                fileList={imgFileList}
                                onPreview={file => {
                                    setPreviewType('image');
                                    setPreviewImage(file.url || file.thumbUrl);
                                    setPreviewVisible(true);
                                }}
                            >
                                {imgFileList.length < 9 && <PlusOutlined />}
                            </Upload>
                        </Form.Item>
                        <Form.Item name="videoUrl" label="视频:">
                            <Upload
                                {...uploadConfig}
                                listType="picture-card"
                                maxCount={9}
                                beforeUpload={beforeUpload}
                                onChange={handleVideoChange}
                                onRemove={() => {
                                    setVideoFileList([]);
                                    editForm.setFieldValue('videoUrl', []);
                                }}
                                showUploadList={{ showPreviewIcon: true }}
                                accept="video/*"
                                fileList={videoFileList}
                                onPreview={file => {
                                    setPreviewType('video');
                                    setPreviewImage(file.url || file.thumbUrl);
                                    setPreviewVisible(true);
                                }}
                            >
                                {videoFileList.length < 9 && <PlusOutlined />}
                            </Upload>
                        </Form.Item>
                    </Form>
                </Modal>
 
                <Modal
                    open={previewVisible}
                    footer={null}
                    onCancel={() => setPreviewVisible(false)}
                    width={previewType === 'video' ? 800 : 600}
                >
                    {previewType === 'image' ? (
                        <img alt="预览" style={{ width: '100%' }} src={previewImage} />
                    ) : (
                        <video style={{ width: '100%' }} src={previewImage} controls autoPlay />
                    )}
                </Modal>
            </PageContainer>
        </div>
    );
};
 
export default Account;