董国庆
2025-02-25 ae3675cb85ca2006e9468157caac4ea298e8b8f4
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
import { Form, Input, Modal, Tree, Button, Spin, Row, Col, Select } from 'antd';
import { forwardRef, useImperativeHandle, useState } from 'react';
import { useEffect } from 'react';
import { getTree, getAddTree } from '../service';
import { Color } from 'antd/es/color-picker';
const formItemLayout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};
 
 
const AddAndEdit = ({ visible, onSave, onUpdate, onCancel }, ref) => {
    const [form] = Form.useForm();
    const [data, setData] = useState({})
    const [treeData, setTreeData] = useState([]);//权限树
    const [treeSeletKeys, setTreeSeletKeys] = useState([]); //勾选权限
    const [detailType, setDetailType] = useState(false);//是否详情
    const [spinning, setSpinning] = useState(false);
 
    const [oneCompanyList, setOneCompanyList] = useState([])
    const [twoCompanyList, setTwoCompanyList] = useState([])
    const [threeCompanyList, setThreeCompanyList] = useState([])
    const [fourCompanyList, setFourCompanyList] = useState([])
 
    //所属职位
    const [positionList, setPositionList] = useState([])
    //所属角色
    const [roleList, setRoleList] = useState([])
    //账号层级
    const [levelList, setLevelList] = useState([])
    //所属区县
    const [countyList, setCountyList] = useState([])
    //所属街道
    const [streetList, setStreetList] = useState([])
    //所属社区
    const [communityList, setCommunityList] = useState([])
 
 
 
 
    useEffect(() => {
        // 获取权限树
        getAddTree().then(res => {
            setTreeData(res.data)
        })
    }, [])
 
    useImperativeHandle(ref, () => {
        return {
            refreshData: (data, type) => {
                setDetailType(type || false)
                if (data.id) {
                    // 获取角色的权限树
                    getTree(data.id).then(res => {
                        setTreeSeletKeys(res.data.systemMenuIds || []);
                    })
                }
                setData(data)
                form.setFieldsValue(data);
            },
            clean: () => {
                setSpinning(false)
            },
        };
    });
 
    // 保存
    const okHandle = () => {
        form.validateFields().then((values) => {
            setSpinning(true)
            values.menuIds = treeSeletKeys
            delete values.tree
            if (data.id) {
                values.id = data.id
                onUpdate(values)
            } else {
                onSave(values);
            }
        });
    };
 
 
    return (
        <Modal
            getContainer={false}
            width="65%"
            destroyOnClose
            title={detailType ? '人员详情' : data.id ? '编辑人员' : '添加人员'}
            open={visible}
            onCancel={() => onCancel(false)}
            afterClose={() => {
                form.resetFields()
                setTreeSeletKeys([])
            }}
            footer={
                !detailType ?
                    [
                        <Button key="back" onClick={() => onCancel(false)}>取消</Button>,
                        <Button key="submit" type="primary" onClick={okHandle}>
                            确定
                        </Button>
                    ]
                    :
                    <Button key="back" onClick={() => onCancel(false)}>关闭</Button>
            }
        >
            <Form layout="horizontal" {...formItemLayout} form={form} scrollToFirstError>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="姓名"
                            rules={[{ required: true, message: '请输入人员姓名' }]}
                        >
                            <Input disabled={detailType} placeholder='请输入人员姓名' />
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属一级单位"
                            rules={[{ required: true, message: '请选择所属一级单位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={oneCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属二级单位"
                            rules={[{ required: true, message: '请选择所属二级单位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={twoCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属三级单位"
                            rules={[{ required: true, message: '请选择所属三级单位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={threeCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属四级单位"
                            rules={[{ required: true, message: '请选择所属四级单位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={fourCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属职位"
                            rules={[{ required: true, message: '请选择所属职位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={positionList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属角色"
                            rules={[{ required: true, message: '请选择所属角色' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={roleList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="账号层级"
                            rules={[{ required: true, message: '请选择账号层级' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={levelList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={16}>
                        <Form.Item
                            label="是否管理员"
                            labelCol={{ span: 4 }}
                            wrapperCol={{ span: 20 }}
                            style={{ marginBottom: 0 }}
                        >
                            <div style={{ display: "flex", flex: 1 }}>
                                <Form.Item
                                    name="name"
                                    rules={[{ required: true, message: '请选择账号层级' }]}
                                >
                                    <Select
                                        key="searchSelect"
                                        allowClear
                                        style={{ width: '280px' }}
                                        placeholder="请选择"
                                        dataSource={levelList}
                                        fieldNames={{ label: 'name', value: 'id' }}
                                        filterOption={false}
                                    >
                                    </Select >
                                </Form.Item>
                                <div style={{ fontSize: '12px', Color: "rgba(0,0,0,0.5)" }}>管理员主要用于接收实现临期提醒,以及上级端登录</div>
                            </div>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属区县"
                            rules={[{ required: true, message: '请选择所属区县' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={oneCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属街道"
                            rules={[{ required: true, message: '请选择所属街道' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={twoCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                            label="所属社区"
                            rules={[{ required: true, message: '请选择所属社区' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                dataSource={threeCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={16}>
                        <Form.Item
                            label="联系方式"
                            labelCol={{ span: 4 }}
                            wrapperCol={{ span: 20 }}
                            style={{ marginBottom: 0 }}
                        >
                            <div style={{ display: "flex", flex: 1 }}>
                                <Form.Item
                                    name="name"
                                    rules={[{ required: true, message: '请输入联系方式' }]}
                                >
                                    <Input disabled={detailType} placeholder='请输入联系方式' />
                                </Form.Item>
                                <div style={{ fontSize: '12px', Color: "rgba(0,0,0,0.5)" }}>联系方式将作为登录账号使用</div>
                            </div>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="name"
                             label="登录密码"
                            rules={[{ required: true, message: '请输入登录密码' }]}
                        >
                            <Input disabled={detailType} placeholder='请输入' />
                        </Form.Item>
                    </Col>
                    <Col span={16}>
                        <Form.Item
                            label="确认密码"
                            labelCol={{ span: 4 }}
                            wrapperCol={{ span: 20 }}
                            style={{ marginBottom: 0 }}
                        >
                            <div style={{ display: "flex", flex: 1 }}>
                                <Form.Item
                                    name="name"
                                    rules={[{ required: true, message: '请输入确认密码' }]}
                                >
                                    <Input disabled={detailType} placeholder='请输入' />
                                </Form.Item>
                                <div style={{ fontSize: '12px', Color: "rgba(0,0,0,0.5)" }}>联系方式将作为登录账号使用</div>
                            </div>
                        </Form.Item>
                    </Col>
                </Row>
 
 
            </Form>
            <Spin spinning={spinning} fullscreen />
        </Modal >
    );
};
 
export default forwardRef(AddAndEdit);