广州市综治平台前端
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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-02-24 10:16:27
 * @LastEditTime: 2022-11-10 16:52:34
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: 新增 or 修改组织架构
 */
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Button, Cascader, Input, Form, Row, Col, Select } from 'antd';
import * as $$ from '../../../utils/utility';
 
const { Option } = Select;
/*
 * isAddOrEdit, // 是否显示该页面
 * type, // 'change':'修改组织';'upAdd':'新增上级组织';'downAdd':'新增下级组织'
 * organizationActive, // 当前组织信息
 * handleClosePage, // 关闭页面返回上级页面
 * handleFinishForm, // 新增组织 or 修改组织
 */
const AddOrEditOrganization = ({ isAddOrEdit, type, organizationActive, handleFinishForm }) => {
    const [form] = Form.useForm();
 
    const [submitType, setSubmitType] = useState();
 
    const [formData, setFormData] = useState({});
 
    // 地区Option
    const location = $$.locationOption();
 
    function handleValuesChange(type, values) {
        let obj = {};
        obj[type] = values;
        setFormData({ ...formData, ...obj });
    }
 
    // 重置
    function handleReset() {
        let obj = { findStatus: '1', ...organizationActive };
        if (type === 'change') {
            ['name', 'dutyName', 'dutyMobile', 'addr'].forEach((x) => {
                obj[x] = organizationActive[x];
            });
            obj.locationSelect = [];
            obj.locationName = [];
            [
                ['prov', 'provName'],
                ['city', 'cityName'],
                ['area', 'areaName'],
                ['road', 'roadName'],
                ['village', 'villageName'],
            ].forEach((x) => {
                if (organizationActive[x[0]]) {
                    obj.locationSelect.push(organizationActive[x[0]]);
                    obj.locationName.push({ label: organizationActive[x[1]] });
                }
            });
            form.setFieldsValue(obj);
        } else {
            form.resetFields();
            form.setFieldsValue({ findStatus: '1' });
        }
        setFormData(obj);
    }
 
    // 提交表单
    function handleSubmit(type) {
        setSubmitType(type);
        form.submit();
    }
 
    useEffect(() => {
        handleReset();
    }, [isAddOrEdit]);
 
    return (
        <div style={{ display: !isAddOrEdit ? 'none' : '' }}>
            <div className="organization-edit">
                <div className="organization-edit-bg">
                    <Form
                        layout="vertical"
                        form={form}
                        className="personnel-add-form"
                        onFinish={(values) => {
                            let formDataCopy = formData;
                            formDataCopy.locationName = formDataCopy.locationName?.map((x) => x.label) || [];
                            ['prov', 'city', 'area', 'road', 'village'].forEach((x, t) => {
                                formDataCopy[x] = values.locationSelect[t];
                            });
                            ['provName', 'cityName', 'areaName', 'roadName', 'villageName'].forEach((x, t) => {
                                formDataCopy[x] = formDataCopy.locationName[t];
                            });
                            let submitData = { ...formDataCopy, ...values };
                            delete submitData.locationSelect;
                            handleFinishForm(submitType, submitData, form);
                        }}
                        onFinishFailed={({ values, errorFields }) => $$.info({ type: 'error', content: errorFields[0].errors })}
                    >
                        <Row gutter={[24, 16]}>
                            <Col span={8}>
                                <Form.Item label="组织名称" name="unitName" required rules={[{ required: true }]}>
                                    <Input placeholder="请输入" allowClear />
                                </Form.Item>
                            </Col>
                            <Col span={8}>
                                <Form.Item label="组织负责人" name="dutyName">
                                    <Input placeholder="请输入" allowClear />
                                </Form.Item>
                            </Col>
                            <Col span={8}>
                                <Form.Item label="手机号码" name="dutyMobile" rules={[{ pattern: $$.mobileRegExp, message: '请输入正确的手机号码' }]}>
                                    <Input placeholder="请输入" allowClear />
                                </Form.Item>
                            </Col>
                            <Col span={8}>
                                <Form.Item label="地域" help="该值对于分流调度起重要作用" name="locationSelect" required rules={[{ required: true }]}>
                                    <Cascader
                                        placeholder="省/市/区(县)/街道/社区"
                                        options={location}
                                        allowClear
                                        changeOnSelect
                                        onChange={(value, option) => handleValuesChange('locationName', option)}
                                    />
                                </Form.Item>
                            </Col>
                            <Col span={16}>
                                <Form.Item label="详细地址" name="addr" rules={[{ required: true, message: '请输入详细地址' }]}>
                                    <Input placeholder="详细地址" allowClear />
                                </Form.Item>
                            </Col>
                            <Col span={8}>
                                <Form.Item label="是否可以找他调(小程序)" required name="findStatus" rules={[{ required: true }]}>
                                    <Select placeholder="请选择">
                                        <Option key="1">否</Option>
                                        <Option key="2">是</Option>
                                    </Select>
                                </Form.Item>
                            </Col>
                            <Col span={24}>
                                <Form.Item>
                                    <Button type="primary" onClick={() => handleSubmit('1')} className="public-buttonMargin">
                                        {type === 'change' ? '保存' : '提交'}
                                    </Button>
                                    {type !== 'change' && type !== 'upAdd' ? (
                                        <Button onClick={() => handleSubmit('2')} className="public-buttonMargin">
                                            提交并继续
                                        </Button>
                                    ) : null}
                                    <Button onClick={handleReset}>重置</Button>
                                </Form.Item>
                            </Col>
                        </Row>
                    </Form>
                </div>
            </div>
        </div>
    );
};
 
AddOrEditOrganization.propTypes = {
    isAddOrEdit: PropTypes.any,
    type: PropTypes.string,
    organizationActive: PropTypes.object,
    handleFinishForm: PropTypes.func,
};
 
export default AddOrEditOrganization;