forked from gzzfw/frontEnd/gzDyh

liuwh
2024-09-09 e92ddbcdc1cb990de02621bccfa62cc067afd3b9
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
/*
 * @Author: dminyi 1301963064@qq.com
 * @Date: 2024-08-09 09:59:43
 * @LastEditors: dminyi 1301963064@qq.com
 * @LastEditTime: 2024-09-07 17:27:08
 * @FilePath: \gzDyh\gz-customerSystem\src\views\basicInformation\organization\index.jsx
 * @Description: 来访登记
 */
 
import React, { useState, useRef, Fragment, useEffect } from "react";
import { useSearchParams, useNavigate } from 'react-router-dom';
import NewPage from '@/components/NewPage';
import * as $$ from '@/utils/utility';
import "@arco-themes/react-gzzz/css/arco.css";
import '../index.less';
import { Space } from 'antd';
import { Button, Steps, Message } from '@arco-design/web-react';
import VisitorRegister from './component/visitorRegister';
import Preview from './preview';
import { useParams } from 'react-router-dom';
 
const Step = Steps.Step;
 
function saveDispute(data) {
    return $$.ax.request({ url: `casedraftInfo/caseDraftRegister`, type: 'post', service: 'mediate', data });
}
 
function getId() {
    return $$.ax.request({ url: `caseUtils/getNewTimeCaseId`, type: 'get', service: 'utils' });
}
 
function submitDispute(data) {
    return $$.ax.request({ url: `caseInfo/caseRegister`, type: 'post', service: 'mediate', data });
}
 
function getDetailData(id) {
    return $$.ax.request({ url: `casedraftInfo/getCasedraftInfo?id=${id}`, type: 'get', service: 'mediate' });
}
 
 
const Organization = (props) => {
    const formRef = useRef();
    const routeData = useParams();
    const navigate = useNavigate();
    const [isReview, setIsReview] = useState(false);//预览页面控制
    const [current, setCurrent] = useState(1);
    const [id, setId] = useState();
    const [editData, setEditData] = useState({});//回显数据
 
    useEffect(() => {
        if (routeData.id) {
            getDeatil(routeData.id)
            setId(routeData.id)
        } else {
            getAppId()
        }
 
    }, [])
 
    //编辑
    const getDeatil = async (id) => {
        const res = await getDetailData(id)
        if (res.type) {
            const { agentList, personList, ...rest } = res.data
            const parList = agentList.concat(personList)
            const obj = {
                ...rest,
                fakeData: parList,
                myCaseType: [rest.caseTypeFirst, rest.caseType],
                myQuesAddress: rest.queRoad ? [rest.queProv, rest.queCity, rest.queArea, rest.queRoad] : undefined
            }
            formRef.current.setFieldsValue(obj)
            setEditData(obj)
        }
    }
 
    //获取id
    const getAppId = async () => {
        const res = await getId()
        if (res.type) {
            setId(res.data)
        }
    }
 
    //提交信息,需要校验规则
    const handleSubmit = async () => {
        if (formRef.current) {
            formRef.current.validate(undefined, (errors, values) => {
                if (!errors) {
                    const { myCaseType, myQuesAddress, ...rest } = formRef.current.getFields()
                    const params = handleData(rest)
                    reauestSubmit({
                        ...params,
                        isSelfAccept: 0,
                        isDraft: 0,
                        operateType: 0,
                    })
                }
            });
        }
    }
 
    //保存草稿信息,不需要校验规则
    const handleSave = () => {
        if (formRef.current) {
            const { myCaseType, myQuesAddress, ...rest } = formRef.current.getFields()
            const params = handleData(rest)
            requestSave(params)
        }
    }
 
    //数据处理
    const handleData = (data) => {
        const { fakeData, ...newObj } = data
        if (data.id) {
            return {
                ...newObj,
                personList: fakeData?.filter(item => item.perType === "15_020008-1" || item.perType === "15_020008-2"),
                agentList: fakeData?.filter(item => item.perType === "24_00006-1" || item.perType === "24_00006-2").map(item => {
                    return {
                        ...item,
                        personId: item.personId.join(',')
                    }
                }),
            }
        } else {
            return {
                ...newObj,
                personList: fakeData?.filter(item => item.perType === "15_020008-1" || item.perType === "15_020008-2"),
                agentList: fakeData?.filter(item => item.perType === "24_00006-1" || item.perType === "24_00006-2").map(item => {
                    return {
                        ...item,
                        personId: item.personId.join(',')
                    }
                }),
                id: id
            }
        }
    }
 
    //预览信息
    const handleReview = () => {
        setIsReview(!isReview)
    }
 
    function selfAcceptance() {
        $$.modalInfo({
            title: '自行受理确认',
            content: '确定自行受理吗?',
            okText: '确定受理',
            cancelText: '我再想想',
            onOk: async () => {
                setCurrent(3);
                navigate(`mediate/visit/handleFeedback`, { replace: true })
            },
        });
    }
 
    //保存请求
    const requestSave = async (data) => {
        const response = await saveDispute(data)
        if (response.type) {
            Message.success('保存草稿成功!')
        }
    }
 
    //提交请求
    const reauestSubmit = async (data) => {
        const response = await submitDispute(data)
        if (response.type) {
            Message.success('提交成功!')
            setCurrent(2)
        }
    }
 
    return (
        <div style={{ position: 'relative' }}>
            <NewPage
                pageHead={
                    { breadcrumbData: [{ title: '工作台' }, { title: '来访登记' }], title: '来访登记' }
                }
            >
                <Fragment>
                    <div style={{ backgroundColor: '#fff', margin: '12px 16px 0px 16px', paddingTop: '16px', paddingLeft: '91px' }}>
                        <Steps type='navigation' current={current}>
                            <Step title='来访登记' disabled />
                            <Step title='事件流转' disabled />
                            <Step title='办理反馈' disabled />
                            <Step title='结案审核' disabled />
                            <Step title='当事人评价' disabled />
                            <Step title='结案归档' disabled />
                        </Steps>
                    </div>
                    <Preview style={{ display: isReview ? '' : 'none' }} data={formRef?.current?.getFields()} />
                    <VisitorRegister
                        formRef={formRef}
                        style={{ display: isReview ? 'none' : '' }}
                        mainId={id}
                        partyList={editData.fakeData}
                        fileInfoList={editData.fileInfoList}
                    />
                    <div className="dataSync-excel">
                        <Space size="large" style={{ margin: '4px 14px' }}>
                            <Button type="primary" style={{ backgroundColor: '#1A6FB8' }} onClick={handleSave} >保存</Button>
                            <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={handleReview}>预览</Button>
                            <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={handleSubmit}>提交</Button>
                            <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={() => selfAcceptance()}>自行受理</Button>
                            <Button type='secondary' onClick={handleReview}>返回上级页面</Button>
                        </Space>
                    </div>
                </Fragment>
            </NewPage>
        </div>
    )
}
 
export default Organization;