|
@@ -1,8 +1,6 @@
|
1
|
1
|
import React, { useState, useEffect, useRef } from 'react';
|
2
|
|
-import { history, Link } from 'umi';
|
3
|
|
-import { Button, Popconfirm, Modal, Form, Input, message, Radio, Select, Tooltip } from 'antd';
|
|
2
|
+import { Button, Popconfirm, Modal, Form, Input, message, Radio, Select } from 'antd';
|
4
|
3
|
import { PlusOutlined } from '@ant-design/icons';
|
5
|
|
-import { getRegionList, addRegion, deleteRegion, updateRegion } from '@/services/region';
|
6
|
4
|
import { getCooperativeList } from '@/services/cooperative';
|
7
|
5
|
import {
|
8
|
6
|
getUserList,
|
|
@@ -20,26 +18,24 @@ const FormItem = Form.Item;
|
20
|
18
|
const { Option } = Select;
|
21
|
19
|
|
22
|
20
|
export default (props) => {
|
23
|
|
- const actions = () => [
|
24
|
|
- <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
|
25
|
|
- 新增
|
26
|
|
- </Button>,
|
27
|
|
- ];
|
|
21
|
+ //编辑弹窗
|
28
|
22
|
const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
29
|
23
|
const [form] = Form.useForm();
|
30
|
24
|
const [editModal, setEditModal] = useState(false);
|
31
|
25
|
const [loading, setLoading] = useState(false);
|
32
|
26
|
const [userId, setuserId] = useState();
|
33
|
27
|
const [password, setPassWord] = useState('');
|
34
|
|
- const actionRef = useRef();
|
35
|
28
|
const [cooperativeList, setCooperativeList] = useState([]);
|
36
|
29
|
|
|
30
|
+ //列表数据
|
|
31
|
+ const actionRef = useRef();
|
|
32
|
+
|
|
33
|
+ // 编辑弹窗的表单提交
|
37
|
34
|
const Submit = (values) => {
|
38
|
35
|
const newData = { ...values };
|
39
|
36
|
if (!newData.sex && newData.sex !== 0) {
|
40
|
37
|
newData.sex = 1;
|
41
|
38
|
}
|
42
|
|
- console.log(newData);
|
43
|
39
|
setLoading(true);
|
44
|
40
|
if (!/^1[0-9]{10}$/.test(newData.phone)) {
|
45
|
41
|
message.warning('请输入正确的十一位手机号');
|
|
@@ -67,19 +63,23 @@ export default (props) => {
|
67
|
63
|
});
|
68
|
64
|
}
|
69
|
65
|
};
|
70
|
|
- const handelEdit = (val) => {
|
71
|
|
- setuserId(val.userId);
|
72
|
|
- form.setFieldsValue(val);
|
73
|
|
- setEditModal(true);
|
74
|
|
- };
|
|
66
|
+ //表单点击取消按钮
|
75
|
67
|
const onCancel = () => {
|
76
|
68
|
setuserId();
|
77
|
69
|
form.resetFields();
|
78
|
70
|
setEditModal(false);
|
79
|
71
|
};
|
|
72
|
+ // 弹窗表单中机构搜索框改变事件目前没用
|
80
|
73
|
const handelChange = () => {};
|
|
74
|
+
|
|
75
|
+ // 列表点击编辑按钮
|
|
76
|
+ const handelEdit = (val) => {
|
|
77
|
+ setuserId(val.userId);
|
|
78
|
+ setEditModal(true);
|
|
79
|
+ };
|
|
80
|
+ //列表点击删除按钮
|
81
|
81
|
const handleDelete = (id) => {
|
82
|
|
- deleteRegion(id)
|
|
82
|
+ deleteUser(id)
|
83
|
83
|
.then(() => {
|
84
|
84
|
message.success('删除成功');
|
85
|
85
|
actionRef.current.reload();
|
|
@@ -88,34 +88,75 @@ export default (props) => {
|
88
|
88
|
message.error(err);
|
89
|
89
|
});
|
90
|
90
|
};
|
|
91
|
+ //列表切换人员状态方法
|
|
92
|
+ const handleOK = (record, data) => {
|
|
93
|
+ const title = record.status
|
|
94
|
+ ? '您确定要将该人员状态变更为禁用吗? 禁用后该人员将不能登录'
|
|
95
|
+ : '您确定要将该人员状态变更为启用吗? 启用后该人员可以登录!';
|
|
96
|
+ Modal.confirm({
|
|
97
|
+ title: title,
|
|
98
|
+ okText: '确认',
|
|
99
|
+ cancelText: '取消',
|
|
100
|
+ onOk() {
|
|
101
|
+ updateUser(record.userId, { ...record, status: record.status === 1 ? 0 : 1 })
|
|
102
|
+ .then((res) => {
|
|
103
|
+ message.success('操作成功');
|
|
104
|
+ actionRef.current.reload();
|
|
105
|
+ })
|
|
106
|
+ .catch((err) => {
|
|
107
|
+ message.error(err);
|
|
108
|
+ });
|
|
109
|
+ },
|
|
110
|
+ });
|
|
111
|
+ };
|
91
|
112
|
useEffect(() => {
|
|
113
|
+ //获取账号默认密码
|
92
|
114
|
getDefaultPassword().then((res) => {
|
93
|
115
|
setPassWord(res);
|
94
|
116
|
});
|
|
117
|
+ //获取机构列表数据
|
95
|
118
|
getCooperativeList().then((res) => {
|
96
|
119
|
setCooperativeList(res.records);
|
97
|
120
|
});
|
98
|
121
|
if (userId) {
|
|
122
|
+ getUserDetail(userId).then((res) => {
|
|
123
|
+ if (res.orgId === '-1') {
|
|
124
|
+ form.setFieldsValue({ ...res, orgId: cooperativeList[0].orgId });
|
|
125
|
+ } else {
|
|
126
|
+ form.setFieldsValue(res);
|
|
127
|
+ }
|
|
128
|
+ });
|
99
|
129
|
} else {
|
100
|
130
|
form.resetFields();
|
101
|
131
|
}
|
102
|
132
|
}, [userId]);
|
|
133
|
+
|
|
134
|
+ const actions = () => [
|
|
135
|
+ <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
|
|
136
|
+ 新增
|
|
137
|
+ </Button>,
|
|
138
|
+ ];
|
103
|
139
|
const columns = [
|
104
|
|
- {
|
105
|
|
- title: '登录账号',
|
106
|
|
- dataIndex: 'loginName',
|
107
|
|
- key: 'loginName',
|
108
|
|
- },
|
109
|
140
|
{
|
110
|
141
|
title: '用户名',
|
111
|
142
|
dataIndex: 'userName',
|
112
|
143
|
key: 'userName',
|
113
|
144
|
},
|
114
|
|
-
|
|
145
|
+ {
|
|
146
|
+ title: '性别',
|
|
147
|
+ dataIndex: 'sex',
|
|
148
|
+ key: 'sex',
|
|
149
|
+ width: 80,
|
|
150
|
+ render: (_, record) => {
|
|
151
|
+ return record.sex === 1 ? '男' : record.sex === 0 ? '女' : '未知';
|
|
152
|
+ },
|
|
153
|
+ search: false,
|
|
154
|
+ },
|
115
|
155
|
{
|
116
|
156
|
title: '手机号',
|
117
|
157
|
dataIndex: 'phone',
|
118
|
158
|
key: 'phone',
|
|
159
|
+ width: 120,
|
119
|
160
|
},
|
120
|
161
|
{
|
121
|
162
|
title: '邮箱',
|
|
@@ -126,6 +167,14 @@ export default (props) => {
|
126
|
167
|
title: '状态',
|
127
|
168
|
dataIndex: 'status',
|
128
|
169
|
key: 'status',
|
|
170
|
+ renderFormItem: () => {
|
|
171
|
+ return (
|
|
172
|
+ <Select placeholder="请选择">
|
|
173
|
+ <Option value={1}>启用</Option>
|
|
174
|
+ <Option value={0}>禁用</Option>
|
|
175
|
+ </Select>
|
|
176
|
+ );
|
|
177
|
+ },
|
129
|
178
|
render: (_, record) => {
|
130
|
179
|
return record.status === 1 ? '启用' : '未启用';
|
131
|
180
|
},
|
|
@@ -134,11 +183,14 @@ export default (props) => {
|
134
|
183
|
title: '操作',
|
135
|
184
|
valueType: 'option',
|
136
|
185
|
render: (_, record) => [
|
137
|
|
- <a key={1} onClick={() => handelEdit(record)}>
|
|
186
|
+ <Button type="link" key={1} onClick={() => handleOK(record)}>
|
|
187
|
+ {record.status === 0 ? '启用' : '禁用'}
|
|
188
|
+ </Button>,
|
|
189
|
+ <a key={2} onClick={() => handelEdit(record)}>
|
138
|
190
|
编辑
|
139
|
191
|
</a>,
|
140
|
192
|
<Popconfirm
|
141
|
|
- key={2}
|
|
193
|
+ key={3}
|
142
|
194
|
title="您是否确认删除 ?"
|
143
|
195
|
onConfirm={() => handleDelete(record.userId)}
|
144
|
196
|
okText="确定"
|
|
@@ -199,7 +251,7 @@ export default (props) => {
|
199
|
251
|
<FormItem label="邮箱" name="email" rules={[{ required: true, message: '请输入' }]}>
|
200
|
252
|
<Input placeholder="请输入" />
|
201
|
253
|
</FormItem>
|
202
|
|
- <FormItem label="所属机构" name="orgId">
|
|
254
|
+ <FormItem label="所属机构" name="orgId" rules={[{ required: true, message: '请输入' }]}>
|
203
|
255
|
<Search placeholder="请选择机构" onChange={handelChange} />
|
204
|
256
|
{/* <Select
|
205
|
257
|
placeholder="请选择机构"
|
|
@@ -214,6 +266,12 @@ export default (props) => {
|
214
|
266
|
))}
|
215
|
267
|
</Select> */}
|
216
|
268
|
</FormItem>
|
|
269
|
+ <FormItem label="状态" name="status" rules={[{ required: true, message: '请选择' }]}>
|
|
270
|
+ <Select placeholder="请选择是否启用">
|
|
271
|
+ <Option value={1}>启用</Option>
|
|
272
|
+ <Option value={0}>禁用</Option>
|
|
273
|
+ </Select>
|
|
274
|
+ </FormItem>
|
217
|
275
|
<FormItem label=" " colon={false}>
|
218
|
276
|
<Button type="default" onClick={onCancel}>
|
219
|
277
|
取消
|