UserManage.js 46.6 KB
Newer Older
1
import React, { useState, useEffect } from 'react';
陈前坚's avatar
陈前坚 committed
2
import {
3
  // Tree,
陈前坚's avatar
陈前坚 committed
4 5 6 7 8 9 10
  Table,
  Space,
  message,
  Modal,
  Input,
  notification,
  Tooltip,
陈前坚's avatar
陈前坚 committed
11
  Card,
陈前坚's avatar
陈前坚 committed
12
  Button,
13
  Spin,
陈前坚's avatar
陈前坚 committed
14 15
  Dropdown,
  Menu,
皮倩雯's avatar
皮倩雯 committed
16
  Popconfirm,
17 18
  Form,
  Radio,
陈前坚's avatar
陈前坚 committed
19 20
} from 'antd';
import {
21
  UserOutlined,
陈前坚's avatar
陈前坚 committed
22
  UserAddOutlined,
陈前坚's avatar
陈前坚 committed
23
  UsergroupAddOutlined,
陈前坚's avatar
陈前坚 committed
24
  EditOutlined,
陈前坚's avatar
陈前坚 committed
25
  EditTwoTone,
陈前坚's avatar
陈前坚 committed
26
  DeleteOutlined,
27
  IdcardOutlined,
陈前坚's avatar
陈前坚 committed
28
  UnlockOutlined,
陈前坚's avatar
陈前坚 committed
29
  ApartmentOutlined,
陈前坚's avatar
陈前坚 committed
30
  StopOutlined,
陈前坚's avatar
陈前坚 committed
31 32
  DoubleLeftOutlined,
  DoubleRightOutlined,
陈前坚's avatar
陈前坚 committed
33
  DownOutlined,
mayongxin's avatar
mayongxin committed
34
  BorderlessTableOutlined,
皮倩雯's avatar
皮倩雯 committed
35 36 37 38 39
  LockOutlined,
  PlusSquareFilled,
  EllipsisOutlined,
  PlusOutlined,
  SyncOutlined,
陈前坚's avatar
陈前坚 committed
40
} from '@ant-design/icons';
41
import PageContainer from '@/components/BasePageContainer';
陈前坚's avatar
陈前坚 committed
42 43
import voca from 'voca';
import zhCN from 'antd/es/locale/zh_CN';
44 45
import {
  addToOrg,
陈前坚's avatar
陈前坚 committed
46
  addToOrgs,
47 48 49
  getOneOUUserListNew,
  getUserRelationList,
  getUserTree,
张烨's avatar
张烨 committed
50 51
  deleteUser as postDeleteUser,
  setUserState as postSetUserState,
陈前坚's avatar
陈前坚 committed
52
  multiDeleteUsers,
mayongxin's avatar
mayongxin committed
53
  setOrgArea,
mayongxin's avatar
mayongxin committed
54
  getOrgArea,
mayongxin's avatar
mayongxin committed
55
  GetMapSetByGroupID,
mayongxin's avatar
mayongxin committed
56 57 58 59 60 61 62 63 64 65 66 67
  GetOUTreeNew,
  GetUserRelationListNew,
  GetUserByKeyNew,
  AddUserNew,
  AddOUNew,
  EditOneOUInfoNew,
  EditUserNew,
  UserStateOUNew,
  DeleteOUNew,
  SetUserRelationListNew,
  JumpToAnotherOUNew,
  DeleteUserNew,
68
} from '@/services/userCenter/userManage/api';
69
import { AddUserAuthSetting, GetUserAuthSet } from '@/services/database/api';
70
import Tree from '@/components/ExpendableTree';
陈前坚's avatar
陈前坚 committed
71
import classnames from 'classnames';
72
import DraggleLayout from 'components/DraggleLayout';
陈前坚's avatar
陈前坚 committed
73
import AddUserModal from './AddUserModal';
74 75 76 77 78 79
import AddSubOrgModal from './AddSubOrgModal';
import EditOrgModal from './EditOrgModal';
import DeleteOrgModal from './DeleteOrgModal';
import RelateRoleModal from './RelateRoleModal';
import EditUserModal from './EditUserModal';
import ChangePasswordModal from './ChangePasswordModal';
皮倩雯's avatar
皮倩雯 committed
80 81
import MapScopeEditModal from '@/components/MapScope';
import AuthModal from './AuthModal';
陈前坚's avatar
陈前坚 committed
82
import styles from './UserManage.less';
皮倩雯's avatar
皮倩雯 committed
83
import { createGuid } from '@/utils/transformUtil';
陈前坚's avatar
陈前坚 committed
84 85

const UserManage = () => {
皮倩雯's avatar
皮倩雯 committed
86 87
  const { TreeNode } = Tree;

88 89
  const [form] = Form.useForm();
  const { Item } = Form;
90
  const [selectValue, setSelctValue] = useState(); // 用户鉴权
91 92

  const [width, setWidth] = useState(50);
陈前坚's avatar
陈前坚 committed
93
  const [treeLoading, setTreeLoading] = useState(false);
陈前坚's avatar
陈前坚 committed
94
  const [tableLoading, setTableLoading] = useState(false);
陈前坚's avatar
陈前坚 committed
95
  const [loading, setLoading] = useState(true);
96
  const [currentOrgOperate, setCurrentOrgOperate] = useState(false); // 是否禁用当前机构操作
陈前坚's avatar
陈前坚 committed
97 98
  const [multiOperate, setMultiOperate] = useState(true); // 是否禁用用户批量操作
  const [multiOperateButtonType, setMultiOperateButtonType] = useState(''); // 更改批量操作按钮样式
陈前坚's avatar
陈前坚 committed
99

陈前坚's avatar
陈前坚 committed
100
  const [treeData, setTreeData] = useState([]); // 用户机构树
陈前坚's avatar
陈前坚 committed
101
  const [treeDataCopy, setTreeDataCopy] = useState([]); // 机构树数据备份,用于更改机构
陈前坚's avatar
陈前坚 committed
102 103
  const [treeState, setTreeState] = useState(true); // 树第一次加载
  const [treeVisible, setTreeVisible] = useState(true); // 树是否可见
陈前坚's avatar
陈前坚 committed
104
  const [tableData, setTableData] = useState([]); // 用户表
105
  const [selectColor, setSelectColor] = useState({}); // 当前选中颜色,操作时设置
陈前坚's avatar
陈前坚 committed
106
  const [orgFilters, setOrgFilters] = useState([]); // 用户列筛选
陈前坚's avatar
陈前坚 committed
107
  const [searchWord, setSearchWord] = useState(''); // 关键字
108
  const [currentSelectOrg, setCurrentSelectOrg] = useState('-1'); // 左侧机构树-选中组织,字符串类型默认全部机构'-1',注意用户表中的OUID是数字
陈前坚's avatar
陈前坚 committed
109
  const [currentSelectOldOrg, setCurrentSelectOldOrg] = useState([]); // 更改机构时的树-原先选中组织
陈前坚's avatar
陈前坚 committed
110

陈前坚's avatar
陈前坚 committed
111 112 113 114 115
  /** ***Modal弹框,是否可视**** */
  const [userVisible, setUserVisible] = useState(false); // 添加用户
  const [addOrgVisible, setAddOrgVisible] = useState(false); // 添加机构
  const [editOrgVisible, setEditOrgVisible] = useState(false); // 编辑机构
  const [deleteOrgVisible, setDeleteOrgVisible] = useState(false); // 删除机构
mayongxin's avatar
mayongxin committed
116
  const [editOrgExtentVisible, setEditOrgExtentVisible] = useState(false); // 删除机构
陈前坚's avatar
陈前坚 committed
117
  const [roleVisible, setRoleVisible] = useState(false); // 关联角色
陈前坚's avatar
陈前坚 committed
118 119 120
  const [changeOrgVisible, setChangeOrgVisible] = useState(false); // 更改机构
  const [passwordVisible, setPasswordVisible] = useState(false); // 修改密码
  const [editUserVisible, setEditUserVisible] = useState(false); // 编辑用户
皮倩雯's avatar
皮倩雯 committed
121
  // const [freezeUserVisible, setFreezeUserVisible] = useState(false); // 冻结用户
陈前坚's avatar
陈前坚 committed
122
  const [deleteUserVisible, setDeleteUserVisible] = useState(false); // 删除用户
mayongxin's avatar
mayongxin committed
123
  const [authUserVisible, setAuthUserVisible] = useState(false); // 鉴权用户
陈前坚's avatar
陈前坚 committed
124

陈前坚's avatar
陈前坚 committed
125
  const [orgTitle, setOrgTitle] = useState('当前机构'); // 弹框标题
126
  const [description, setDescription] = useState(''); // 机构描述信息
127 128
  const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 已选用户数,机构改变时重置
  const [tableLength, setTableLength] = useState(0); // 当前机构用户总数
陈前坚's avatar
陈前坚 committed
129
  const [orgID, setOrgID] = useState(); // 当前选择的机构ID
陈前坚's avatar
陈前坚 committed
130 131
  const [newOrgID, setNewOrgID] = useState(); // 更改机构新选择的ID
  const [currentUser, setCurrentUser] = useState({}); // 当前用户
132

陈前坚's avatar
陈前坚 committed
133 134 135 136
  const [userIDs, setUserIDs] = useState(''); // 批量删除的用户
  const [orgIDs, setOrgIDs] = useState(''); // 批量操作的机构
  const [multiDelete, setMultiDelete] = useState(false); // 是否批量删除用户
  const [multiChangeOrgs, setMultiChangeOrgs] = useState(false); // 是否批量更改机构
陈前坚's avatar
陈前坚 committed
137
  const [multiRelateRoles, setMultiRelateRoles] = useState(false); // 是否批量更改机构
陈前坚's avatar
陈前坚 committed
138

陈前坚's avatar
陈前坚 committed
139 140
  const [rolelist, setRolelist] = useState([]); // 角色列表
  const [stationlist, setStationlist] = useState([]); // 站点列表
mayongxin's avatar
mayongxin committed
141

皮倩雯's avatar
皮倩雯 committed
142 143 144 145
  const [orgAreas, setOrgAreas] = useState([]);
  const [currentOrgArea, setCurrentOrgArea] = useState('');
  const [currentOrgDistinct, setCurrentOrgDistinct] = useState('');
  const [saveExtentFlag, setSaveExtentFlag] = useState(0);
146
  const [filteredValue,setFilteredValue] =useState([]);
陈前坚's avatar
陈前坚 committed
147
  const { Search } = Input;
148 149
  const setRowClassName = record =>
    record.userID === selectColor.userID ? styles.clickRowStyle : '';
陈前坚's avatar
陈前坚 committed
150 151 152 153 154 155
  // 用户表列名
  const columns = [
    {
      title: '登录名',
      dataIndex: 'loginName',
      key: 'loginName',
156
      width: 150,
157
      // fixed: 'left',
陈前坚's avatar
陈前坚 committed
158 159 160 161 162 163 164 165 166
      render: item => (
        <div
          ref={r => {
            if (r) {
              r.innerHTML = item;
            }
          }}
        />
      ),
陈前坚's avatar
陈前坚 committed
167 168 169 170 171
    },
    {
      title: '用户姓名',
      dataIndex: 'userName',
      key: 'userName',
172
      width: 150,
陈前坚's avatar
陈前坚 committed
173 174 175 176 177 178 179 180 181
      render: item => (
        <div
          ref={r => {
            if (r) {
              r.innerHTML = item;
            }
          }}
        />
      ),
陈前坚's avatar
陈前坚 committed
182
    },
183 184 185 186
    {
      title: '所在机构',
      dataIndex: 'OUName',
      key: 'OUName',
187
      width: 150,
188
      ellipsis: true,
陈前坚's avatar
陈前坚 committed
189
      filters: orgFilters,
190
      filteredValue,
陈前坚's avatar
陈前坚 committed
191
      onFilter: (value, record) => record.OUName === value,
192
    },
陈前坚's avatar
陈前坚 committed
193 194 195 196
    {
      title: '手机号码',
      dataIndex: 'phone',
      key: 'phone',
陈前坚's avatar
陈前坚 committed
197
      width: 150,
陈前坚's avatar
陈前坚 committed
198
      ellipsis: true,
199 200
      render: record => {
        if (record) {
201 202 203 204 205 206 207 208 209
          return (
            <div
              ref={r => {
                if (r) {
                  r.innerHTML = record;
                }
              }}
            />
          );
210
        }
tianfen's avatar
tianfen committed
211
        return <span>未绑定</span>;
212
      },
陈前坚's avatar
陈前坚 committed
213 214 215 216 217
    },
    {
      title: '钉钉账户',
      dataIndex: 'ddid',
      key: 'ddid',
陈前坚's avatar
陈前坚 committed
218
      width: 150,
陈前坚's avatar
陈前坚 committed
219 220 221 222 223 224 225 226 227 228
      render: record => {
        if (record) {
          return (
            <Tooltip title={record}>
              <span style={{ color: '#50aefc', cursor: 'pointer' }}>
                已绑定
              </span>
            </Tooltip>
          );
        }
tianfen's avatar
tianfen committed
229
        return <span>未绑定</span>;
陈前坚's avatar
陈前坚 committed
230
      },
陈前坚's avatar
陈前坚 committed
231 232 233 234 235
    },
    {
      title: '微信账户',
      dataIndex: 'wxid',
      key: 'wxid',
陈前坚's avatar
陈前坚 committed
236
      width: 140,
陈前坚's avatar
陈前坚 committed
237 238 239 240 241 242 243 244 245 246
      render: record => {
        if (record) {
          return (
            <Tooltip title={record}>
              <span style={{ color: '#50aefc', cursor: 'pointer' }}>
                已绑定
              </span>
            </Tooltip>
          );
        }
tianfen's avatar
tianfen committed
247
        return <span>未绑定</span>;
陈前坚's avatar
陈前坚 committed
248
      },
陈前坚's avatar
陈前坚 committed
249 250 251 252
    },
    {
      title: '操作',
      key: 'action',
陈前坚's avatar
陈前坚 committed
253
      // fixed: 'right',
陈前坚's avatar
陈前坚 committed
254
      width: 250,
255
      align: 'center',
陈前坚's avatar
陈前坚 committed
256
      render: record => (
陈前坚's avatar
陈前坚 committed
257
        <Space size="middle">
陈前坚's avatar
陈前坚 committed
258
          <Tooltip title="关联角色">
259
            <IdcardOutlined
陈前坚's avatar
陈前坚 committed
260
              onClick={() => relateRole(record)}
261
              style={{ fontSize: '20px', color: '#1890FF' }}
陈前坚's avatar
陈前坚 committed
262 263 264 265 266 267 268 269 270
            />
          </Tooltip>
          <Tooltip title="更改机构">
            <ApartmentOutlined
              onClick={() => changeOrg(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="修改密码">
陈前坚's avatar
陈前坚 committed
271
            <UnlockOutlined
陈前坚's avatar
陈前坚 committed
272 273 274 275 276 277 278 279 280 281
              onClick={() => changePassword(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="编辑用户">
            <EditTwoTone
              onClick={() => editUser(record)}
              style={{ fontSize: '16px' }}
            />
          </Tooltip>
皮倩雯's avatar
皮倩雯 committed
282
          {(record.state == 0 || record.state == null) && (
283
            <>
284
              {/* {     console.log(record.state,'record.state')} */}
285
              <Tooltip title="冻结用户">
皮倩雯's avatar
皮倩雯 committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
                <Popconfirm
                  placement="bottomRight"
                  title={
                    <p>
                      即将冻结用户{' '}
                      <span className={styles.redText}>
                        {voca.stripTags(record.loginName)}
                      </span>
                      ,是否确认冻结?
                    </p>
                  }
                  okText="确认"
                  cancelText="取消"
                  onConfirm={() => freezeUser(record)}
                >
                  <StopOutlined
                    style={{ fontSize: '16px', color: '#e86060' }}
                  />
                </Popconfirm>
305 306 307
              </Tooltip>
            </>
          )}
皮倩雯's avatar
皮倩雯 committed
308
          {record.state == 1 && (
309
            <>
310
              {console.log(record.state, 'record.state1')}
311
              <Tooltip title="解冻用户">
皮倩雯's avatar
皮倩雯 committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
                <Popconfirm
                  placement="bottomRight"
                  title={
                    <p>
                      即将解冻用户{' '}
                      <span className={styles.redText}>
                        {voca.stripTags(record.loginName)}
                      </span>
                      ,是否确认解冻?
                    </p>
                  }
                  okText="确认"
                  cancelText="取消"
                  onConfirm={() => freezeUser(record)}
                >
                  <UserOutlined
                    style={{ fontSize: '16px', color: '#1890ff' }}
                  />
                </Popconfirm>
331 332 333
              </Tooltip>
            </>
          )}
mayongxin's avatar
mayongxin committed
334
          <Tooltip title="用户鉴权">
335
            <Popconfirm
336 337 338
              placement="bottomRight"
              title={
                <div style={{ width: '130px' }}>
339 340 341
                  <Form form={form}>
                    <Item>
                      <Radio.Group
342
                        value={selectValue}
343 344 345 346 347 348 349 350 351
                        onChange={onTypeChange}
                      >
                        <Space direction="vertical">
                          <Radio value={0}>访客</Radio>
                          <Radio value={1}>普通用户</Radio>
                          <Radio value={2}>管理员</Radio>
                          <Radio value={3}>超级管理员</Radio>
                        </Space>
                      </Radio.Group>
352
                    </Item>
353 354
                  </Form>
                </div>
355 356 357 358 359
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => authUser(record)}
            >
360 361 362 363
              <LockOutlined
                onClick={() => jianquan(record)}
                style={{ fontSize: '16px', color: '#1890ff' }}
              />
364
            </Popconfirm>
mayongxin's avatar
mayongxin committed
365
          </Tooltip>
陈前坚's avatar
陈前坚 committed
366
          <Tooltip title="删除用户">
皮倩雯's avatar
皮倩雯 committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
            <Popconfirm
              placement="bottomRight"
              title={
                <p>
                  即将删除用户{' '}
                  <span className={styles.redText}>
                    {voca.stripTags(record.loginName)}
                  </span>
                  ,是否确认删除?
                </p>
              }
              // title={`确认删除用户${currentUser}`}
              okText="确认"
              cancelText="取消"
              onConfirm={() => deleteUser(record)}
            >
              <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} />
            </Popconfirm>
陈前坚's avatar
陈前坚 committed
385
          </Tooltip>
陈前坚's avatar
陈前坚 committed
386 387 388 389
        </Space>
      ),
    },
  ];
390

391 392 393 394
  // 获取搜索框的值
  const handleSearch = e => {
    setSearchWord(e.target.value);
  };
皮倩雯's avatar
皮倩雯 committed
395
  // 复选框
陈前坚's avatar
陈前坚 committed
396
  const rowSelection = {
397 398 399 400 401
    selectedRowKeys,
    onChange: (RowKeys, Rows) => {
      setSelectedRowKeys(RowKeys);
      setUserIDs(RowKeys.toString()); // 数组转字符串,逗号连接
      setOrgIDs(Rows.map(item => item.OUID).toString());
陈前坚's avatar
陈前坚 committed
402
      // 选中行数大于0时设置批量操作可行
403
      if (RowKeys.length > 0) {
404
        setSelectColor({});
陈前坚's avatar
陈前坚 committed
405 406 407 408 409 410
        setMultiOperate(false);
        setMultiOperateButtonType('primary');
      } else {
        setMultiOperate(true);
        setMultiOperateButtonType('default');
      }
陈前坚's avatar
陈前坚 committed
411 412
    },
  };
陈前坚's avatar
陈前坚 committed
413 414 415 416
  // 渲染机构树
  const mapTree = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
    return {
皮倩雯's avatar
皮倩雯 committed
417 418 419 420 421
      title: (
        <div className={styles.title}>
          <span className={styles.titleText}>{org.text}</span>
          <span className={styles.tip}>
            <Tooltip title="" className={styles.fs}>
皮倩雯's avatar
皮倩雯 committed
422
              <Dropdown overlay={orgButtonMenu} disabled={currentOrgOperate} >
423 424 425 426
                <PlusOutlined
                  style={{ marginLeft: 20 }}
                  onClick={e => e.stopPropagation()}
                />
皮倩雯's avatar
皮倩雯 committed
427 428 429 430
              </Dropdown>
            </Tooltip>

            <Dropdown overlay={orgButtonMenu1} disabled={currentOrgOperate}>
431 432 433 434
              <EllipsisOutlined
                style={{ marginLeft: 10, fontSize: '20px' }}
                onClick={e => e.stopPropagation()}
              />
皮倩雯's avatar
皮倩雯 committed
435 436 437 438
            </Dropdown>
          </span>
        </div>
      ),
陈前坚's avatar
陈前坚 committed
439 440 441 442 443
      key: org.id,
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map(i => mapTree(i)) : [],
    };
  };
444

陈前坚's avatar
陈前坚 committed
445
  // 重新渲染树
陈前坚's avatar
陈前坚 committed
446 447
  const updateTrees = () => {
    setTreeLoading(true);
mayongxin's avatar
mayongxin committed
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
    // getUserTree(-1, -1)
    //   .then(res => {
    //     if (res.length > 0) {
    //       setTreeLoading(false);
    //       setTreeData(res);
    //       setTreeDataCopy(res);
    //       // 第一次加载,默认选择第一个组织
    //       if (treeState) {
    //         onSelect([res[0].id], false);
    //         setTreeState(false);
    //       }
    //     } else {
    //       setTreeLoading(false);
    //       notification.error({
    //         message: '获取失败',
    //         description: res.message,
    //       });
    //     }
    //   })
    //   .catch(err => {
    //     setTreeLoading(false);
    //     message.error(err);
    //   });
皮倩雯's avatar
皮倩雯 committed
471 472 473 474
    GetOUTreeNew({ selectOU: -1 })
      .then(newres => {
        if (newres.code === 0) {
          let res = newres.data;
皮倩雯's avatar
皮倩雯 committed
475
          console.log(res)
陈前坚's avatar
陈前坚 committed
476
          setTreeLoading(false);
477
          setTreeData(res);
陈前坚's avatar
陈前坚 committed
478
          setTreeDataCopy(res);
479 480
          // 第一次加载,默认选择第一个组织
          if (treeState) {
陈前坚's avatar
陈前坚 committed
481
            onSelect([res[0].id], false);
482 483
            setTreeState(false);
          }
陈前坚's avatar
陈前坚 committed
484 485 486 487
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
皮倩雯's avatar
皮倩雯 committed
488
            // eslint-disable-next-line no-undef
陈前坚's avatar
陈前坚 committed
489 490
            description: res.message,
          });
陈前坚's avatar
陈前坚 committed
491 492 493
        }
      })
      .catch(err => {
陈前坚's avatar
陈前坚 committed
494
        setTreeLoading(false);
陈前坚's avatar
陈前坚 committed
495 496
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
497
  };
张烨's avatar
张烨 committed
498 499 500 501

  // 获取用户机构树
  useEffect(() => {
    updateTrees();
502
  }, []);
皮倩雯's avatar
皮倩雯 committed
503 504
  // 更新获取初始范围
  useEffect(() => {
mayongxin's avatar
mayongxin committed
505
    getOrgArea().then(res => {
506
      if (res.msg === 'Ok') {
皮倩雯's avatar
皮倩雯 committed
507
        setOrgAreas(res.Results);
mayongxin's avatar
mayongxin committed
508
      }
皮倩雯's avatar
皮倩雯 committed
509 510
    });
  }, [saveExtentFlag]);
陈前坚's avatar
陈前坚 committed
511

陈前坚's avatar
陈前坚 committed
512
  // 点击树节点,获取当前机构下所有用户
陈前坚's avatar
陈前坚 committed
513
  const onSelect = (props, e) => {
皮倩雯's avatar
皮倩雯 committed
514 515
    console.log(e)
    console.log(props)
陈前坚's avatar
陈前坚 committed
516
    setTableLoading(true);
陈前坚's avatar
陈前坚 committed
517
    if (e) {
皮倩雯's avatar
皮倩雯 committed
518
      setOrgTitle(e.node.title.props.children[0].props.children);
陈前坚's avatar
陈前坚 committed
519
    }
陈前坚's avatar
陈前坚 committed
520
    if (!props[0]) {
张烨's avatar
张烨 committed
521
      setCurrentSelectOrg(currentSelectOrg);
陈前坚's avatar
陈前坚 committed
522
    } else {
张烨's avatar
张烨 committed
523
      setCurrentSelectOrg(props[0]);
陈前坚's avatar
陈前坚 committed
524
    }
mayongxin's avatar
mayongxin committed
525
    // orgAreas.map((item)=>{
皮倩雯's avatar
皮倩雯 committed
526

mayongxin's avatar
mayongxin committed
527 528 529 530 531 532
    //     if(item.OUID == props[0]){
    //       setCurrentOrgArea(item.Extent)
    //       setCurrentOrgDistinct(item.AreaName)
    //     }
    // })
    GetMapSetByGroupID({
皮倩雯's avatar
皮倩雯 committed
533 534 535 536 537
      groupID: props[0],
    }).then(res => {
      if (res.code === 0) {
        setCurrentOrgArea(res.data.MapRange);
        setCurrentOrgDistinct(res.data.AreeName);
mayongxin's avatar
mayongxin committed
538
      }
皮倩雯's avatar
皮倩雯 committed
539
    });
张烨's avatar
张烨 committed
540
    setOrgID(props[0] || currentSelectOrg);
陈前坚's avatar
陈前坚 committed
541 542
    // 树节点变化(即props不为空)时才请求,避免重复请求
    if (props[0]) {
皮倩雯's avatar
皮倩雯 committed
543
      // eslint-disable-next-line no-console
陈前坚's avatar
陈前坚 committed
544 545
      getOneOUUserListNew(props[0] || currentSelectOrg)
        .then(res => {
546
          setCurrentOrgOperate(false); // 重置禁用当前机构操作为false
547
          setMultiOperate(true); // 重新禁止用户批量操作
548
          setSelectedRowKeys([]); // 重置选中用户数
陈前坚's avatar
陈前坚 committed
549 550 551 552
          if (res.code === 0) {
            setTableLoading(false);
            setSearchWord(''); // 搜索框置空
            setOrgTitle(res.data.GroupName);
553
            setDescription(res.data.Description);
陈前坚's avatar
陈前坚 committed
554 555 556 557 558 559 560 561 562 563 564 565 566 567
            // 返回用户表数据结构处理,扁平化
            const temp = flatten(getUsers(res.data));
            // 设置过滤字段
            let arr = temp.map(item => item.OUName);
            arr = arr.filter((value, index) => arr.indexOf(value) === index);
            setOrgFilters(arr.map(item => ({ text: item, value: item })));
            setTableLength(temp.length);
            const table = temp.map((item, index) => {
              item.key = index;
              return item;
            });
            setTableData(table);
          } else {
            setTableLoading(false);
皮倩雯's avatar
皮倩雯 committed
568 569 570 571
            // notification.error({
            //   message: '获取失败',
            //   description: res.msg,
            // });
陈前坚's avatar
陈前坚 committed
572 573 574
          }
        })
        .catch(err => {
陈前坚's avatar
陈前坚 committed
575
          setTableLoading(false);
陈前坚's avatar
陈前坚 committed
576 577 578 579 580
          message.error(err);
        });
    } else {
      setTableLoading(false);
    }
陈前坚's avatar
陈前坚 committed
581
  };
陈前坚's avatar
陈前坚 committed
582

陈前坚's avatar
陈前坚 committed
583
  // 返回用户表数据结构处理,扁平化
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
  const getUsers = orgObj => {
    let result = orgObj.Users;
    result.map(item => {
      item.OUID = orgObj.GroupId;
      item.OUName = orgObj.GroupName;
      return item;
    });
    if (orgObj.Childs.length > 0)
      result = [...result, ...orgObj.Childs.map(o => getUsers(o))];
    return result;
  };
  const flatten = arr => {
    while (arr.some(item => Array.isArray(item))) {
      arr = [].concat(...arr);
    }
    return arr;
  };
陈前坚's avatar
陈前坚 committed
601
  // 添加用户
602
  const addUser = e => {
陈前坚's avatar
陈前坚 committed
603 604
    setUserVisible(true);
  };
陈前坚's avatar
陈前坚 committed
605 606
  // 添加顶级机构
  const addOrg = () => {
陈前坚's avatar
陈前坚 committed
607
    setAddOrgVisible(true);
陈前坚's avatar
陈前坚 committed
608
    setOrgID('-1');
陈前坚's avatar
陈前坚 committed
609
  };
陈前坚's avatar
陈前坚 committed
610
  // 添加下级机构
611
  const addSubOrg = e => {
陈前坚's avatar
陈前坚 committed
612 613 614 615
    setAddOrgVisible(true);
  };
  // 编辑机构
  const editOrg = () => {
陈前坚's avatar
陈前坚 committed
616
    setEditOrgVisible(true);
陈前坚's avatar
陈前坚 committed
617
  };
陈前坚's avatar
陈前坚 committed
618 619
  // 删除机构
  const deleteOrg = () => {
陈前坚's avatar
陈前坚 committed
620
    setDeleteOrgVisible(true);
621 622
    // 删除后默认选择第一个组织
    setTreeState(true);
陈前坚's avatar
陈前坚 committed
623
  };
皮倩雯's avatar
皮倩雯 committed
624
  // 编辑机构范围
mayongxin's avatar
mayongxin committed
625
  const EditOrgScope = () => {
皮倩雯's avatar
皮倩雯 committed
626 627
    setEditOrgExtentVisible(true);
  };
陈前坚's avatar
陈前坚 committed
628

陈前坚's avatar
陈前坚 committed
629
  // 在currentUser变化后获取角色列表
陈前坚's avatar
陈前坚 committed
630
  useEffect(() => {
张烨's avatar
张烨 committed
631
    if (currentUser && currentUser.userID) {
陈前坚's avatar
陈前坚 committed
632 633
      getRoleList();
    }
张烨's avatar
张烨 committed
634
  }, [currentUser]);
陈前坚's avatar
陈前坚 committed
635

陈前坚's avatar
陈前坚 committed
636
  /** ***用户批量操作****** */
陈前坚's avatar
陈前坚 committed
637
  // 关联角色
陈前坚's avatar
陈前坚 committed
638
  const relateRoles = () => {
陈前坚's avatar
陈前坚 committed
639
    getEmptyRoleList();
陈前坚's avatar
陈前坚 committed
640
    setRoleVisible(true);
陈前坚's avatar
陈前坚 committed
641
    setMultiRelateRoles(true);
陈前坚's avatar
陈前坚 committed
642 643 644 645 646 647 648 649 650 651 652 653
  };
  // 更改机构
  const changeOrgs = () => {
    setChangeOrgVisible(true);
    setMultiChangeOrgs(true);
  };
  // 删除用户
  const deleteUsers = () => {
    setDeleteUserVisible(true);
    setMultiDelete(true);
  };

陈前坚's avatar
陈前坚 committed
654
  /** ***右侧表格相关操作****** */
陈前坚's avatar
陈前坚 committed
655
  // 关联角色
陈前坚's avatar
陈前坚 committed
656
  const relateRole = record => {
陈前坚's avatar
陈前坚 committed
657
    setRoleVisible(true);
张烨's avatar
张烨 committed
658
    setCurrentUser(record);
659
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
660
  };
陈前坚's avatar
陈前坚 committed
661
  // 更改机构
陈前坚's avatar
陈前坚 committed
662
  const changeOrg = record => {
663
    setChangeOrgVisible(true);
张烨's avatar
张烨 committed
664
    setCurrentUser(record);
665
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
666
    setCurrentSelectOldOrg(record.OUID);
陈前坚's avatar
陈前坚 committed
667
  };
陈前坚's avatar
陈前坚 committed
668
  // 修改密码
陈前坚's avatar
陈前坚 committed
669 670
  const changePassword = record => {
    setPasswordVisible(true);
张烨's avatar
张烨 committed
671
    setCurrentUser(record);
672
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
673
  };
陈前坚's avatar
陈前坚 committed
674
  // 编辑用户
陈前坚's avatar
陈前坚 committed
675 676
  const editUser = record => {
    setEditUserVisible(true);
张烨's avatar
张烨 committed
677
    setCurrentUser(record);
678
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
679
  };
陈前坚's avatar
陈前坚 committed
680
  // 冻结用户
陈前坚's avatar
陈前坚 committed
681
  const freezeUser = record => {
皮倩雯's avatar
皮倩雯 committed
682
    // setFreezeUserVisible(true);
张烨's avatar
张烨 committed
683
    setCurrentUser(record);
684
    setSelectColor(record);
皮倩雯's avatar
皮倩雯 committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
    let state = '';
    console.log(record);
    if (record.state === '0' || record.state === null) {
      state = '1';
    } else {
      state = '0';
    }
    UserStateOUNew({ ouid: record.userID })
      .then(res => {
        if (res.code === 0) {
          // 重新获取用户表
          // eslint-disable-next-line no-unused-expressions
          currentSelectOrg === '-1'
            ? submitSearchUser()
            : onSelect([currentSelectOrg]);
          notification.success({
            message: '提交成功',
            duration: 2,
          });
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
715
  };
陈前坚's avatar
陈前坚 committed
716
  // 删除用户
陈前坚's avatar
陈前坚 committed
717
  const deleteUser = record => {
皮倩雯's avatar
皮倩雯 committed
718 719
    console.log(record.userName);
    setCurrentUser(record.userName);
720
    setSelectColor(record);
皮倩雯's avatar
皮倩雯 committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    DeleteUserNew({
      userID: record.userID,
      ouID: record.OUID,
    })
      .then(res => {
        if (res.code === 0) {
          notification.success({
            message: '提交成功',
            duration: 2,
          });
          // eslint-disable-next-line no-unused-expressions
          currentSelectOrg === '-1'
            ? submitSearchUser()
            : onSelect([currentSelectOrg]);
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
746
  };
747

皮倩雯's avatar
皮倩雯 committed
748
  // 用户鉴权
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
  //   useEffect(() => {
  //     currentUser.userID
  //     GetUserAuthSet({
  //         UserId: currentUser.userID
  //     }).then(
  //         res => {
  //             if(res.code == 0){
  //                 setSelctValue(res.data)
  //                 console.log(selectValue);
  //                 console.log(res.data);
  //             }
  //         }
  //     )
  // }, [currentUser])
  const jianquan = record => {
    GetUserAuthSet({
      UserId: record.userID,
    }).then(res => {
      if (res.code == 0) {
        setSelctValue(res.data);
        console.log(res.data);
      }
    });
  };
  const onTypeChange = value => {
774
    setSelctValue(value.target.value);
775
  };
776
  const authUser = (record) => {
mayongxin's avatar
mayongxin committed
777
    setCurrentUser(record);
778 779 780 781 782 783
    console.log(selectValue)
    AddUserAuthSetting({ 
      userId: record.userID,
      userLevel: selectValue 
    }).then(res => {
      if (res.code === 0) {
784
        message.info('提交成功');
785
      }
786
    });
皮倩雯's avatar
皮倩雯 committed
787
  };
788

陈前坚's avatar
陈前坚 committed
789 790
  // 查找用户
  const submitSearchUser = () => {
mayongxin's avatar
mayongxin committed
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
    // getUserByKey(searchWord)
    //   .then(res => {
    //     if (res.success) {
    //       setSelectedRowKeys([]); // 重置选中用户数
    //       setCurrentOrgOperate(true); // 禁止当前机构操作
    //       setMultiOperate(true); // 禁用批量操作
    //       setOrgTitle('全部机构搜索结果'); // 设置表头
    //       setCurrentSelectOrg('-1'); // 清空选中机构
    //       setTableData(res.root);
    //       setTableLength(res.root.length);
    //     } else {
    //       notification.error({
    //         message: '提交失败',
    //         description: res.message,
    //       });
    //     }
    //   })
    //   .catch(err => {
    //     message.error(err);
    //   });
皮倩雯's avatar
皮倩雯 committed
811
    GetUserByKeyNew({ key: searchWord })
陈前坚's avatar
陈前坚 committed
812
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
813
        if (res.code === 0) {
814
          setSelectedRowKeys([]); // 重置选中用户数
815
          setCurrentOrgOperate(true); // 禁止当前机构操作
816
          setMultiOperate(true); // 禁用批量操作
817
          setOrgTitle('全部机构搜索结果'); // 设置表头
818
          setCurrentSelectOrg('-1'); // 清空选中机构
皮倩雯's avatar
皮倩雯 committed
819
          console.log(res.data);
mayongxin's avatar
mayongxin committed
820 821
          setTableData(res.data);
          setTableLength(res.data.length);
陈前坚's avatar
陈前坚 committed
822 823 824 825 826 827 828 829 830 831 832
        } else {
          notification.error({
            message: '提交失败',
            description: res.message,
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
  };
张烨's avatar
张烨 committed
833

陈前坚's avatar
陈前坚 committed
834 835
  /** ***表单提交相关操作****** */
  // 根据当前 userID 获取用户关联角色
陈前坚's avatar
陈前坚 committed
836
  const getRoleList = () => {
837
    setLoading(true);
mayongxin's avatar
mayongxin committed
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
    // getUserRelationList(currentUser.userID)
    //   .then(res => {
    //     setLoading(false);
    //     if (res.success) {
    //       const { roleList, stationList } = res;
    //       setRolelist(roleList);
    //       setStationlist(stationList);
    //     } else {
    //       notification.error({
    //         message: '提交失败',
    //         description: res.message,
    //       });
    //     }
    //   })
    //   .catch(err => {
    //     setLoading(false);
    //     setTableLoading(false);
    //     message.error(err);
    //   });
857
    console.log(currentUser.userID);
皮倩雯's avatar
皮倩雯 committed
858
    GetUserRelationListNew({ userID: currentUser.userID })
陈前坚's avatar
陈前坚 committed
859
      .then(res => {
860
        setLoading(false);
皮倩雯's avatar
皮倩雯 committed
861
        if (res.code === 0) {
mayongxin's avatar
mayongxin committed
862
          const { roleList, stationList } = res.data;
863 864
          setRolelist(roleList);
          setStationlist(stationList);
陈前坚's avatar
陈前坚 committed
865 866 867 868 869 870 871 872
        } else {
          notification.error({
            message: '提交失败',
            description: res.message,
          });
        }
      })
      .catch(err => {
873
        setLoading(false);
陈前坚's avatar
陈前坚 committed
874 875 876 877
        setTableLoading(false);
        message.error(err);
      });
  };
陈前坚's avatar
陈前坚 committed
878 879 880
  // 获取全部未勾选的角色列表与站点列表
  const getEmptyRoleList = () => {
    setLoading(true);
mayongxin's avatar
mayongxin committed
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
    // getUserRelationList('')
    //   .then(res => {
    //     setLoading(false);
    //     if (res.roleList && res.roleList.length > 0) {
    //       const { roleList, stationList } = res;
    //       setRolelist(roleList);
    //       setStationlist(stationList);
    //     } else {
    //       notification.error({
    //         message: '提交失败',
    //         description: res.message,
    //       });
    //     }
    //   })
    //   .catch(err => {
    //     setLoading(false);
    //     setTableLoading(false);
    //     message.error(err);
    //   });
皮倩雯's avatar
皮倩雯 committed
900
    GetUserRelationListNew({ userID: '' })
陈前坚's avatar
陈前坚 committed
901 902
      .then(res => {
        setLoading(false);
皮倩雯's avatar
皮倩雯 committed
903
        if (res.code === 0) {
mayongxin's avatar
mayongxin committed
904
          const { roleList, stationList } = res.data;
陈前坚's avatar
陈前坚 committed
905 906 907
          setRolelist(roleList);
          setStationlist(stationList);
        } else {
908
          console.log(err);
皮倩雯's avatar
皮倩雯 committed
909 910 911 912
          // notification.error({
          //   message: '提交失败',
          //   description: res.message,
          // });
陈前坚's avatar
陈前坚 committed
913 914 915 916 917 918 919 920
        }
      })
      .catch(err => {
        setLoading(false);
        setTableLoading(false);
        message.error(err);
      });
  };
陈前坚's avatar
陈前坚 committed
921
  // 提交-更改机构
皮倩雯's avatar
皮倩雯 committed
922
  const submitChangeOrg = () => {
mayongxin's avatar
mayongxin committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
    // addToOrg(currentUser.userID, currentUser.OUID, newOrgID)
    // .then(res => {
    //   if (res.success) {
    //     setChangeOrgVisible(false);
    //     // 跳转到新组织机构下的用户表
    //     onSelect([newOrgID]);
    //     // setExpandedKeys([`${newOrgID}`]);
    //     notification.success({
    //       message: '提交成功',
    //       duration: 2,
    //     });
    //   } else {
    //     notification.error({
    //       message: '提交失败',
    //       description: res.message,
    //     });
    //   }
    // })
    // .catch(err => {
    //   message.error(err);
    // });
    JumpToAnotherOUNew({
皮倩雯's avatar
皮倩雯 committed
945 946 947
      userID: currentUser.userID,
      oldOUID: currentUser.OUID,
      newOUID: newOrgID,
mayongxin's avatar
mayongxin committed
948
    })
陈前坚's avatar
陈前坚 committed
949
      .then(res => {
陈前坚's avatar
陈前坚 committed
950 951 952 953
        if (res.code === 0) {
          setChangeOrgVisible(false);
          // 跳转到新组织机构下的用户表
          onSelect([newOrgID]);
皮倩雯's avatar
皮倩雯 committed
954
          // setExpandedKeys([`${newOrgID}`]);
陈前坚's avatar
陈前坚 committed
955 956
          notification.success({
            message: '提交成功',
957
            duration: 2,
陈前坚's avatar
陈前坚 committed
958 959 960 961
          });
        } else {
          notification.error({
            message: '提交失败',
陈前坚's avatar
陈前坚 committed
962
            description: res.msg,
陈前坚's avatar
陈前坚 committed
963 964 965 966 967 968
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
皮倩雯's avatar
皮倩雯 committed
969
  };
970

皮倩雯's avatar
皮倩雯 committed
971 972 973 974 975 976 977 978 979 980 981
  // 提交-批量更改机构
  const submitChangeOrgs = () =>
    addToOrgs(userIDs, orgIDs, newOrgID)
      .then(res => {
        if (res.code === 0) {
          setChangeOrgVisible(false);
          // 跳转到新组织机构下的用户表
          const temp = orgIDs.split(',');
          // 批量更改机构成功后设置老的orgIDs为全部是newOrgID的数组,并转字符串
          setOrgIDs(temp.map(() => newOrgID).toString());
          onSelect([newOrgID]);
陈前坚's avatar
陈前坚 committed
982 983
          notification.success({
            message: '提交成功',
984
            duration: 2,
陈前坚's avatar
陈前坚 committed
985 986 987 988
          });
        } else {
          notification.error({
            message: '提交失败',
mayongxin's avatar
mayongxin committed
989
            description: res.msg,
陈前坚's avatar
陈前坚 committed
990 991 992 993 994 995
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
皮倩雯's avatar
皮倩雯 committed
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053

  // 提交-冻结用户
  // const submitFreezeUser = () => {
  //   let state = '';
  //   if (currentUser.state === '0' || currentUser.state === null) {
  //     state = '1';
  //   } else {
  //     state = '0';
  //   }
  //   // postSetUserState(currentUser.userID, state)
  //   //   .then(res => {
  //   //     if (res.success) {
  //   //       setFreezeUserVisible(false);
  //   //       // 重新获取用户表
  //   //       // eslint-disable-next-line no-unused-expressions
  //   //       currentSelectOrg === '-1'
  //   //         ? submitSearchUser()
  //   //         : onSelect([currentSelectOrg]);
  //   //       notification.success({
  //   //         message: '提交成功',
  //   //         duration: 2,
  //   //       });
  //   //     } else {
  //   //       notification.error({
  //   //         message: '提交失败',
  //   //         description: res.message,
  //   //       });
  //   //     }
  //   //   })
  //   //   .catch(err => {
  //   //     setTableLoading(false);
  //   //     message.error(err);
  //   //   });
  //   UserStateOUNew({ ouid: currentUser.userID, state })
  //     .then(res => {
  //       if (res.code === 0) {
  //         // setFreezeUserVisible(false);
  //         // 重新获取用户表
  //         // eslint-disable-next-line no-unused-expressions
  //         currentSelectOrg === '-1'
  //           ? submitSearchUser()
  //           : onSelect([currentSelectOrg]);
  //         notification.success({
  //           message: '提交成功',
  //           duration: 2,
  //         });
  //       } else {
  //         notification.error({
  //           message: '提交失败',
  //           description: res.msg,
  //         });
  //       }
  //     })
  //     .catch(err => {
  //       setTableLoading(false);
  //       message.error(err);
  //     });
  // };
陈前坚's avatar
陈前坚 committed
1054
  // 提交-删除用户
陈前坚's avatar
陈前坚 committed
1055
  const submitDeleteUser = () => {
mayongxin's avatar
mayongxin committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
    // postDeleteUser(currentUser.userID)
    //   .then(res => {
    //     if (res.success) {
    //       setDeleteUserVisible(false);
    //       notification.success({
    //         message: '提交成功',
    //         duration: 2,
    //       });
    //       // eslint-disable-next-line no-unused-expressions
    //       currentSelectOrg === '-1'
    //         ? submitSearchUser()
    //         : onSelect([currentSelectOrg]);
    //     } else {
    //       notification.error({
    //         message: '提交失败',
    //         description: res.message,
    //       });
    //     }
    //   })
    //   .catch(err => {
    //     setTableLoading(false);
    //     message.error(err);
    //   });
皮倩雯's avatar
皮倩雯 committed
1079 1080 1081 1082 1083 1084
    DeleteUserNew({
      userID: currentUser.userID,
      ouID: currentUser.OUID,
    })
      .then(res => {
        if (res.code === 0) {
陈前坚's avatar
陈前坚 committed
1085 1086
          notification.success({
            message: '提交成功',
1087
            duration: 2,
陈前坚's avatar
陈前坚 committed
1088
          });
1089 1090 1091 1092
          // eslint-disable-next-line no-unused-expressions
          currentSelectOrg === '-1'
            ? submitSearchUser()
            : onSelect([currentSelectOrg]);
陈前坚's avatar
陈前坚 committed
1093 1094 1095
        } else {
          notification.error({
            message: '提交失败',
mayongxin's avatar
mayongxin committed
1096
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
  };
  // 提交-批量删除用户
  const submitDeleteUsers = () => {
陈前坚's avatar
陈前坚 committed
1107
    multiDeleteUsers(userIDs)
陈前坚's avatar
陈前坚 committed
1108 1109 1110 1111 1112
      .then(res => {
        if (res.code === 0) {
          setDeleteUserVisible(false);
          notification.success({
            message: '提交成功',
1113
            duration: 2,
陈前坚's avatar
陈前坚 committed
1114
          });
1115
          // 重新获取用户表,查找用户时currentSelectOrg为'-1',无需跳转
1116
          // eslint-disable-next-line no-unused-expressions
1117
          currentSelectOrg === '-1'
1118 1119
            ? submitSearchUser()
            : onSelect([currentSelectOrg]);
陈前坚's avatar
陈前坚 committed
1120
        } else {
陈前坚's avatar
陈前坚 committed
1121 1122
          notification.error({
            message: '提交失败',
陈前坚's avatar
陈前坚 committed
1123
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1124 1125 1126 1127 1128 1129 1130
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
1131
  };
1132
  // 重置默认第一个
1133
  const handleReset = () => {
1134 1135 1136 1137 1138 1139
    GetOUTreeNew({ selectOU: -1 })
      .then(newres => {
        if (newres.code === 0) {
          let res = newres.data;
          setTreeLoading(false);
          setSearchWord('');
1140
          setFilteredValue([])
1141
          // 第一次加载,默认选择第一个组织
1142
          onSelect([res[0].id], false);
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
1156
  };
1157 1158 1159 1160
  const onChangeInput = (filters) =>{
    setFilteredValue(filters.OUName);
  }

皮倩雯's avatar
皮倩雯 committed
1161
  // 更改机构范围
mayongxin's avatar
mayongxin committed
1162 1163 1164 1165
  const submitExtent = (extent, areaName) => {
    if (extent) {
      setOrgArea({
        OUID: currentSelectOrg,
皮倩雯's avatar
皮倩雯 committed
1166 1167
        areaName,
        extent,
mayongxin's avatar
mayongxin committed
1168
      }).then(res => {
1169
        if (res.msg === '') {
皮倩雯's avatar
皮倩雯 committed
1170 1171
          setSaveExtentFlag(saveExtentFlag + 1);
          message.success('机构范围设置成功!');
mayongxin's avatar
mayongxin committed
1172
        } else {
皮倩雯's avatar
皮倩雯 committed
1173
          message.warn(res.Message);
mayongxin's avatar
mayongxin committed
1174
        }
皮倩雯's avatar
皮倩雯 committed
1175
      });
mayongxin's avatar
mayongxin committed
1176
    }
皮倩雯's avatar
皮倩雯 committed
1177 1178
    setEditOrgExtentVisible(false);
  };
陈前坚's avatar
陈前坚 committed
1179

皮倩雯's avatar
皮倩雯 committed
1180
  const addChange =e=>{
1181
    console.log(e)
皮倩雯's avatar
皮倩雯 committed
1182 1183
    e.domEvent.stopPropagation()
  }
陈前坚's avatar
陈前坚 committed
1184 1185 1186
  /** ***操作按钮**** */
  // 机构操作
  const orgButtonMenu = (
皮倩雯's avatar
皮倩雯 committed
1187 1188
    <Menu onClick={e =>addChange(e)}>
      <Menu.Item key="1" onClick={addUser} icon={<UserAddOutlined />}>
陈前坚's avatar
陈前坚 committed
1189 1190 1191
        添加用户
      </Menu.Item>
      <Menu.Item key="2" onClick={addSubOrg} icon={<UsergroupAddOutlined />}>
陈前坚's avatar
陈前坚 committed
1192
        添加下级机构
陈前坚's avatar
陈前坚 committed
1193
      </Menu.Item>
皮倩雯's avatar
皮倩雯 committed
1194 1195 1196
    </Menu>
  );
  const orgButtonMenu1 = (
皮倩雯's avatar
皮倩雯 committed
1197
    <Menu onClick={e =>addChange(e)}>
陈前坚's avatar
陈前坚 committed
1198
      <Menu.Item key="3" onClick={editOrg} icon={<EditOutlined />}>
陈前坚's avatar
陈前坚 committed
1199
        编辑当前机构
陈前坚's avatar
陈前坚 committed
1200 1201
      </Menu.Item>
      <Menu.Item key="4" onClick={deleteOrg} icon={<DeleteOutlined />}>
陈前坚's avatar
陈前坚 committed
1202
        删除当前机构
陈前坚's avatar
陈前坚 committed
1203
      </Menu.Item>
皮倩雯's avatar
皮倩雯 committed
1204 1205 1206 1207 1208
      <Menu.Item
        key="5"
        onClick={EditOrgScope}
        icon={<BorderlessTableOutlined />}
      >
mayongxin's avatar
mayongxin committed
1209 1210
        编辑机构范围
      </Menu.Item>
陈前坚's avatar
陈前坚 committed
1211 1212 1213 1214 1215
    </Menu>
  );
  // 用户批量操作
  const userButtonMenu = (
    <Menu>
1216
      <Menu.Item key="1" onClick={relateRoles} icon={<IdcardOutlined />}>
陈前坚's avatar
陈前坚 committed
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
        批量关联角色
      </Menu.Item>
      <Menu.Item key="2" onClick={changeOrgs} icon={<ApartmentOutlined />}>
        批量更改机构
      </Menu.Item>
      <Menu.Item key="3" onClick={deleteUsers} icon={<DeleteOutlined />}>
        批量删除用户
      </Menu.Item>
    </Menu>
  );

陈前坚's avatar
陈前坚 committed
1228
  return (
1229 1230
    <PageContainer className={styles.userManageContainer}>
      <div className={styles.contentContainer}>
陈前坚's avatar
陈前坚 committed
1231
        {/* 左侧机构树 */}
陈前坚's avatar
陈前坚 committed
1232
        <Spin spinning={treeLoading} tip="loading...">
陈前坚's avatar
陈前坚 committed
1233
          <Card
皮倩雯's avatar
皮倩雯 committed
1234
            style={{overflowY:'hidden'}}
陈前坚's avatar
陈前坚 committed
1235 1236 1237 1238 1239 1240
            className={classnames({
              [styles.orgContainer]: true,
              [styles.orgContainerHide]: !treeVisible,
            })}
          >
            <div>
皮倩雯's avatar
皮倩雯 committed
1241 1242
              <span
                style={{
1243
                  fontSize: '15px ',
皮倩雯's avatar
皮倩雯 committed
1244
                  fontWeight: 'bold',
皮倩雯's avatar
皮倩雯 committed
1245
                  marginLeft: '15px'
皮倩雯's avatar
皮倩雯 committed
1246 1247 1248 1249
                }}
              >
                机构列表
              </span>
陈前坚's avatar
陈前坚 committed
1250
              <Tooltip title="添加顶级机构">
皮倩雯's avatar
皮倩雯 committed
1251
                <PlusSquareFilled
陈前坚's avatar
陈前坚 committed
1252 1253 1254
                  onClick={() => addOrg()}
                  style={{
                    color: '#1890FF',
1255
                    fontSize: '25px',
皮倩雯's avatar
皮倩雯 committed
1256
                    verticalAlign: 'middle',
皮倩雯's avatar
皮倩雯 committed
1257
                    marginLeft: '67%'
陈前坚's avatar
陈前坚 committed
1258 1259 1260
                  }}
                />
              </Tooltip>
皮倩雯's avatar
皮倩雯 committed
1261
              <hr style={{ width: '95%', color: '#eeecec' ,marginLeft: '15px'}} />
陈前坚's avatar
陈前坚 committed
1262 1263 1264
              {treeData.length > 0 && (
                <Tree
                  showIcon="true"
皮倩雯's avatar
皮倩雯 committed
1265
                  // showLine={{ showLeafIcon: false }}
陈前坚's avatar
陈前坚 committed
1266 1267
                  blockNode
                  autoExpandParent
陈前坚's avatar
陈前坚 committed
1268
                  // expandedKeys={[currentSelectOrg]}
1269
                  // defaultExpandAll
陈前坚's avatar
陈前坚 committed
1270 1271
                  selectedKeys={[currentSelectOrg]}
                  onSelect={onSelect}
1272 1273
                  height={
                    treeData.length && treeData.length > 30
皮倩雯's avatar
皮倩雯 committed
1274
                      ? treeData.length * 15+30
1275 1276
                      : 1000
                  }
陈前坚's avatar
陈前坚 committed
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
                  treeData={treeData.map(t => mapTree(t))}
                />
              )}
            </div>
            <div className={styles.switcher}>
              {treeVisible && (
                <Tooltip title="隐藏机构列表">
                  <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                </Tooltip>
              )}
              {!treeVisible && (
                <Tooltip title="显示机构列表">
                  <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                </Tooltip>
              )}
            </div>
陈前坚's avatar
陈前坚 committed
1293
          </Card>
陈前坚's avatar
陈前坚 committed
1294
        </Spin>
1295

陈前坚's avatar
陈前坚 committed
1296
        {/* 右侧用户表 */}
陈前坚's avatar
陈前坚 committed
1297 1298 1299 1300 1301 1302
        <div
          className={classnames({
            [styles.userContainer]: true,
            [styles.userContainerHide]: !treeVisible,
          })}
        >
陈前坚's avatar
陈前坚 committed
1303
          <div style={{ height: '50px' }}>
1304 1305
            <p
              className={styles.title}
1306 1307 1308
              title={`${orgTitle}(已选${
                selectedRowKeys.length
              }/共${tableLength}人)`}
1309 1310
            >
              {orgTitle}(已选{selectedRowKeys.length}/共{tableLength}人
陈前坚's avatar
陈前坚 committed
1311 1312
            </p>
            <span style={{ float: 'right', margin: '10px' }}>
陈前坚's avatar
陈前坚 committed
1313
              <Search
1314 1315
                style={{ width: 260 }}
                placeholder="搜索登录名/用户姓名/手机号"
陈前坚's avatar
陈前坚 committed
1316 1317 1318 1319 1320
                onSearch={submitSearchUser}
                onChange={e => handleSearch(e)}
                enterButton
                value={searchWord}
              />
皮倩雯's avatar
皮倩雯 committed
1321

1322 1323 1324
              <Button icon={<SyncOutlined />} onClick={handleReset}>
                重置
              </Button>
皮倩雯's avatar
皮倩雯 committed
1325

陈前坚's avatar
陈前坚 committed
1326 1327 1328 1329 1330
              <Dropdown overlay={userButtonMenu} disabled={multiOperate}>
                <Button type={multiOperateButtonType}>
                  用户批量操作 <DownOutlined />
                </Button>
              </Dropdown>
陈前坚's avatar
陈前坚 committed
1331 1332
            </span>
          </div>
1333
          <Table
陈前坚's avatar
陈前坚 committed
1334
            rowSelection={{
1335
              type: 'checkbox',
陈前坚's avatar
陈前坚 committed
1336 1337
              ...rowSelection,
            }}
1338
            rowClassName={setRowClassName}
陈前坚's avatar
陈前坚 committed
1339
            size="small"
陈前坚's avatar
陈前坚 committed
1340
            rowKey={record => record.userID}
陈前坚's avatar
陈前坚 committed
1341
            locale={zhCN}
陈前坚's avatar
陈前坚 committed
1342
            bordered
1343 1344 1345
            columns={columns}
            dataSource={tableData}
            loading={tableLoading}
1346 1347
            scroll={{ x: 'max-content', y: 'calc(100vh - 210px)' }}
            // scroll={{ x: 'max-content' }}
陈前坚's avatar
陈前坚 committed
1348
            pagination={{
陈前坚's avatar
陈前坚 committed
1349 1350
              showTotal: (total, range) =>
                `第${range[0]}-${range[1]} 条/共 ${total} 条`,
陈前坚's avatar
陈前坚 committed
1351
              pageSizeOptions: [10, 20, 50, 100],
陈前坚's avatar
陈前坚 committed
1352
              defaultPageSize: 20,
陈前坚's avatar
陈前坚 committed
1353 1354 1355
              showQuickJumper: true,
              showSizeChanger: true,
            }}
1356
            onChange={onChangeInput}
1357
          />
1358
        </div>
1359

陈前坚's avatar
陈前坚 committed
1360
        {/* Modal弹框 */}
1361
        {/* 添加用户 */}
陈前坚's avatar
陈前坚 committed
1362 1363 1364 1365 1366
        <AddUserModal
          title={`在${orgTitle}下添加用户`}
          visible={userVisible}
          orgID={orgID}
          onCancel={() => setUserVisible(false)}
1367
          onSelect={() => onSelect([orgID])}
陈前坚's avatar
陈前坚 committed
1368
        />
1369
        {/* 添加下级机构 */}
1370
        <AddSubOrgModal
陈前坚's avatar
陈前坚 committed
1371
          title={orgID === '-1' ? '添加顶级机构' : `在${orgTitle}下添加机构`}
1372
          visible={addOrgVisible}
1373
          orgID={orgID}
1374
          onCancel={() => setAddOrgVisible(false)}
1375 1376 1377
          onSelect={onSelect}
          updateTrees={updateTrees}
        />
1378
        {/* 编辑机构 */}
1379
        <EditOrgModal
陈前坚's avatar
陈前坚 committed
1380
          title={`编辑${orgTitle}`}
1381
          visible={editOrgVisible}
1382 1383 1384
          orgID={orgID}
          orgTitle={orgTitle}
          description={description}
1385
          onCancel={() => setEditOrgVisible(false)}
1386 1387 1388 1389 1390
          onSelect={onSelect}
          updateTrees={updateTrees}
        />
        {/* 删除机构 */}
        <DeleteOrgModal
1391 1392
          title="确认删除机构"
          visible={deleteOrgVisible}
1393 1394
          orgID={orgID}
          updateTrees={updateTrees}
1395
          onCancel={() => setDeleteOrgVisible(false)}
1396
        />
陈前坚's avatar
陈前坚 committed
1397
        {/* 关联角色 */}
1398 1399 1400 1401
        <RelateRoleModal
          currentUser={currentUser}
          userIDs={userIDs}
          currentSelectOrg={currentSelectOrg}
陈前坚's avatar
陈前坚 committed
1402
          visible={roleVisible}
1403 1404 1405 1406 1407
          rolelist={rolelist}
          loading={loading}
          stationlist={stationlist}
          multiRelateRoles={multiRelateRoles}
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
1408 1409 1410 1411
          onCancel={() => {
            setRoleVisible(false);
            setMultiRelateRoles(false);
          }}
1412
        />
陈前坚's avatar
陈前坚 committed
1413
        {/* 更改机构 */}
1414 1415 1416
        <Modal
          title="更改机构"
          visible={changeOrgVisible}
陈前坚's avatar
陈前坚 committed
1417 1418 1419 1420 1421
          onOk={multiChangeOrgs ? submitChangeOrgs : submitChangeOrg}
          onCancel={() => {
            setChangeOrgVisible(false);
            setMultiChangeOrgs(false);
          }}
1422 1423
          okText="确认"
          cancelText="取消"
1424
          width="500px"
1425
        >
张烨's avatar
张烨 committed
1426
          <span>请选择要更改的目标机构:</span>
陈前坚's avatar
陈前坚 committed
1427
          {changeOrgVisible && treeDataCopy.length > 0 && (
陈前坚's avatar
陈前坚 committed
1428 1429
            <Tree
              showIcon="true"
陈前坚's avatar
陈前坚 committed
1430
              showLine={{ showLeafIcon: false }}
1431
              // defaultExpandAll
陈前坚's avatar
陈前坚 committed
1432 1433 1434 1435 1436 1437
              // 未切换时原先的节点,注意要转字符串
              selectedKeys={[`${currentSelectOldOrg}`]}
              onSelect={value => {
                setNewOrgID(value[0]);
                // 切换后选中的节点
                setCurrentSelectOldOrg(value[0]);
陈前坚's avatar
陈前坚 committed
1438
              }}
陈前坚's avatar
陈前坚 committed
1439
              treeData={treeDataCopy.map(t => mapTree(t))}
陈前坚's avatar
陈前坚 committed
1440 1441
            />
          )}
1442
        </Modal>
陈前坚's avatar
陈前坚 committed
1443
        {/* 修改密码 */}
1444
        <ChangePasswordModal
陈前坚's avatar
陈前坚 committed
1445
          visible={passwordVisible}
1446
          currentUser={currentUser}
1447 1448
          submitSearchUser={submitSearchUser}
          currentSelectOrg={currentSelectOrg}
1449
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
1450
          onCancel={() => setPasswordVisible(false)}
1451
        />
陈前坚's avatar
陈前坚 committed
1452
        {/* 编辑用户 */}
1453
        <EditUserModal
陈前坚's avatar
陈前坚 committed
1454
          visible={editUserVisible}
1455
          currentUser={currentUser}
1456 1457
          submitSearchUser={submitSearchUser}
          currentSelectOrg={currentSelectOrg}
1458
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
1459
          onCancel={() => setEditUserVisible(false)}
1460
        />
陈前坚's avatar
陈前坚 committed
1461
        {/* 冻结用户 */}
皮倩雯's avatar
皮倩雯 committed
1462
        {/* <Modal
1463
          title="请确认"
陈前坚's avatar
陈前坚 committed
1464 1465 1466 1467 1468 1469
          visible={freezeUserVisible}
          onOk={submitFreezeUser}
          onCancel={() => setFreezeUserVisible(false)}
          okText="确认"
          cancelText="取消"
        >
张烨's avatar
张烨 committed
1470 1471
          <p>
            即将{+currentUser.state ? '激活' : '冻结'}用户{' '}
1472 1473 1474
            <span className={styles.redText}>
              {voca.stripTags(currentUser.loginName)}
            </span>
张烨's avatar
张烨 committed
1475 1476 1477
            ,是否确认
            {+currentUser.state ? '激活' : '冻结'}?
          </p>
皮倩雯's avatar
皮倩雯 committed
1478
        </Modal> */}
1479
        {/* 多选删除用户 */}
1480 1481 1482
        <Modal
          title="确认删除用户"
          visible={deleteUserVisible}
陈前坚's avatar
陈前坚 committed
1483 1484 1485 1486 1487
          onOk={multiDelete ? submitDeleteUsers : submitDeleteUser}
          onCancel={() => {
            setDeleteUserVisible(false);
            setMultiDelete(false);
          }}
1488 1489 1490
          okText="确认"
          cancelText="取消"
        >
1491
          <p>将删除多个用户, 是否确认删除?</p>
1492
        </Modal>
mayongxin's avatar
mayongxin committed
1493
        <MapScopeEditModal
mayongxin's avatar
mayongxin committed
1494
          mapId={createGuid()}
mayongxin's avatar
mayongxin committed
1495 1496 1497 1498 1499 1500 1501
          visible={editOrgExtentVisible}
          stationId={currentSelectOrg}
          onCancel={() => setEditOrgExtentVisible(false)}
          confirmModal={submitExtent}
          distinct={currentOrgDistinct}
          extent={currentOrgArea}
        />
1502
        {/* <AuthModal
皮倩雯's avatar
皮倩雯 committed
1503 1504 1505
          visible={authUserVisible}
          currentUser={currentUser}
          onCancel={() => setAuthUserVisible(false)}
1506
        /> */}
陈前坚's avatar
陈前坚 committed
1507 1508
      </div>
    </PageContainer>
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
    // <DraggleLayout
    //     containerWidth={550}
    //     containerHeight={220}
    //     min={50}
    //     max={500}
    //     initLeftWidth={100}
    //     onWidthChange={w => setWidth(w)}
    //     handler={
    //       <div
    //         style={{
    //           width: 4,
    //           height: '100%',
    //           background: 'rgb(77, 81, 100)',
    //         }}
    //       />
    //     }
    //   >
    //     <div
    //       style={{
    //         backgroundColor: `rgb(36, 205, 208)`,
    //         color: `#fff`,
    //         height: '100%',
    //         display: 'flex',
    //         alignItems: 'center',
    //         justifyContent: 'center',
    //       }}
    //     >
    //       left
    //     </div>
    //     <div
    //       style={{
    //         backgroundColor: `rgb(116, 140, 253)`,
    //         color: `#fff`,
    //         height: '100%',
    //         display: 'flex',
    //         alignItems: 'center',
    //         justifyContent: 'center',
    //       }}
    //     >
    //       right
    //     </div>
    //   </DraggleLayout>
陈前坚's avatar
陈前坚 committed
1551 1552 1553 1554
  );
};

export default UserManage;