|
@@ -1,149 +1,292 @@
|
1
|
|
-import { history, Link } from 'umi';
|
2
|
|
-import { useRef } from 'react';
|
3
|
|
-import { Button, Modal, message, Popconfirm, Tooltip } from 'antd';
|
4
|
|
-import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
|
1
|
+import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
+import { Button, Popconfirm, Modal, Form, Input, message, Radio, Select } from 'antd';
|
|
3
|
+import { PlusOutlined } from '@ant-design/icons';
|
|
4
|
+import { getCooperativeList } from '@/services/cooperative';
|
|
5
|
+import {
|
|
6
|
+ getUserList,
|
|
7
|
+ addUser,
|
|
8
|
+ deleteUser,
|
|
9
|
+ updateUser,
|
|
10
|
+ getDefaultPassword,
|
|
11
|
+ getUserDetail,
|
|
12
|
+} from '@/services/user';
|
5
|
13
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
6
|
|
-import ProTable, { TableDropdown } from '@ant-design/pro-table';
|
|
14
|
+import PageTable from '@/components/PageTable';
|
|
15
|
+import Search from '@/components/CooperativeSearch';
|
7
|
16
|
|
|
17
|
+const FormItem = Form.Item;
|
|
18
|
+const { Option } = Select;
|
8
|
19
|
|
9
|
20
|
export default (props) => {
|
10
|
|
- const dataSource = [
|
11
|
|
- {
|
12
|
|
- id: 9,
|
13
|
|
- key: '1',
|
14
|
|
- name: '胡彦斌',
|
15
|
|
- age: 32,
|
16
|
|
- status: 0,
|
17
|
|
- zz: '西湖区湖底公园1号',
|
18
|
|
- },
|
19
|
|
-
|
20
|
|
- ];
|
21
|
|
-
|
22
|
|
-
|
23
|
|
- // 测试内容👆-------------------------
|
|
21
|
+ //编辑弹窗
|
|
22
|
+ const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
|
23
|
+ const [form] = Form.useForm();
|
|
24
|
+ const [editModal, setEditModal] = useState(false);
|
|
25
|
+ const [loading, setLoading] = useState(false);
|
|
26
|
+ const [userId, setuserId] = useState();
|
|
27
|
+ const [password, setPassWord] = useState('');
|
|
28
|
+ const [cooperativeList, setCooperativeList] = useState([]);
|
24
|
29
|
|
|
30
|
+ //列表数据
|
25
|
31
|
const actionRef = useRef();
|
26
|
|
- const gotoDetail = (id) => {
|
27
|
|
- history.push(`Administrator/AdminEdit`)
|
28
|
|
- }
|
29
|
|
-
|
30
|
32
|
|
31
|
|
- const handleDelete = (e) => {
|
32
|
|
- deleteNote(e.noteId).then(res => {
|
33
|
|
- message.success('删除成功');
|
34
|
|
- actionRef.current.reload();
|
35
|
|
- })
|
36
|
|
- }
|
|
33
|
+ // 编辑弹窗的表单提交
|
|
34
|
+ const Submit = (values) => {
|
|
35
|
+ const newData = { ...values };
|
|
36
|
+ if (!newData.sex && newData.sex !== 0) {
|
|
37
|
+ newData.sex = 1;
|
|
38
|
+ }
|
|
39
|
+ setLoading(true);
|
|
40
|
+ if (!/^1[0-9]{10}$/.test(newData.phone)) {
|
|
41
|
+ message.warning('请输入正确的十一位手机号');
|
|
42
|
+ setLoading(false);
|
|
43
|
+ return false;
|
|
44
|
+ }
|
|
45
|
+ if (userId) {
|
|
46
|
+ updateUser(userId, newData).then(() => {
|
|
47
|
+ setLoading(false);
|
|
48
|
+ message.success(`修改成功`);
|
|
49
|
+ onCancel();
|
|
50
|
+ actionRef.current.reload();
|
|
51
|
+ });
|
|
52
|
+ } else {
|
|
53
|
+ addUser(newData)
|
|
54
|
+ .then(() => {
|
|
55
|
+ setLoading(false);
|
|
56
|
+ message.success(`保存成功`);
|
|
57
|
+ onCancel();
|
|
58
|
+ actionRef.current.reload();
|
|
59
|
+ })
|
|
60
|
+ .catch((err) => {
|
|
61
|
+ setLoading(false);
|
|
62
|
+ message.error(err.message || err);
|
|
63
|
+ });
|
|
64
|
+ }
|
|
65
|
+ };
|
|
66
|
+ //表单点击取消按钮
|
|
67
|
+ const onCancel = () => {
|
|
68
|
+ setuserId();
|
|
69
|
+ form.resetFields();
|
|
70
|
+ setEditModal(false);
|
|
71
|
+ };
|
|
72
|
+ // 弹窗表单中机构搜索框改变事件目前没用
|
|
73
|
+ const handelChange = () => {};
|
37
|
74
|
|
|
75
|
+ // 列表点击编辑按钮
|
|
76
|
+ const handelEdit = (val) => {
|
|
77
|
+ setuserId(val.userId);
|
|
78
|
+ setEditModal(true);
|
|
79
|
+ };
|
|
80
|
+ //列表点击删除按钮
|
|
81
|
+ const handleDelete = (id) => {
|
|
82
|
+ deleteUser(id)
|
|
83
|
+ .then(() => {
|
|
84
|
+ message.success('删除成功');
|
|
85
|
+ actionRef.current.reload();
|
|
86
|
+ })
|
|
87
|
+ .catch((err) => {
|
|
88
|
+ message.error(err);
|
|
89
|
+ });
|
|
90
|
+ };
|
|
91
|
+ //列表切换人员状态方法
|
38
|
92
|
const handleOK = (record, data) => {
|
39
|
|
- const titleCourse = record.status ? '您确定要禁用该用户吗? 禁用后该用户不能在后台登陆!' : '您确定要启用该用户吗? 启用后该用户将允许在后台登陆!';
|
|
93
|
+ const title = record.status
|
|
94
|
+ ? '您确定要将该人员状态变更为禁用吗? 禁用后该人员将不能登录'
|
|
95
|
+ : '您确定要将该人员状态变更为启用吗? 启用后该人员可以登录!';
|
40
|
96
|
Modal.confirm({
|
41
|
|
- title: titleCourse,
|
|
97
|
+ title: title,
|
42
|
98
|
okText: '确认',
|
43
|
99
|
cancelText: '取消',
|
44
|
|
- onOk () {
|
45
|
|
- publishNote(record.noteId, record.status ? 'off' : 'on').then(res => {
|
46
|
|
- message.success('操作成功');
|
47
|
|
- actionRef.current.reload()
|
48
|
|
- })
|
|
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
|
+ });
|
49
|
109
|
},
|
50
|
110
|
});
|
51
|
|
- }
|
|
111
|
+ };
|
|
112
|
+ useEffect(() => {
|
|
113
|
+ //获取账号默认密码
|
|
114
|
+ getDefaultPassword().then((res) => {
|
|
115
|
+ setPassWord(res);
|
|
116
|
+ });
|
|
117
|
+ //获取机构列表数据
|
|
118
|
+ getCooperativeList().then((res) => {
|
|
119
|
+ setCooperativeList(res.records);
|
|
120
|
+ });
|
|
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
|
+ });
|
|
129
|
+ } else {
|
|
130
|
+ form.resetFields();
|
|
131
|
+ }
|
|
132
|
+ }, [userId]);
|
|
133
|
+
|
52
|
134
|
const actions = () => [
|
53
|
|
- <Button key='add' type="primary" icon={<PlusOutlined />} onClick={() => gotoDetail()}>新增</Button>,
|
54
|
|
- ]
|
|
135
|
+ <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
|
|
136
|
+ 新增
|
|
137
|
+ </Button>,
|
|
138
|
+ ];
|
55
|
139
|
const columns = [
|
56
|
140
|
{
|
57
|
|
- title: '账号',
|
58
|
|
- key: 'zz',
|
59
|
|
- dataIndex: 'zz',
|
|
141
|
+ title: '用户名',
|
|
142
|
+ dataIndex: 'userName',
|
|
143
|
+ key: 'userName',
|
60
|
144
|
},
|
61
|
145
|
{
|
62
|
|
- title: '姓名',
|
63
|
|
- dataIndex: 'name',
|
64
|
|
- key: 'name',
|
|
146
|
+ title: '性别',
|
|
147
|
+ dataIndex: 'sex',
|
|
148
|
+ key: 'sex',
|
|
149
|
+ width: 80,
|
|
150
|
+ render: (_, record) => {
|
|
151
|
+ return record.sex === 1 ? '男' : record.sex === 0 ? '女' : '未知';
|
|
152
|
+ },
|
65
|
153
|
search: false,
|
66
|
154
|
},
|
67
|
155
|
{
|
68
|
|
- title: '邮箱',
|
69
|
|
- dataIndex: 'a',
|
70
|
|
- key: 'a',
|
71
|
|
- search: false,
|
|
156
|
+ title: '手机号',
|
|
157
|
+ dataIndex: 'phone',
|
|
158
|
+ key: 'phone',
|
|
159
|
+ width: 120,
|
72
|
160
|
},
|
73
|
161
|
{
|
74
|
|
- title: '角色',
|
75
|
|
- dataIndex: 'weight',
|
76
|
|
- key: 'weight',
|
77
|
|
- valueType: 'select',
|
78
|
|
- render: (t, record) => record.noteType === 'peseng' ? '农户' : '农机手',
|
79
|
|
- valueEnum: {
|
80
|
|
- 'peseng': { text: '农户', },
|
81
|
|
- 'peseng': { text: '农机手', },
|
82
|
|
- }
|
|
162
|
+ title: '邮箱',
|
|
163
|
+ dataIndex: 'email',
|
|
164
|
+ key: 'email',
|
83
|
165
|
},
|
84
|
166
|
{
|
85
|
167
|
title: '状态',
|
86
|
168
|
dataIndex: 'status',
|
87
|
|
- // initialValue: 'all',
|
88
|
169
|
key: 'status',
|
89
|
|
- valueEnum: {
|
90
|
|
- 0: { text: '已启用', status: 'Success' },
|
91
|
|
- 1: { text: '已禁用', status: 'Error' },
|
92
|
|
- }
|
93
|
|
- },
|
94
|
|
-
|
95
|
|
- {
|
96
|
|
- title: (
|
97
|
|
- <>
|
98
|
|
- 创建时间
|
99
|
|
- <Tooltip placement="top">
|
100
|
|
- <QuestionCircleOutlined style={{ marginLeft: 4 }} />
|
101
|
|
- </Tooltip>
|
102
|
|
- </>
|
103
|
|
- ),
|
104
|
|
- hideInTable: true,
|
105
|
|
- key: 'createdAt',
|
106
|
|
- dataIndex: 'createdAt',
|
107
|
|
- valueType: 'date',
|
108
|
|
- // render: (t) => formatterTime(t),
|
109
|
|
- sorter: (a, b) => a.createdAt - b.createdAt,
|
|
170
|
+ renderFormItem: () => {
|
|
171
|
+ return (
|
|
172
|
+ <Select placeholder="请选择">
|
|
173
|
+ <Option value={1}>启用</Option>
|
|
174
|
+ <Option value={0}>禁用</Option>
|
|
175
|
+ </Select>
|
|
176
|
+ );
|
|
177
|
+ },
|
|
178
|
+ render: (_, record) => {
|
|
179
|
+ return record.status === 1 ? '启用' : '未启用';
|
|
180
|
+ },
|
110
|
181
|
},
|
111
|
182
|
{
|
112
|
183
|
title: '操作',
|
113
|
184
|
valueType: 'option',
|
114
|
|
- key: 'option',
|
115
|
|
- ellipsis: true,
|
116
|
|
- width: 200,
|
117
|
185
|
render: (_, record) => [
|
118
|
|
- <Button type="link" key={1} onClick={() => handleOK(record)}>{record.status === 0 ? '启用' : '禁用'}</Button>,
|
119
|
|
- <Link key={2} to={`Administrator/AdminEdit`}>编辑</Link>,
|
|
186
|
+ <Button type="link" key={1} onClick={() => handleOK(record)}>
|
|
187
|
+ {record.status === 0 ? '启用' : '禁用'}
|
|
188
|
+ </Button>,
|
|
189
|
+ <a key={2} onClick={() => handelEdit(record)}>
|
|
190
|
+ 编辑
|
|
191
|
+ </a>,
|
120
|
192
|
<Popconfirm
|
121
|
193
|
key={3}
|
122
|
194
|
title="您是否确认删除 ?"
|
123
|
|
- onConfirm={() => handleDelete(record)}
|
|
195
|
+ onConfirm={() => handleDelete(record.userId)}
|
124
|
196
|
okText="确定"
|
125
|
197
|
cancelText="取消"
|
126
|
198
|
>
|
127
|
|
- <a href="#" >删除</a>
|
|
199
|
+ <a href="#">删除</a>
|
128
|
200
|
</Popconfirm>,
|
129
|
|
- ]
|
|
201
|
+ ],
|
130
|
202
|
},
|
131
|
|
- ]
|
132
|
|
-
|
133
|
|
-
|
134
|
|
-
|
|
203
|
+ ];
|
135
|
204
|
|
136
|
205
|
return (
|
137
|
206
|
<PageHeaderWrapper>
|
138
|
|
- <ProTable
|
139
|
|
- dataSource={dataSource}
|
|
207
|
+ <PageTable
|
|
208
|
+ request={getUserList}
|
|
209
|
+ // expfunc={exportPersonList}
|
140
|
210
|
columns={columns}
|
141
|
|
- // request={getNoteList} 请求
|
142
|
|
- // rowKey="noteId"
|
|
211
|
+ actionRef={actionRef}
|
|
212
|
+ rowKey="userId"
|
143
|
213
|
options={false}
|
144
|
214
|
toolBarRender={actions}
|
145
|
|
- actionRef={actionRef}
|
|
215
|
+ scroll={{ x: 1000 }}
|
146
|
216
|
/>
|
|
217
|
+ <Modal
|
|
218
|
+ title={userId ? '人员编辑' : '人员新增'}
|
|
219
|
+ visible={editModal}
|
|
220
|
+ onCancel={onCancel}
|
|
221
|
+ keyboard={false}
|
|
222
|
+ maskClosable={false}
|
|
223
|
+ destroyOnClose={true}
|
|
224
|
+ footer={null}
|
|
225
|
+ >
|
|
226
|
+ <Form {...formItemLayout} onFinish={Submit} form={form}>
|
|
227
|
+ <FormItem label="登录账号">
|
|
228
|
+ <Input.Group compact>
|
|
229
|
+ <Form.Item
|
|
230
|
+ name="loginName"
|
|
231
|
+ noStyle
|
|
232
|
+ rules={[{ required: true, message: '请输入登录账号' }]}
|
|
233
|
+ >
|
|
234
|
+ <Input placeholder="请输入" />
|
|
235
|
+ </Form.Item>
|
|
236
|
+ <span style={{ opacity: '0.7' }}>默认密码{password}</span>
|
|
237
|
+ </Input.Group>
|
|
238
|
+ </FormItem>
|
|
239
|
+ <FormItem label="用户名" name="userName" rules={[{ required: true, message: '请输入' }]}>
|
|
240
|
+ <Input placeholder="请输入" />
|
|
241
|
+ </FormItem>
|
|
242
|
+ <FormItem label="性别" name="sex">
|
|
243
|
+ <Radio.Group name="sex" defaultValue={1}>
|
|
244
|
+ <Radio value={1}>男</Radio>
|
|
245
|
+ <Radio value={0}>女</Radio>
|
|
246
|
+ </Radio.Group>
|
|
247
|
+ </FormItem>
|
|
248
|
+ <FormItem label="手机号" name="phone" rules={[{ required: true, message: '请输入' }]}>
|
|
249
|
+ <Input maxLength="11" placeholder="请输入" />
|
|
250
|
+ </FormItem>
|
|
251
|
+ <FormItem label="邮箱" name="email" rules={[{ required: true, message: '请输入' }]}>
|
|
252
|
+ <Input placeholder="请输入" />
|
|
253
|
+ </FormItem>
|
|
254
|
+ <FormItem label="所属机构" name="orgId" rules={[{ required: true, message: '请输入' }]}>
|
|
255
|
+ <Search placeholder="请选择机构" onChange={handelChange} />
|
|
256
|
+ {/* <Select
|
|
257
|
+ placeholder="请选择机构"
|
|
258
|
+ showSearch
|
|
259
|
+ onSearch={handelFormSearch}
|
|
260
|
+ onChange={handelFormSearch}
|
|
261
|
+ >
|
|
262
|
+ {cooperativeList.map((item) => (
|
|
263
|
+ <Option value={item.orgId} key={item.orgId}>
|
|
264
|
+ {item.name}
|
|
265
|
+ </Option>
|
|
266
|
+ ))}
|
|
267
|
+ </Select> */}
|
|
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>
|
|
275
|
+ <FormItem label=" " colon={false}>
|
|
276
|
+ <Button type="default" onClick={onCancel}>
|
|
277
|
+ 取消
|
|
278
|
+ </Button>
|
|
279
|
+ <Button
|
|
280
|
+ type="primary"
|
|
281
|
+ loading={loading}
|
|
282
|
+ htmlType="Submit"
|
|
283
|
+ style={{ marginLeft: '4em' }}
|
|
284
|
+ >
|
|
285
|
+ 确认
|
|
286
|
+ </Button>
|
|
287
|
+ </FormItem>
|
|
288
|
+ </Form>
|
|
289
|
+ </Modal>
|
147
|
290
|
</PageHeaderWrapper>
|
148
|
|
- )
|
149
|
|
-}
|
|
291
|
+ );
|
|
292
|
+};
|