广州市综治平台前端
xusd
2 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
import React, { useEffect, useRef, useState } from 'react'
import { Row, Col } from 'antd';
import { Form, Input, Button, Radio } from '@arco-design/web-react';
import ArcoUpload from '@/components/ArcoUpload';
import { Scrollbars } from "react-custom-scrollbars";
import * as $$ from '@/utils/utility';
import { useNavigate } from 'react-router-dom';
 
const RadioGroup = Radio.Group;
const FormItem = Form.Item;
const TextArea = Input.TextArea;
const appUrl = $$.appUrl;
 
function getId() {
  return $$.ax.request({ url: `caseUtils/getNewTimeId`, type: 'get', service: 'utils' });
}
 
function delFile(id) {
  return $$.ax.request({ url: `fileInfo/deleteFileById`, type: 'get', service: 'sys', data: { id } });
}
 
function requestDismiss(data) {
  return $$.ax.request({ url: `caseTask/dismiss`, type: 'post', service: 'mediate', data });
}
 
export default function BackModel(props) {
  const navigate = useNavigate();
  const formRef = useRef();
  const [id, setId] = useState();
  const [reasonRadio, setReasonRadio] = useState();
  
  const { canalSecond } = props;
  const isReturnMode = canalSecond === '22_00003-1';
  
  const options = [
    {
      label: '不属于相关职责范围',
      value: 0
    },
    {
      label: '诉求不合理或不明确',
      value: 1
    },
    {
      label: '无法与当事人取得联系',
      value: 2
    },
    {
      label: '缺乏具体事实依据',
      value: 3
    },
    {
      label: '违反法律法规',
      value: 4
    },
    {
      label: isReturnMode ? '回退理由' : '其他',
      value: 5
    },
  ];
 
  // 当为回退模式时,只显示value=5的选项
  const displayOptions = isReturnMode ? options.filter(option => option.value === 5) : options;
 
  useEffect(() => {
    getAppId()
    // 设置默认选中值
    const defaultValue = isReturnMode ? 5 : 1;
    setReasonRadio(defaultValue);
    
    // 设置默认内容
    if (formRef.current) {
      setTimeout(() => {
        formRef.current.setFieldValue('backType', defaultValue);
        if (defaultValue !== 5) {
          const obj = displayOptions.find(item => item.value === defaultValue);
          if (obj) {
            formRef.current.setFieldValue('disContent', obj.label);
          }
        }
      }, 100);
    }
  }, [isReturnMode])
 
  //获取id
  const getAppId = async () => {
    const res = await getId()
    if (res.type) {
      setId(res.data)
    }
  }
 
  const handleSubmit = () => {
    if (formRef.current) {
      formRef.current.validate(undefined, (errors, values) => {
        if (!errors) {
          const disContent = formRef.current.getFieldValue('disContent')
          handleReturn({
            id,
            caseId: props.caseId,
            caseTaskId: props.caseTaskId,
            disContent: disContent
          })
        }
      })
    }
  }
 
  //删除文件
  const handleDelFile = async (id) => {
    const res = await delFile(id)
    if (res.type) {
      $$.infoSuccess({ content: '删除成功!' });
    }
  }
 
  //请求
  const handleReturn = async (data) => {
    const res = await requestDismiss(data)
    if (res.type) {
      $$.infoSuccess({ content: '提交申请成功!' });
      props.onCancel()
      navigate('/mediate/visit/visitWorkBench')
    }
  }
 
  return (
    <div>
      <Scrollbars style={{ height: '550px' }} autoHide>
        <Form
          ref={formRef}
          layout='vertical'
          requiredSymbol={false}
          initialValues={{
            backType: isReturnMode ? 5 : 1
          }}//默认值
          scrollToFirstError
        >
          <Row>
            <Col span={24}>
              <FormItem
                label={(<div style={{ display: 'flex' }}>{isReturnMode ? '回退理由' : '不予受理理由'}<div className="must">必填</div></div>)}
                field='backType'
                rules={[{ required: true, message: isReturnMode ? '请选择回退理由' : '请选择不予受理理由' }]}
              >
                <RadioGroup
                  direction='vertical'
                  options={displayOptions}
                  onChange={(value) => {
                    setReasonRadio(value)
                    if (value !== 5) {
                      const obj = displayOptions.find(item => item.value === value)
                      formRef.current.setFieldValue('disContent', obj.label)
                    } else {
                      formRef.current.setFieldValue('disContent', '')
                    }
                  }}
                />
              </FormItem>
            </Col>
            {
              reasonRadio === 5 && <Col span={24}>
                <FormItem
                  label=' '
                  field='disContent'
                  rules={[{ required: true, message: isReturnMode ? '回退理由不能为空' : '不予受理理由不能为空' }]}
                >
                  <TextArea
                    autoSize={{ minRows: 4, maxRows: 8 }}
                    placeholder={isReturnMode ? '请填写回退的具体理由' : '请填写不予受理的具体理由'}
                  />
                </FormItem>
              </Col>
            }
            {!isReturnMode && (
              <Col span={24} className="doubleFile">
                <ArcoUpload
                  params={{
                    action: `${appUrl.fileUrl}/${appUrl.sys}/api/web/fileInfo/upload?mainId=${props.caseId}&ownerId=${id}&ownerType=22_00018-515`,
                  }}
                  field='file'
                  label='附件材料'
                  handleDelFile={handleDelFile}
                />
              </Col>
            )}
          </Row>
        </Form>
      </Scrollbars>
      <div className='dialogFooter'>
        <Button
          type="primary"
          className="dialogPrimary"
          onClick={handleSubmit}
        >
          提交
        </Button>
      </div>
    </div>
  )
}