forked from gzzfw/frontEnd/gzDyh

zhangyongtian
2024-09-08 f7452b9d6295748c9840245d26df6514e8ed2c1d
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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2023-02-08 14:24:37
 * @LastEditTime: 2024-08-09 16:29:11
 * @LastEditors: dminyi 1301963064@qq.com
 * @Version: 1.0.0
 * @Description: 司法局审核
 */
import React, { useState, useEffect } from 'react';
import './index.less';
import { useNavigate, useLocation, useSearchParams } from 'react-router-dom';
import { Col, Form, Input, Row, Select, Space, Table, Typography, Button } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';
import Page from '../../../components/Page';
import TableView from '../../../components/TableView';
import TableSearch from '../../../components/TableSearch';
import {
    ax,
    changeTimeFormat,
    clearSessionStorage,
    dateFormat,
    getSessionStorage,
    infoSuccess,
    modalInfo,
    myMoment,
    setSessionStorage,
} from '../../../utils/utility';
import MyModal from '../../../components/MyModal';
import publicDataStatus from '../../../status/publicData';
import * as $$ from '../../../utils/utility';
 
const { Link } = Typography;
 
const { TextArea } = Input;
 
function getDataApi(submitData) {
    return ax.request({ url: 'rmtj/pageEndAudit', type: 'get', data: submitData, service: 'mediate' });
}
 
// 获取审核记录
function getExamineHistoryApi(applyId) {
    return ax.request({ url: `rmtj/listAuditHis?applyId=${applyId}`, type: 'get', service: 'mediate' });
}
 
// 审核 or 批量审核
function examineApi(submitData) {
    return ax.request({ url: submitData.applyId ? 'rmtj/endApplyAudit' : 'rmtj/batchEndApplyAudit', type: 'post', data: submitData, service: 'mediate' });
}
 
// 移除 or 批量移除
function removeApi(submitData) {
    return ax.request({
        url: Array.isArray(submitData) ? 'rmtj/batchReSendRmtj' : 'rmtj/reSendRmtj',
        type: Array.isArray(submitData) ? 'post' : 'get',
        data: submitData,
        service: 'mediate',
    });
}
 
 
const JudicialExamine = () => {
    const location = useLocation();
 
    const navigate = useNavigate();
 
    const [searchParams] = useSearchParams();
 
    const [form] = Form.useForm();
 
    // 调解组织select框数据
    const [adjustOrgData, setAdjustOrgData] = useState([]);
 
    // 搜索
    const [search, setSearch] = useState({ page: 1, size: 10 });
 
    // 数据
    const [data, setData] = useState({ tableData: [] });
 
    const [modal, setModal] = useState({ visible: false, submit: {} });
 
    // 审核记录
    const [examineHis, setExamineHis] = useState([]);
 
    // table选择数据
    const [selectedRowsObj, setSelectedRowsObj] = useState({});
 
    function handleGetSelectedRowKeys(type) {
        let arr = [];
        for (let item in selectedRowsObj) {
            arr = arr.concat(selectedRowsObj[item][type]);
        }
        return arr;
    }
    const selectedRowKeys = handleGetSelectedRowKeys('selectedRowKeys');
 
    const columns = [
        { title: '调解案号', dataIndex: 'caseNo' },
        {
            title: '调解结果',
            dataIndex: 'mediResultName',
            render: (text, record) =>
                !text ? '-' : <div className={`public-tag public-tag-${record.mediResult === '22_00025-1' ? 'tagGreen' : 'tagRed'}`}>{text}</div>,
        },
        { title: '调解组织', dataIndex: 'mediateUnitName' },
        { title: '调解员', dataIndex: 'mediator' },
        { title: '申请人', dataIndex: 'plaintiffs' },
        { title: '被申请人', dataIndex: 'defendants' },
        { title: '纠纷发生地', dataIndex: 'addr' },
        { title: '纠纷类型', dataIndex: 'caseTypeName' },
        { title: '申请渠道', dataIndex: 'canalName' },
        {
            title: '初审结果',
            dataIndex: 'firstAuditResultName',
            render: (text, record) =>
                !text ? '-' :
                    record.firstAuditResult === '0' ? text :
                        <div className={`public-tag public-tag-${record.firstAuditResult === '1' ? 'tagGreen' : 'tagRed'}`}>{text}</div>
        },
        { title: '提审时间', dataIndex: 'applyTime' },
        {
            title: '终审结果',
            dataIndex: 'endAuditResultName',
            render: (text, record) =>
                !text ? '-' :
                    record.endAuditResult === '0' ? text :
                        <div className={`public-tag public-tag-${record.endAuditResult === '1' ? 'tagGreen' : 'tagRed'}`}>{text}</div>
        },
        {
            title: '转入结果',
            dataIndex: 'rmtjStatusName',
            render: (text, record) =>
                !text ? '-' :
                    record.rmtjStatus === '1' || record.rmtjStatus === '2' ? text :
                            <div className={`public-tag public-tag-${record.rmtjStatus === '3' ? 'tagBlue2' : 'tagRed'}`}>{text}</div>
        },
        { title: '转入案号', dataIndex: 'rmtjCaseId' },
        {
            title: '操作',
            dataIndex: 'action',
            width: 120,
            render: (_, record) => (
                <Space>
                    <Link onClick={() => handleCheck(record)}>查看</Link>
                    {record.endAuditResult !== '1' && 
                    <Link onClick={() => getExamineHistory(record)}>{record.endAuditResult === '0' ? '审核' : '重审'}</Link>}
                    {record.rmtjStatus === '4' && 
                    <Link onClick={() => handleRemove(record, 'one')}>重转</Link>}
                </Space>
            ),
        },
    ];
 
    // 查看
    function handleCheck(record) {
        setSessionStorage(location.pathname, {
            search,
            title: record.caseNo,
            breadcrumbData: [{ title: '司法局审核', url: location.pathname }, { title: '查看' }],
            tableActive: record.id,
            pageFrom: 'mediateAll',
        });
        navigate(`/mediate/caseDetail?caseId=${record.id}&judicialId=${record.judicId}&back=${location.pathname}`);
    }
 
    function handleChangeInput(key, value) {
        if (Array.isArray(key)) {
            modal.submit[key[0]] = value[0];
            modal.submit[key[1]] = value[1];
        } else {
            modal.submit[key] = value;
        }
        setModal({ ...modal });
    }
 
    // 搜索 or 重置
    function handleSearch(type, data, tableActive) {
        if (type === 'recovery') {
            let obj = { ...data };
            if (obj.applyTime) {
                obj.applyTime = [myMoment(obj.applyStart), myMoment(obj.applyEnd)];
            }
            form.setFieldsValue(obj);
            getData(data, tableActive);
            return;
        }
        if (type === 'reset') {
            form.resetFields();
            getData({ page: 1, size: 10 });
            return;
        }
        if (type === 'search' || type === 'changePage') {
            let values = form.getFieldsValue();
            changeTimeFormat(values, 'applyTime', 'applyStart', 'applyEnd');
            let obj = type === 'changePage' ? { page: data[0], size: data[1] } : { page: 1 };
            getData({ ...search, ...values, ...obj });
        }
    }
 
    // 获取数据
    async function getData(submitData, tableActive) {
        global.setSpinning(true);
        const res = await getDataApi(submitData);
        global.setSpinning(false);
        if (res.type) {
            setData({ total: res.data.totalElements, tableData: res.data.content, tableActive });
            setSearch(submitData);
        }
    }
 
    // 获取审核记录
    async function getExamineHistory(record) {
        global.setSpinning(true);
        const res = await getExamineHistoryApi(record.applyId);
        global.setSpinning(false);
        if (res.type) {
            setExamineHis(res.data || []);
            setModal({ visible: true, title: record.caseNo, submit: { applyId: record.applyId, auditResult: '1', auditResultName: '同意' } });
        }
    }
 
    // 审核
    async function handleExamine() {
        global.setSpinning(true);
        const res = await examineApi(modal.submit);
        global.setSpinning(false);
        if (res.type) {
            infoSuccess({ content: '审核成功' });
            setModal({ visible: false });
            getData(search);
        }
    }
 
    // 移除
    function handleRemove(record, type) {
        modalInfo({
            title: '重转确认',
            content: type === 'one' ? `是否将${record.caseNo}重新转入人民调解系统?` : `是否将${selectedRowKeys.length}个案件重新转入人民调解系统?`,
            okText: '确认重转',
            onOk: async () => {
                global.setSpinning(true);
                const res = await removeApi(type === 'one' ? { applyId: record.applyId } : selectedRowKeys);
                global.setSpinning(false);
                if (res.type) {
                    infoSuccess({ content: '重转成功' });
                    getData(search);
                }
            },
        });
    }
 
    function downloadXls() {
        window.open(`https://zfw-dyh.by.gov.cn/dyh-mediate/api/v1/caseOut/rmtj/selectExcels?caseIds=${selectedRowKeys}`);
    };
 
    function downloadFile() {
        // let caseIds = selectedRowKeys.map(({ caseId }) => caseId).join(',');
        window.open(`https://zfw-dyh.by.gov.cn/dyh-mediate/api/v1/caseOut/rmtj/selectFiles?caseIds=${selectedRowKeys}`);
    };
 
    // 导出查询结果
    async function searchTotal() {
        let list = data.tableData || [];
        if (list.length == 0) {
            $$.info({ type: 'error', content: '暂无数据可以导出' });
        } else {
            $$.modalInfo({
                title: '导出查询结果确认',
                content: <span>确认导出当前查询结果包含的<span className='ledger-main-title'>全部案件信息</span> 吗?</span>,
                okText: '确定导出',
                cancelText: '我再想想',
                onOk: async () => {
                    // console.log('search', object.keys(search));
                    let data = JSON.parse(JSON.stringify(search));
                    let params = $$.getQueryObj(data);
                    let userId = $$.getLocal('customerSystemUser')?.userId;
                    window.location.href = `${$$.appUrl.baseUrl}/${$$.appUrl.mediate}/api/v1/caseOut/rmtj/outQueryEnd?${params}userId=${userId}`;
                },
            });
        }
    }
 
    // 初始化
    useEffect(() => {
        publicDataStatus.getUnitData((data) => setAdjustOrgData(data));
        let returnRouteData = getSessionStorage(location.pathname);
        if (searchParams.get('isBack') && !!returnRouteData) {
            handleSearch('recovery', returnRouteData.search, returnRouteData.tableActive);
        } else {
            handleSearch('reset');
        }
        if (!!returnRouteData) {
            clearSessionStorage(location.pathname);
        }
    }, []);
 
    return (
        <>
            <Page pageHead={{ title: '司法局审核' }}>
                <div className="judicialExamine">
                    <div className="pageSearch">
                        <TableSearch
                            labelLength={7}
                            form={form}
                            itemData={[
                                { type: 'Input', name: 'plaintiffs', label: '申请人' },
                                { type: 'Input', name: 'defendants', label: '被申请人' },
                                { type: 'Input', name: 'caseNo', label: '调解案号' },
                                { type: 'TreeSelect', name: 'mediateUnitId', label: '调解组织', placeholder: '查询调解组织名称', treedata: adjustOrgData },
                                {
                                    type: 'Select',
                                    name: 'endAuditResult',
                                    label: '终审结果',
                                    selectdata: [
                                        { label: '待审核', value: '0' },
                                        { label: '同意', value: '1' },
                                        { label: '拒绝', value: '2' },
                                    ],
                                },
                                {
                                    type: 'Select',
                                    name: 'rmtjStatus',
                                    label: '转入结果',
                                    selectdata: [
                                        { label: '未转入', value: '1' },
                                        { label: '转入中', value: '2' },
                                        { label: '已转入', value: '3' },
                                        { label: '转入失败', value: '4' },
                                    ],
                                },
                                { type: 'Input', name: 'rmtjCaseId', label: '转入案号' },
                                { type: 'RangePicker', name: 'applyTime', label: '提审时间' },
                            ]}
                            handleReset={() => handleSearch('reset')}
                            handleSearch={() => handleSearch('search')}
                        />
                    </div>
                    <div className="pageTable">
                        <TableView
                            showHeader
                            title="查询结果"
                            buttonAction={[
                                <Button icon={<DownloadOutlined />} type="primary" ghost onClick={() => searchTotal()}>
                                    导出查询结果
                                </Button>,
                                <Button disabled={!selectedRowKeys.length ? true : false} onClick={downloadXls}>
                                    导出选择
                                </Button>,
                                <Button disabled={!selectedRowKeys.length ? true : false} onClick={downloadFile}>
                                    下载附件
                                </Button>,
                                <Button
                                    disabled={!selectedRowKeys.length ? true : false}
                                    onClick={() =>
                                        setModal({
                                            type: 'all',
                                            visible: true,
                                            title: `${selectedRowKeys.length}个案件批量审核`,
                                            submit: { applyIdList: selectedRowKeys, auditResult: '1', auditResultName: '同意' },
                                        })
                                    }
                                >
                                    批量审核
                                </Button>,
                                <Button disabled={!selectedRowKeys.length ? true : false} onClick={handleRemove}>
                                    批量重转
                                </Button>,
                            ]}
                            columns={columns}
                            dataSource={data.tableData}
                            rowSelection={{
                                selectedRowKeys,
                                onChange: (selectedRowKeys) => {
                                    let obj = { [search.page]: { selectedRowKeys } };
                                    setSelectedRowsObj({ ...selectedRowsObj, ...obj });
                                },
                            }}
                            pagination={{
                                current: search.page,
                                pageSize: search.size,
                                total: data.total,
                                onChange: (page, pageSize) => handleSearch('changePage', [page, pageSize]),
                            }}
                            rowClassName={(record) => (record.id === data.tableActive ? 'tableRowActive' : '')}
                        />
                    </div>
                </div>
            </Page>
            <MyModal visible={modal.visible} width={600} onCancel={() => setModal({ visible: false })} onOk={handleExamine} okText="提交">
                <h4>{modal.title}司法局审核</h4>
                <Row gutter={[16, 16]}>
                    <Col span={24}>
                        <h5>审核结果</h5>
                        <Select
                            style={{ width: '100%' }}
                            value={modal.submit?.auditResult}
                            onChange={(value, option) => handleChangeInput(['auditResult', 'auditResultName'], [value, option.label])}
                            options={[
                                { label: '同意', value: '1' },
                                { label: '拒绝', value: '2' },
                            ]}
                            placeholder="请选择"
                        />
                    </Col>
                    <Col span={24}>
                        <h5>审核意见</h5>
                        <TextArea
                            rows={2}
                            value={modal.submit?.auditContent}
                            onChange={(e) => handleChangeInput('auditContent', e.target.value)}
                            placeholder="请输入"
                        />
                    </Col>
                </Row>
                {!modal.type && (
                    <>
                        <div className="judicialExamine-divider" />
                        <h4>审核记录</h4>
                        <Table
                            columns={[
                                { title: '审核结果', dataIndex: 'auditResultName' },
                                { title: '审核意见', dataIndex: 'auditContent' },
                                { title: '审核人', dataIndex: 'auditerName' },
                                { title: '审核时间', dataIndex: 'auditTime', render: (text) => dateFormat(text) },
                            ]}
                            dataSource={examineHis}
                            direction="暂无历史记录"
                            pagination={false}
                            size="small"
                            rowKey="applyId"
                        />
                    </>
                )}
            </MyModal>
        </>
    );
};
 
export default JudicialExamine;