李志伟 3 years ago
parent
commit
478c36db2c
1 changed files with 83 additions and 25 deletions
  1. 83
    25
      src/pages/SystemManagement/Administrator/index.jsx

+ 83
- 25
src/pages/SystemManagement/Administrator/index.jsx View File

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