董国庆
2025-02-27 cc6a5dcac86b83b8b665770039d30e2c466b9925
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
import { Form, Input, Modal, Tree, Button, Spin, Row, Col, Select, Radio } from 'antd';
import { forwardRef, useImperativeHandle, useState } from 'react';
import { useEffect } from 'react';
import { getDepartmentList, systemPostList, systemRoleList, getSystemUserInfo, getCityList, addSystemUserInfo, editSystemUserInfo } 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([{ name: '市级账号', value: 1 }, { name: '区县账号', value: 2 }, { name: '街道账号', value: 3 }, { name: '社区账号', value: 4 }, { name: '党员账号', value: 5 }])
    //所属区县
    const [countyList, setCountyList] = useState([])
    const [activeCounty, setActiveCounty] = useState('')
    //所属街道
    const [streetList, setStreetList] = useState([])
    const [activeStreet, setActiveStreet] = useState('')
    //所属社区
    const [communityList, setCommunityList] = useState([])
    // const [activeCommunity, setActiveCommunity] = useState({})
 
 
 
 
    useEffect(() => {
        // 获取单位
        setTimeout(() => {
            getDepartmentList(1).then(res => {
                setOneCompanyList(() => res.data)
            })
            getDepartmentList(2).then(res => {
                setTwoCompanyList(() => res.data)
            })
        }, 2000);
        setTimeout(() => {
            getDepartmentList(3).then(res => {
                setThreeCompanyList(() => res.data)
            })
            getDepartmentList(4).then(res => {
                setThreeCompanyList(() => res.data)
            })
        }, 4000);
    }, [])
 
    useImperativeHandle(ref, () => {
        return {
            refreshData: (data, type) => {
                setDetailType(type || false)
 
                getCountyList()
                systemPostList({ pageNum: 1, pageSize: 10000 }).then(res => {
                    setPositionList(() => res.data.records)
                })
                systemRoleList({ pageNum: 1, pageSize: 10000 }).then(res => {
                    setRoleList(() => res.data.records)
                })
 
                if (data.id) {
                    getInfo(data.id)
                }
                setData(data)
            },
            clean: () => {
                setSpinning(false)
            },
        };
    });
 
    // 保存
    const okHandle = () => {
        form.validateFields().then((values) => {
            console.log('value',values)
            if (data.id) {
                values.id = data.id
                onUpdate(values)
            } else {
                onSave(values);
            }
        });
    };
    const getCountyList = (id) => {
        getCityList({ id: '510400', tier: 2 }).then(res => {
            setCountyList(() => res.data)
        })
    }
    const getStreetList = (id) => {
        getCityList({ id: id, tier: 3 }).then(res => {
            setStreetList(() => res.data)
        })
    }
    const getcommunityList = (id) => {
        getCityList({ id: id, tier: 4 }).then(res => {
            setCommunityList(() => res.data)
        })
    }
    const changeCountry = (value, label) => {
        console.log('区县', value,'11111111',label);
        setActiveCounty(value)
        getStreetList(value)
 
    }
    const changeStreet = (value) => {
        console.log('街道', value);
        setActiveStreet(value)
        getcommunityList(value)
    }
    const changeCommunity = (value) => {
        console.log('社区', value);
        // setActiveCommunity(value)
    }
    const getInfo = (id) => {
        getSystemUserInfo(id).then(res => {
 
        })
    }
 
    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="oneDepartmentId"
                            label="所属一级单位"
                            rules={[{ required: true, message: '请选择所属一级单位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={oneCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="twoDepartmentId"
                            label="所属二级单位"
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={twoCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="threeDepartmentId"
                            label="所属三级单位"
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={threeCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="fourDepartmentId"
                            label="所属四级单位"
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={fourCompanyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="systemPostId"
                            label="所属职位"
                            rules={[{ required: true, message: '请选择所属职位' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={positionList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="systemRoleId"
                            label="所属角色"
                            rules={[{ required: true, message: '请选择所属角色' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={roleList}
                                fieldNames={{ label: 'name', value: 'id' }}
                                filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="accountLevel"
                            label="账号层级"
                            rules={[{ required: true, message: '请选择账号层级' }]}
                        >
                            <Select
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={levelList}
                                fieldNames={{ label: 'name', value: 'value' }}
                            // 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="isAdmin"
                                    rules={[{ required: true, message: '是否管理员' }]}
                                >
                                    <Radio.Group
                                        // style={style}
                                        // onChange={onChange}
                                        // value={value}
                                        options={[{ value: 1, label: '否', }, { value: 2, label: '是', },
 
                                        ]}
                                    />
                                </Form.Item>
                                <div style={{ fontSize: '12px', color: "rgba(0,0,0,0.5)", marginLeft: "10px" }}>管理员主要用于接收实现临期提醒,以及上级端登录</div>
                            </div>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            name="districtsCode"
                            label="所属区县"
                            rules={[{ required: true, message: '请选择所属区县' }]}
                        >
                            {/* <Select
                                // onChange={changeCountry}
                                // value={activeCounty}
                                placeholder="请选择"
                                options={levelList}
                                fieldNames={{ label: 'name', value: 'id' }}
                            >
                            </Select > */}
                            <Select
                                key="searchSelect"
                                allowClear
                                onChange={changeCountry}
                                value={activeCounty}
                                placeholder="请选择"
                                options={countyList}
                                fieldNames={{ label: 'name', value: 'id' }}
                            // filterOption={false}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="streetId"
                            label="所属街道"
                            rules={[{ required: true, message: '请选择所属街道' }]}
                        >
                            <Select
                                onChange={changeStreet}
                                disabled={!activeCounty}
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={streetList}
                                fieldNames={{ label: 'name', value: 'id' }}
                            >
                            </Select >
                        </Form.Item>
                    </Col>
                    <Col span={8}>
                        <Form.Item
                            name="communityId"
                            label="所属社区"
                            rules={[{ required: true, message: '请选择所属社区' }]}
                        >
                            <Select
                                disabled={!activeStreet}
                                key="searchSelect"
                                allowClear
                                placeholder="请选择"
                                options={communityList}
                                fieldNames={{ label: 'name', value: 'id' }}
                            >
                            </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="phone"
                                    rules={[{
                                        validator: (rule, value) => {
                                            return new Promise((resolve, reject) => {
                                                if (!value) {
                                                    reject('请输入联系方式');
                                                }
                                                const phoneRegex = /^((\+86)?(13|14|15|16|17|18|19)[0-9]{9})|((\+86)?(0[0-9]{2,3})?([2-9][0-9]{6,7}))$/;
                                                if (!phoneRegex.test(value)) {
                                                    reject('请输入正确的电话号码');
                                                }
                                                resolve('');
                                            });
                                        },
                                    }]}
                                >
                                    <Input disabled={detailType} placeholder='请输入联系方式' />
                                </Form.Item>
                                <div style={{ fontSize: '12px', color: "rgba(0,0,0,0.5)", marginLeft: "10px" }}>联系方式将作为登录账号使用</div>
                            </div>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={8}>
                        <Form.Item
                            required
                            name="password"
                            label="登录密码"
                            rules={[{
                                validator: (rule, value) => {
                                    return new Promise((resolve, reject) => {
                                        if (!value) {
                                            reject('请输入新密码');
                                        }
                                        const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
                                        if (!passwordRegex.test(value)) {
                                            reject('密码需要包含大小写字母,数字和特殊符号,且长度为8位以上');
                                        }
                                        resolve('');
                                    });
                                },
                            }]}
                        >
                            <Input.Password disabled={detailType} placeholder='请输入' />
                        </Form.Item>
                    </Col>
                    <Col span={16}>
                        <Form.Item
                            label="确认密码"
                            required
                            labelCol={{ span: 4 }}
                            wrapperCol={{ span: 20 }}
                            style={{ marginBottom: 0 }}
                        >
                            <div style={{ display: "flex", flex: 1 }}>
                                <Form.Item
                                    name="surePassword"
                                    rules={[{
                                        validator: (rule, value) => {
                                            return new Promise((resolve, reject) => {
                                                if (!value) {
                                                    reject('请再次输入新密码');
                                                }
                                                if (value != form.getFieldValue('password')) {
                                                    reject('两次密码请保持一致');
                                                }
                                                resolve('');
                                            });
                                        },
                                    },]}
                                >
                                    <Input.Password disabled={detailType} placeholder='请输入' />
                                </Form.Item>
                                <div style={{ fontSize: '12px', color: "rgba(0,0,0,0.5)", marginLeft: "10px" }}>密码需要包含大小写字母,数字和特殊符号,且长度为8位以上</div>
                            </div>
                        </Form.Item>
                    </Col>
                </Row>
 
 
            </Form>
            <Spin spinning={spinning} fullscreen />
        </Modal >
    );
};
 
export default forwardRef(AddAndEdit);