UserManage.jsx 65.3 KB
Newer Older
1
/* eslint-disable no-unused-expressions */
皮倩雯's avatar
皮倩雯 committed
2
/* eslint-disable eqeqeq */
3
import React, { useState, useEffect, useRef } from 'react';
陈前坚's avatar
陈前坚 committed
4
import {
5
  Tree,
陈前坚's avatar
陈前坚 committed
6 7 8 9 10 11 12
  Table,
  Space,
  message,
  Modal,
  Input,
  notification,
  Tooltip,
陈前坚's avatar
陈前坚 committed
13
  Card,
陈前坚's avatar
陈前坚 committed
14
  Button,
15
  Spin,
陈前坚's avatar
陈前坚 committed
16 17
  Dropdown,
  Menu,
皮倩雯's avatar
皮倩雯 committed
18
  Popconfirm,
19 20
  Form,
  Radio,
21
  Pagination,
陈前坚's avatar
陈前坚 committed
22 23
} from 'antd';
import {
24
  UserOutlined,
陈前坚's avatar
陈前坚 committed
25
  UserAddOutlined,
陈前坚's avatar
陈前坚 committed
26
  UsergroupAddOutlined,
陈前坚's avatar
陈前坚 committed
27
  EditOutlined,
陈前坚's avatar
陈前坚 committed
28
  EditTwoTone,
陈前坚's avatar
陈前坚 committed
29
  DeleteOutlined,
30
  IdcardOutlined,
陈前坚's avatar
陈前坚 committed
31
  UnlockOutlined,
陈前坚's avatar
陈前坚 committed
32
  ApartmentOutlined,
陈前坚's avatar
陈前坚 committed
33
  StopOutlined,
陈前坚's avatar
陈前坚 committed
34 35
  DoubleLeftOutlined,
  DoubleRightOutlined,
陈前坚's avatar
陈前坚 committed
36
  DownOutlined,
mayongxin's avatar
mayongxin committed
37
  BorderlessTableOutlined,
皮倩雯's avatar
皮倩雯 committed
38 39 40 41 42
  LockOutlined,
  PlusSquareFilled,
  EllipsisOutlined,
  PlusOutlined,
  SyncOutlined,
43
  ClusterOutlined,
皮倩雯's avatar
皮倩雯 committed
44
  MessageOutlined,
陈前坚's avatar
陈前坚 committed
45
} from '@ant-design/icons';
46
import PageContainer from '@/components/BasePageContainer';
陈前坚's avatar
陈前坚 committed
47 48
import voca from 'voca';
import zhCN from 'antd/es/locale/zh_CN';
49 50
import {
  addToOrg,
陈前坚's avatar
陈前坚 committed
51
  addToOrgs,
52 53 54
  getOneOUUserListNew,
  getUserRelationList,
  getUserTree,
皮倩雯's avatar
皮倩雯 committed
55
  // eslint-disable-next-line import/named
张烨's avatar
张烨 committed
56 57
  deleteUser as postDeleteUser,
  setUserState as postSetUserState,
陈前坚's avatar
陈前坚 committed
58
  multiDeleteUsers,
mayongxin's avatar
mayongxin committed
59
  setOrgArea,
mayongxin's avatar
mayongxin committed
60
  getOrgArea,
mayongxin's avatar
mayongxin committed
61
  GetMapSetByGroupID,
mayongxin's avatar
mayongxin committed
62 63 64 65 66 67
  GetOUTreeNew,
  GetUserRelationListNew,
  GetUserByKeyNew,
  UserStateOUNew,
  JumpToAnotherOUNew,
  DeleteUserNew,
皮倩雯's avatar
皮倩雯 committed
68
  loadAllUserRole,
69
  DragGroup,
70 71
  GetAllSite,
  SetGroupManager,
皮倩雯's avatar
皮倩雯 committed
72
  ChangeSMSState,
邓超's avatar
邓超 committed
73
} from '@/services/userManage/api';
74
import { AddUserAuthSetting, GetUserAuthSet } from '@/services/database/api';
75
import TreeComponents from '@/components/ExpendableTree';
陈前坚's avatar
陈前坚 committed
76
import classnames from 'classnames';
77
import DraggleLayout from 'components/DraggleLayout';
陈前坚's avatar
陈前坚 committed
78
import AddUserModal from './AddUserModal';
79 80 81 82 83 84
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
85 86
import MapScopeEditModal from '@/components/MapScope';
import AuthModal from './AuthModal';
陈前坚's avatar
陈前坚 committed
87
import styles from './UserManage.less';
皮倩雯's avatar
皮倩雯 committed
88
import { createGuid } from '@/utils/transformUtil';
邓超's avatar
邓超 committed
89 90 91 92 93
const TdCell = props => {
  // onMouseEnter, onMouseLeave在数据量多的时候,会严重阻塞表格单元格渲染,严重影响性能
  const { onMouseEnter, onMouseLeave, ...restProps } = props;
  return <td {...restProps} />;
};
陈前坚's avatar
陈前坚 committed
94 95

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

98 99
  const [form] = Form.useForm();
  const { Item } = Form;
100
  const [selectValue, setSelctValue] = useState(); // 用户鉴权
101 102

  const [width, setWidth] = useState(50);
陈前坚's avatar
陈前坚 committed
103
  const [treeLoading, setTreeLoading] = useState(false);
陈前坚's avatar
陈前坚 committed
104
  const [tableLoading, setTableLoading] = useState(false);
陈前坚's avatar
陈前坚 committed
105
  const [loading, setLoading] = useState(true);
106
  const [currentOrgOperate, setCurrentOrgOperate] = useState(false); // 是否禁用当前机构操作
陈前坚's avatar
陈前坚 committed
107 108
  const [multiOperate, setMultiOperate] = useState(true); // 是否禁用用户批量操作
  const [multiOperateButtonType, setMultiOperateButtonType] = useState(''); // 更改批量操作按钮样式
陈前坚's avatar
陈前坚 committed
109

陈前坚's avatar
陈前坚 committed
110
  const [treeData, setTreeData] = useState([]); // 用户机构树
陈前坚's avatar
陈前坚 committed
111
  const [treeDataCopy, setTreeDataCopy] = useState([]); // 机构树数据备份,用于更改机构
陈前坚's avatar
陈前坚 committed
112 113
  const [treeState, setTreeState] = useState(true); // 树第一次加载
  const [treeVisible, setTreeVisible] = useState(true); // 树是否可见
陈前坚's avatar
陈前坚 committed
114
  const [tableData, setTableData] = useState([]); // 用户表
115
  const [selectColor, setSelectColor] = useState({}); // 当前选中颜色,操作时设置
陈前坚's avatar
陈前坚 committed
116
  const [orgFilters, setOrgFilters] = useState([]); // 用户列筛选
陈前坚's avatar
陈前坚 committed
117
  const [searchWord, setSearchWord] = useState(''); // 关键字
皮倩雯's avatar
皮倩雯 committed
118
  const [currentSelectOrg1, setCurrentSelectOrg1] = useState('-1');
119
  const [currentSelectOrg, setCurrentSelectOrg] = useState('-1'); // 左侧机构树-选中组织,字符串类型默认全部机构'-1',注意用户表中的OUID是数字
陈前坚's avatar
陈前坚 committed
120
  const [currentSelectOldOrg, setCurrentSelectOldOrg] = useState([]); // 更改机构时的树-原先选中组织
皮倩雯's avatar
皮倩雯 committed
121
  const [showSearchStyle, setShowSearchStyle] = useState(false); // 是否显示模糊查询样式
陈前坚's avatar
陈前坚 committed
122

陈前坚's avatar
陈前坚 committed
123 124 125 126 127
  /** ***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
128
  const [editOrgExtentVisible, setEditOrgExtentVisible] = useState(false); // 删除机构
陈前坚's avatar
陈前坚 committed
129
  const [roleVisible, setRoleVisible] = useState(false); // 关联角色
陈前坚's avatar
陈前坚 committed
130 131 132
  const [changeOrgVisible, setChangeOrgVisible] = useState(false); // 更改机构
  const [passwordVisible, setPasswordVisible] = useState(false); // 修改密码
  const [editUserVisible, setEditUserVisible] = useState(false); // 编辑用户
皮倩雯's avatar
皮倩雯 committed
133
  // const [freezeUserVisible, setFreezeUserVisible] = useState(false); // 冻结用户
陈前坚's avatar
陈前坚 committed
134
  const [deleteUserVisible, setDeleteUserVisible] = useState(false); // 删除用户
mayongxin's avatar
mayongxin committed
135
  const [authUserVisible, setAuthUserVisible] = useState(false); // 鉴权用户
陈前坚's avatar
陈前坚 committed
136

陈前坚's avatar
陈前坚 committed
137
  const [orgTitle, setOrgTitle] = useState('当前机构'); // 弹框标题
138
  const [groupId, setGroupId] = useState();
皮倩雯's avatar
皮倩雯 committed
139
  const [orgTitle1, setOrgTitle1] = useState('当前机构'); // 弹框标题
140
  const [description, setDescription] = useState(''); // 机构描述信息
141 142
  const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 已选用户数,机构改变时重置
  const [tableLength, setTableLength] = useState(0); // 当前机构用户总数
陈前坚's avatar
陈前坚 committed
143
  const [orgID, setOrgID] = useState(); // 当前选择的机构ID
陈前坚's avatar
陈前坚 committed
144 145
  const [newOrgID, setNewOrgID] = useState(); // 更改机构新选择的ID
  const [currentUser, setCurrentUser] = useState({}); // 当前用户
146

皮倩雯's avatar
皮倩雯 committed
147 148 149
  const [mult, setMult] = useState(''); // 判断是否是批量关联
  const [multiRoleList, setMultiRoleList] = useState([]);
  const [multistationList, setMultiStationList] = useState([]);
陈前坚's avatar
陈前坚 committed
150 151 152 153
  const [userIDs, setUserIDs] = useState(''); // 批量删除的用户
  const [orgIDs, setOrgIDs] = useState(''); // 批量操作的机构
  const [multiDelete, setMultiDelete] = useState(false); // 是否批量删除用户
  const [multiChangeOrgs, setMultiChangeOrgs] = useState(false); // 是否批量更改机构
陈前坚's avatar
陈前坚 committed
154
  const [multiRelateRoles, setMultiRelateRoles] = useState(false); // 是否批量更改机构
陈前坚's avatar
陈前坚 committed
155

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

皮倩雯's avatar
皮倩雯 committed
159 160 161 162
  const [orgAreas, setOrgAreas] = useState([]);
  const [currentOrgArea, setCurrentOrgArea] = useState('');
  const [currentOrgDistinct, setCurrentOrgDistinct] = useState('');
  const [saveExtentFlag, setSaveExtentFlag] = useState(0);
皮倩雯's avatar
皮倩雯 committed
163
  const [filteredValue, setFilteredValue] = useState([]);
皮倩雯's avatar
皮倩雯 committed
164 165
  const [keep1, setKeep1] = useState([4]); // 存储树选择
  const [id, setId] = useState('');
陈前坚's avatar
陈前坚 committed
166
  const { Search } = Input;
167
  const [hoverItemIndex, setHoverItemIndex] = useState(0); // hover流程索引
168
  const [keepTree, setKeepTree] = useState([]); // 保存所有一级id用于控制只展开一项一级菜单
169 170

  const [expendKey, setExpendKey] = useState(''); // 保存默认展开项
171
  const [expendKeyOrg, setExpendKeyOrg] = useState(''); // 保存默认展开项
172 173 174
  const [menuID, setMenuID] = useState(''); // 选中的树IDs
  const [keepId, setKeepId] = useState('');
  const [flag, setFlag] = useState(1); // 刷新标志
175 176
  const userContainer = useRef();
  const flagRef = useRef(1);
177 178

  const [searchWordOrg, setSearchWordOrg] = useState('');
179
  const [keepDataList, setKeepDataList] = useState([]);
180
  const [siteList, setSiteList] = useState([]);
181
  const setRowClassName = record =>
182
    record.userId === selectColor.userId ? styles.clickRowStyle : '';
183

184 185 186 187 188 189
  const [demoVisivle, setDemoVisible] = useState(false);
  const [searchTreeValue, setSearchTreeValue] = useState('');

  const [total, setTotal] = useState(0);
  const [pageSize, setPageSize] = useState(20);
  const [currentPage, setCurrentPage] = useState(1);
190
  const [treeDataTotal, setTreeDataTotal] = useState();
陈前坚's avatar
陈前坚 committed
191 192 193 194 195 196
  // 用户表列名
  const columns = [
    {
      title: '登录名',
      dataIndex: 'loginName',
      key: 'loginName',
197
      // width: 100,
198
      // fixed: 'left',
皮倩雯's avatar
皮倩雯 committed
199
      render: item => searchStyle(item),
陈前坚's avatar
陈前坚 committed
200 201 202 203 204
    },
    {
      title: '用户姓名',
      dataIndex: 'userName',
      key: 'userName',
205
      // width: 100,
皮倩雯's avatar
皮倩雯 committed
206
      render: item => searchStyle(item),
陈前坚's avatar
陈前坚 committed
207
    },
208 209
    {
      title: '所在机构',
210 211
      dataIndex: 'groupName',
      key: 'groupName',
212
      // width: 150,
213
      ellipsis: true,
陈前坚's avatar
陈前坚 committed
214
      filters: orgFilters,
215
      filteredValue,
216
      onFilter: (value, record) => record.groupName === value,
217
    },
陈前坚's avatar
陈前坚 committed
218 219 220 221
    {
      title: '手机号码',
      dataIndex: 'phone',
      key: 'phone',
222
      // width: 150,
陈前坚's avatar
陈前坚 committed
223
      ellipsis: true,
皮倩雯's avatar
皮倩雯 committed
224 225 226
      render: text => {
        if (text) {
          return searchStyle(text);
227
        }
tianfen's avatar
tianfen committed
228
        return <span>未绑定</span>;
229
      },
陈前坚's avatar
陈前坚 committed
230
    },
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    // {
    //   title: '钉钉账户',
    //   dataIndex: 'ddid',
    //   key: 'ddid',
    //   // width: 150,
    //   render: record => {
    //     if (record) {
    //       return (
    //         <Tooltip title={record}>
    //           <span style={{ color: '#50aefc', cursor: 'pointer' }}>已绑定</span>
    //         </Tooltip>
    //       );
    //     }
    //     return <span>未绑定</span>;
    //   },
    // },
    // {
    //   title: '微信账户',
    //   dataIndex: 'wxid',
    //   key: 'wxid',
    //   // width: 140,
    //   render: record => {
    //     if (record) {
    //       return (
    //         <Tooltip title={record}>
    //           <span style={{ color: '#50aefc', cursor: 'pointer' }}>已绑定</span>
    //         </Tooltip>
    //       );
    //     }
    //     return <span>未绑定</span>;
    //   },
    // },
263 264 265 266
    {
      title: '站点权限',
      dataIndex: 'stationCount',
      key: 'stationCount',
267
      width: 100,
268
    },
陈前坚's avatar
陈前坚 committed
269
    {
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
      title: '权限设置',
      key: 'action',
      // fixed: 'right',
      width: 150,
      align: 'center',
      render: record => (
        <Space size="middle">
          <Tooltip title="关联权限">
            <IdcardOutlined
              onClick={() => relateRole(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="更改机构">
            <ApartmentOutlined
              onClick={() => changeOrg(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="设置为主管">
            <Popconfirm
              placement="bottomRight"
              title={
                <p>
                  确定将用户
                  <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                  设置为{orgTitle}主管吗?
                </p>
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                console.log(groupId, 'groupId');
                SetGroupManager({ groupId, userId: record.userId }).then(res => {
                  if (res.code === 0) {
                    // eslint-disable-next-line no-unused-expressions
                    currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
                  } else {
                    notification.error({
                      message: '设置失败',
                      description: res.msg,
                    });
                  }
                });
              }}
            >
              <UserOutlined
                style={{ fontSize: '16px', color: record.isManager ? '#FAAD14' : '#1890FF' }}
              />
            </Popconfirm>
          </Tooltip>
皮倩雯's avatar
皮倩雯 committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
          <Tooltip title={record.isSendSMS === 0 ? '不接收短信' : '接收短信'}>
            <Popconfirm
              placement="bottomRight"
              title={
                record.isSendSMS === 0 ? (
                  <p>
                    确定设置用户
                    <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                    可以接收短信吗?
                  </p>
                ) : (
                  <p>
                    确定设置用户
                    <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                    不可接收短信吗?
                  </p>
                )
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                ChangeSMSState({ userId: record.userId }).then(res => {
                  if (res.code === 0) {
                    currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
                  } else {
                    notification.error({
                      message: '设置失败',
                      description: res.msg,
                    });
                  }
                });
              }}
            >
              <MessageOutlined
                style={{ fontSize: '16px', color: record.isSendSMS === 0 ? '#e86060' : '#1890FF' }}
              />
            </Popconfirm>
          </Tooltip>
359 360
        </Space>
      ),
陈前坚's avatar
陈前坚 committed
361 362 363 364
    },
    {
      title: '操作',
      key: 'action',
陈前坚's avatar
陈前坚 committed
365
      // fixed: 'right',
366
      width: 100,
367
      align: 'center',
陈前坚's avatar
陈前坚 committed
368
      render: record => (
陈前坚's avatar
陈前坚 committed
369
        <Space size="middle">
370
          {/* <Tooltip title="关联权限">
邓超's avatar
邓超 committed
371 372 373 374 375 376 377 378 379 380 381
            <IdcardOutlined
              onClick={() => relateRole(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
          <Tooltip title="更改机构">
            <ApartmentOutlined
              onClick={() => changeOrg(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
          </Tooltip>
382 383 384 385 386 387 388 389 390 391 392 393 394 395
          <Tooltip title="设置为主管">
            <Popconfirm
              placement="bottomRight"
              title={
                <p>
                  确定将用户
                  <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                  设置为{orgTitle}主管吗?
                </p>
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                console.log(groupId, 'groupId');
396
                SetGroupManager({ groupId, userId: record.userId }).then(res => {
397 398 399 400 401 402 403 404 405 406 407 408 409
                  if (res.code === 0) {
                    // eslint-disable-next-line no-unused-expressions
                    currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
                  } else {
                    notification.error({
                      message: '设置失败',
                      description: res.msg,
                    });
                  }
                });
              }}
            >
              <UserOutlined
410
                style={{ fontSize: '16px', color: record.isManager ? '#FAAD14' : '#1890FF' }}
411 412
              />
            </Popconfirm>
413
          </Tooltip> */}
414
          {/* <Tooltip title="修改密码">
陈前坚's avatar
陈前坚 committed
415
            <UnlockOutlined
陈前坚's avatar
陈前坚 committed
416 417 418
              onClick={() => changePassword(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
419 420
          </Tooltip> */}
          {/* <Tooltip title="编辑用户">
421
            <EditTwoTone onClick={() => editUser(record)} style={{ fontSize: '16px' }} />
422
          </Tooltip> */}
皮倩雯's avatar
皮倩雯 committed
423
          {(record.state == 0 || record.state == null) && (
424
            <>
425
              {record.loginName == 'panda' || record.loginName == 'admin' ? (
邓超's avatar
邓超 committed
426
                <StopOutlined style={{ fontSize: '16px', color: '#1890ff' }} disabled />
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
              ) : (
                <Tooltip title="冻结用户">
                  <Popconfirm
                    placement="bottomRight"
                    title={
                      <p>
                        即将冻结用户{' '}
                        <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
                        ,是否确认冻结?
                      </p>
                    }
                    okText="确认"
                    cancelText="取消"
                    onConfirm={() => freezeUser(record)}
                  >
442
                    <StopOutlined style={{ fontSize: '16px', color: '#1890ff' }} />
443 444 445
                  </Popconfirm>
                </Tooltip>
              )}
446 447
            </>
          )}
皮倩雯's avatar
皮倩雯 committed
448
          {record.state == 1 && (
449
            <>
450
              {console.log(record.state, 'record.state1')}
451
              <Tooltip title="解冻用户">
皮倩雯's avatar
皮倩雯 committed
452 453 454 455
                <Popconfirm
                  placement="bottomRight"
                  title={
                    <p>
456
                      即将解冻用户
457
                      <span className={styles.redText}>{voca.stripTags(record.loginName)}</span>
皮倩雯's avatar
皮倩雯 committed
458 459 460 461 462 463 464
                      ,是否确认解冻?
                    </p>
                  }
                  okText="确认"
                  cancelText="取消"
                  onConfirm={() => freezeUser(record)}
                >
465
                  <StopOutlined style={{ fontSize: '16px', color: '#e86060' }} />
皮倩雯's avatar
皮倩雯 committed
466
                </Popconfirm>
467 468 469
              </Tooltip>
            </>
          )}
470
          {/* <Tooltip title="用户鉴权">
471
            <Popconfirm
472 473 474
              placement="bottomRight"
              title={
                <div style={{ width: '130px' }}>
475 476
                  <Form form={form}>
                    <Item>
皮倩雯's avatar
皮倩雯 committed
477
                      <Radio.Group value={selectValue} onChange={onTypeChange}>
478 479 480 481 482 483 484
                        <Space direction="vertical">
                          <Radio value={0}>访客</Radio>
                          <Radio value={1}>普通用户</Radio>
                          <Radio value={2}>管理员</Radio>
                          <Radio value={3}>超级管理员</Radio>
                        </Space>
                      </Radio.Group>
485
                    </Item>
486 487
                  </Form>
                </div>
488 489 490 491 492
              }
              okText="确认"
              cancelText="取消"
              onConfirm={() => authUser(record)}
            >
493 494 495 496
              <LockOutlined
                onClick={() => jianquan(record)}
                style={{ fontSize: '16px', color: '#1890ff' }}
              />
497
            </Popconfirm>
498
          </Tooltip> */}
499
          {record.loginName == 'panda' || record.loginName == 'admin' ? (
邓超's avatar
邓超 committed
500
            <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} disabled />
501
          ) : (
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
            <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>
518
          )}
陈前坚's avatar
陈前坚 committed
519 520 521 522
        </Space>
      ),
    },
  ];
523 524 525 526 527

  useEffect(() => {
    setExpendKey(menuID);
    console.log(expendKey);
  }, [menuID]);
528 529 530
  // 获取用户机构树
  useEffect(() => {
    window.addEventListener('resize', resizeListener);
531 532 533 534 535 536
    GetAllSite().then(res => {
      if (res.code === 0) {
        setSiteList(res.data.map(item => ({ value: item.GroupId, label: item.GroupName })));
      }
    });

537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
    updateTrees();
    return () => {
      window.removeEventListener('resize', resizeListener);
    };
  }, []);

  // 更新获取初始范围
  useEffect(() => {
    getOrgArea().then(res => {
      if (res.msg === 'Ok') {
        console.log(res);
        setOrgAreas(res.Results);
      }
    });
  }, [saveExtentFlag]);
552 553 554 555 556 557 558 559

  useEffect(() => {
    if (!changeOrgVisible) {
      setExpendKeyOrg('');
      setSearchWordOrg('');
      GetOUTreeNew({ keyword: '' })
        .then(newres => {
          if (newres.code === 0) {
560
            let res = newres.data.list;
561 562 563 564 565 566 567 568 569
            setTreeDataCopy(res);
          }
        })
        .catch(err => {
          setTreeLoading(false);
          message.error(err);
        });
    }
  }, [changeOrgVisible]);
570 571 572 573
  const resizeListener = () => {
    flagRef.current += 1;
    setFlag(flagRef.current);
  };
皮倩雯's avatar
皮倩雯 committed
574 575
  // 模糊查询匹配的样式
  const searchStyle = val => {
576 577 578
    if (!val) {
      return val;
    }
皮倩雯's avatar
皮倩雯 committed
579 580
    let n;
    if (showSearchStyle) {
581
      n = val.replace(new RegExp(searchWord, 'g'), `<span style='color:red'>${searchWord}</span>`);
皮倩雯's avatar
皮倩雯 committed
582 583 584 585 586
    } else {
      n = val;
    }
    return <div dangerouslySetInnerHTML={{ __html: n }} />;
  };
587 588 589 590
  // 获取搜索框的值
  const handleSearch = e => {
    setSearchWord(e.target.value);
  };
591 592 593 594 595 596 597 598 599 600

  // 获取搜索框的值
  const handleSearchOrg = e => {
    setSearchWordOrg(e.target.value);
  };

  const submitSearch = () => {
    GetOUTreeNew({ keyword: searchWordOrg })
      .then(newres => {
        if (newres.code === 0) {
601
          let res = newres.data.list;
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
          setTreeDataCopy(res);
          console.log(res);
          let aa = [];
          res.map(i => {
            if (i.children.length > 0) {
              aa.push(i.id);
            }
            console.log(i.id);
            aa = i.id;
          });
          setExpendKeyOrg(aa.toString());
        } else {
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
  };
皮倩雯's avatar
皮倩雯 committed
626
  // 复选框
陈前坚's avatar
陈前坚 committed
627
  const rowSelection = {
628 629
    selectedRowKeys,
    onChange: (RowKeys, Rows) => {
630 631
      console.log(RowKeys);
      console.log(Rows);
632
      setSelectedRowKeys(RowKeys);
皮倩雯's avatar
皮倩雯 committed
633
      getCheckList(RowKeys);
634
      setUserIDs(RowKeys.toString()); // 数组转字符串,逗号连接
635
      setOrgIDs(Rows.map(item => item.groupId).toString());
陈前坚's avatar
陈前坚 committed
636
      // 选中行数大于0时设置批量操作可行
637
      if (RowKeys.length > 0) {
638
        setSelectColor({});
陈前坚's avatar
陈前坚 committed
639 640 641 642 643 644
        setMultiOperate(false);
        setMultiOperateButtonType('primary');
      } else {
        setMultiOperate(true);
        setMultiOperateButtonType('default');
      }
陈前坚's avatar
陈前坚 committed
645 646
    },
  };
陈前坚's avatar
陈前坚 committed
647 648 649
  // 渲染机构树
  const mapTree = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
650 651 652
    const indexsearch = org.text.indexOf(searchTreeValue);
    const beforeStr = org.text.substring(0, indexsearch);
    const afterStr = org.text.slice(indexsearch + searchTreeValue.length);
陈前坚's avatar
陈前坚 committed
653
    return {
皮倩雯's avatar
皮倩雯 committed
654
      title: (
皮倩雯's avatar
皮倩雯 committed
655
        <div className={styles.title1}>
656 657
          <span className={styles.titleText}>
            {org.children.length == 0 ? (
658 659 660 661 662 663 664 665
              <ApartmentOutlined
                style={{
                  fontSize: '14px',
                  color: '#1890FF',
                  verticalAlign: 'middle',
                  marginTop: '-3px',
                }}
              />
666 667 668
            ) : (
              <span />
            )}
669 670 671 672 673 674 675 676 677
            {org.text.includes(searchTreeValue) && searchTreeValue != '' ? (
              <span>
                {beforeStr}
                <span className={styles.titleSearch}>{searchTreeValue}</span>
                {afterStr}
              </span>
            ) : (
              <span>{org.text}</span>
            )}
678
          </span>
679 680 681 682 683 684 685 686 687 688 689 690
          <span
            className={classnames({
              [styles.tip1]: true,
              [styles.listHover]: org === hoverItemIndex,
            })}
            onMouseEnter={() => {
              setHoverItemIndex(org);
            }}
            onMouseLeave={() => {
              setHoverItemIndex('');
            }}
          >
691
            <Tooltip title="添加用户" className={styles.fs1}>
692 693 694 695 696 697 698 699 700 701 702 703
              <UserAddOutlined
                style={{ marginLeft: 20, lineHeight: '24px' }}
                onClick={e => {
                  e.stopPropagation();
                  addUser();
                }}
                onMouseEnter={e => {
                  setOrgID(org);
                  setOrgTitle1(org.text);
                  console.log(org);
                }}
              />
皮倩雯's avatar
皮倩雯 committed
704
            </Tooltip>
皮倩雯's avatar
皮倩雯 committed
705
            <Dropdown overlay={orgButtonMenu1}>
706
              <EllipsisOutlined
707
                style={{ marginLeft: 10, fontSize: '20px', lineHeight: '24px' }}
708
                onClick={e => e.stopPropagation()}
皮倩雯's avatar
皮倩雯 committed
709 710 711 712
                onMouseEnter={e => {
                  setOrgID(org);
                  setOrgTitle1(org.text);
                  getDescription(org.id);
713
                  // getMapSetByGroupID(org.id);
皮倩雯's avatar
皮倩雯 committed
714 715 716 717
                  setCurrentSelectOrg1(org.id);
                  setId(org.text);
                  console.log(org);
                }}
718
              />
皮倩雯's avatar
皮倩雯 committed
719 720 721 722
            </Dropdown>
          </span>
        </div>
      ),
陈前坚's avatar
陈前坚 committed
723 724 725 726 727
      key: org.id,
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map(i => mapTree(i)) : [],
    };
  };
728

皮倩雯's avatar
皮倩雯 committed
729 730 731 732 733 734 735 736 737 738
  const mapTree1 = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
    return {
      title: org.text,
      key: org.id,
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map(i => mapTree1(i)) : [],
    };
  };

陈前坚's avatar
陈前坚 committed
739
  // 重新渲染树
740
  const updateTrees = e => {
陈前坚's avatar
陈前坚 committed
741
    setTreeLoading(true);
mayongxin's avatar
mayongxin committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
    // 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);
    //   });
765
    GetOUTreeNew({ groupId: -1, keyword: e })
皮倩雯's avatar
皮倩雯 committed
766
      .then(newres => {
767
        setTreeLoading(false);
皮倩雯's avatar
皮倩雯 committed
768
        if (newres.code === 0) {
769 770
          let res = newres.data.list;
          setTreeDataTotal(newres.data.count);
771
          console.log(res);
772

773
          setTreeData(res);
774
          // setTreeDataCopy(res);
皮倩雯's avatar
皮倩雯 committed
775 776 777 778 779
          let aa = [];
          res.forEach(i => {
            aa.push(i.id);
          });
          setKeepTree(aa);
780

781 782
          // 第一次加载,默认选择第一个组织
          if (treeState) {
皮倩雯's avatar
皮倩雯 committed
783
            onSelect([res[0].id]);
784 785
            setTreeState(false);
          }
陈前坚's avatar
陈前坚 committed
786 787 788 789
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
皮倩雯's avatar
皮倩雯 committed
790
            // eslint-disable-next-line no-undef
陈前坚's avatar
陈前坚 committed
791 792
            description: res.message,
          });
陈前坚's avatar
陈前坚 committed
793 794 795
        }
      })
      .catch(err => {
陈前坚's avatar
陈前坚 committed
796
        setTreeLoading(false);
陈前坚's avatar
陈前坚 committed
797 798
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
799
  };
张烨's avatar
张烨 committed
800

801 802 803
  const updateTrees1 = e => {
    console.log(e);
    setTreeLoading(true);
804
    GetOUTreeNew({ groupId: -1 })
805 806
      .then(newres => {
        if (newres.code === 0) {
807 808
          let res = newres.data.list;
          setTreeDataTotal(newres.data.count);
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
          console.log(res);
          setTreeLoading(false);
          setTreeData(res);
          setTreeDataCopy(res);
          let aa = [];
          res.forEach(i => {
            aa.push(i.id);
          });
          setKeepTree(aa);
          console.log(e);
          setMenuID(e.toString());
          setExpendKey(e);
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
  };

陈前坚's avatar
陈前坚 committed
836
  // 点击树节点,获取当前机构下所有用户
837
  const onSelect = (props, e, size, index) => {
皮倩雯's avatar
皮倩雯 committed
838 839 840 841
    if (e) {
      props[0] = e.node.key;
    } else {
      props[0] = props.toString();
842
    }
皮倩雯's avatar
皮倩雯 committed
843
    setKeep1(props);
陈前坚's avatar
陈前坚 committed
844
    setTableLoading(true);
陈前坚's avatar
陈前坚 committed
845
    if (!props[0]) {
张烨's avatar
张烨 committed
846
      setCurrentSelectOrg(currentSelectOrg);
皮倩雯's avatar
皮倩雯 committed
847
      setCurrentSelectOrg1(currentSelectOrg);
陈前坚's avatar
陈前坚 committed
848
    } else {
张烨's avatar
张烨 committed
849
      setCurrentSelectOrg(props[0]);
皮倩雯's avatar
皮倩雯 committed
850
      setCurrentSelectOrg1(props[0]);
陈前坚's avatar
陈前坚 committed
851
    }
mayongxin's avatar
mayongxin committed
852
    GetMapSetByGroupID({
皮倩雯's avatar
皮倩雯 committed
853 854 855
      groupID: props[0],
    }).then(res => {
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
856
        console.log(res);
皮倩雯's avatar
皮倩雯 committed
857
        if (res.code.MapRange != null) {
858 859 860
          setCurrentOrgArea(res.data.MapRange);
          setCurrentOrgDistinct(res.data.AreeName);
        }
mayongxin's avatar
mayongxin committed
861
      }
皮倩雯's avatar
皮倩雯 committed
862
    });
张烨's avatar
张烨 committed
863
    setOrgID(props[0] || currentSelectOrg);
陈前坚's avatar
陈前坚 committed
864 865
    // 树节点变化(即props不为空)时才请求,避免重复请求
    if (props[0]) {
866 867
      console.log(props[0]);
      setMenuID(props[0]);
皮倩雯's avatar
皮倩雯 committed
868
      // eslint-disable-next-line no-console
869 870

      setGroupId(props[0]);
871 872 873 874 875
      let sizedata = '';
      let currentData = '';
      if (currentSelectOrg !== props[0]) {
        setPageSize(20);
        setCurrentPage(1);
876 877
        sizedata = size || 20;
        currentData = index || 1;
878 879
      } else {
        // 分页查询
880 881
        sizedata = size || pageSize;
        currentData = index || currentPage;
882 883 884
      }

      getOneOUUserListNew(props[0] || currentSelectOrg, sizedata, currentData)
陈前坚's avatar
陈前坚 committed
885
        .then(res => {
886
          setCurrentOrgOperate(false); // 重置禁用当前机构操作为false
887
          setMultiOperate(true); // 重新禁止用户批量操作
888
          setSelectedRowKeys([]); // 重置选中用户数
陈前坚's avatar
陈前坚 committed
889
          if (res.code === 0) {
890
            setTotal(res.data.count);
陈前坚's avatar
陈前坚 committed
891 892 893 894
            setTableLoading(false);
            setSearchWord(''); // 搜索框置空
            setOrgTitle(res.data.GroupName);
            // 返回用户表数据结构处理,扁平化
895
            let temp = res.data.data;
陈前坚's avatar
陈前坚 committed
896
            // 设置过滤字段
897
            let arr = temp.map(item => item.groupName);
陈前坚's avatar
陈前坚 committed
898 899 900
            arr = arr.filter((value, index) => arr.indexOf(value) === index);
            setOrgFilters(arr.map(item => ({ text: item, value: item })));
            setTableLength(temp.length);
901
            let datalist = [];
陈前坚's avatar
陈前坚 committed
902
            const table = temp.map((item, index) => {
903
              if (item.loginName == 'panda' || item.loginName == 'admin') {
904
                datalist.push(item.userId);
905
              }
陈前坚's avatar
陈前坚 committed
906 907 908
              item.key = index;
              return item;
            });
909
            setKeepDataList(datalist);
皮倩雯's avatar
皮倩雯 committed
910
            setShowSearchStyle(false);
911
            console.log(table);
陈前坚's avatar
陈前坚 committed
912 913 914
            setTableData(table);
          } else {
            setTableLoading(false);
皮倩雯's avatar
皮倩雯 committed
915 916 917 918
            // notification.error({
            //   message: '获取失败',
            //   description: res.msg,
            // });
陈前坚's avatar
陈前坚 committed
919 920 921
          }
        })
        .catch(err => {
陈前坚's avatar
陈前坚 committed
922
          setTableLoading(false);
陈前坚's avatar
陈前坚 committed
923 924 925 926 927
          message.error(err);
        });
    } else {
      setTableLoading(false);
    }
陈前坚's avatar
陈前坚 committed
928
  };
陈前坚's avatar
陈前坚 committed
929

930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
  // // 添加用户刷新表数据
  // const onSelect1 = () => {
  //   console.log(orgID);
  //   setTableLoading(true);
  //   // eslint-disable-next-line no-console
  //   getOneOUUserListNew(orgID.id || currentSelectOrg, pageSize, currentPage)
  //     .then(res => {
  //       setCurrentOrgOperate(false); // 重置禁用当前机构操作为false
  //       setMultiOperate(true); // 重新禁止用户批量操作
  //       setSelectedRowKeys([]); // 重置选中用户数
  //       if (res.code === 0) {
  //         setTableLoading(false);
  //         setSearchWord(''); // 搜索框置空
  //         setOrgTitle(res.data.GroupName);
  //         // setDescription(res.data.Description);
  //         // 返回用户表数据结构处理,扁平化
  //         let temp = res.data.data;
  //         // const temp = flatten(getUsers(res.data));
  //         // 设置过滤字段
  //         let arr = temp.map(item => item.groupName);
  //         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;
  //         });
  //         setShowSearchStyle(false);
  //         setTableData(table);
  //       } else {
  //         setTableLoading(false);
  //       }
  //     })
  //     .catch(err => {
  //       setTableLoading(false);
  //       message.error(err);
  //     });
  // };
968

皮倩雯's avatar
皮倩雯 committed
969
  const getDescription = e => {
970
    getOneOUUserListNew(e, pageSize, currentPage).then(res => {
皮倩雯's avatar
皮倩雯 committed
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
      if (res.code === 0) {
        setDescription(res.data.Description);
      }
    });
  };

  const getMapSetByGroupID = e => {
    GetMapSetByGroupID({
      groupID: e,
    }).then(res => {
      if (res.code === 0) {
        console.log(res);
        setCurrentOrgArea(res.data.MapRange);
        setCurrentOrgDistinct(res.data.AreeName);
      }
    });
  };
陈前坚's avatar
陈前坚 committed
988
  // 返回用户表数据结构处理,扁平化
989 990 991 992 993 994 995 996 997 998
  // 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;
  // };
999 1000 1001 1002 1003 1004
  const flatten = arr => {
    while (arr.some(item => Array.isArray(item))) {
      arr = [].concat(...arr);
    }
    return arr;
  };
陈前坚's avatar
陈前坚 committed
1005
  // 添加用户
1006
  const addUser = e => {
陈前坚's avatar
陈前坚 committed
1007 1008
    setUserVisible(true);
  };
陈前坚's avatar
陈前坚 committed
1009 1010
  // 添加顶级机构
  const addOrg = () => {
陈前坚's avatar
陈前坚 committed
1011
    setAddOrgVisible(true);
陈前坚's avatar
陈前坚 committed
1012
    setOrgID('-1');
陈前坚's avatar
陈前坚 committed
1013
  };
陈前坚's avatar
陈前坚 committed
1014
  // 添加下级机构
1015
  const addSubOrg = e => {
陈前坚's avatar
陈前坚 committed
1016 1017 1018 1019
    setAddOrgVisible(true);
  };
  // 编辑机构
  const editOrg = () => {
陈前坚's avatar
陈前坚 committed
1020
    setEditOrgVisible(true);
陈前坚's avatar
陈前坚 committed
1021
  };
陈前坚's avatar
陈前坚 committed
1022 1023
  // 删除机构
  const deleteOrg = () => {
陈前坚's avatar
陈前坚 committed
1024
    setDeleteOrgVisible(true);
1025 1026 1027 1028 1029 1030 1031
    console.log(orgID);
    console.log(keep1);
    if (orgID.id == keep1) {
      setTreeState(true);
    } else {
      setTreeState(false);
    }
陈前坚's avatar
陈前坚 committed
1032
  };
皮倩雯's avatar
皮倩雯 committed
1033
  // 编辑机构范围
mayongxin's avatar
mayongxin committed
1034
  const EditOrgScope = () => {
皮倩雯's avatar
皮倩雯 committed
1035 1036
    setEditOrgExtentVisible(true);
  };
陈前坚's avatar
陈前坚 committed
1037

陈前坚's avatar
陈前坚 committed
1038
  // 在currentUser变化后获取角色列表
1039
  // useEffect(() => {
1040
  //   if (currentUser && currentUser.userId) {
1041 1042 1043
  //     getRoleList();
  //   }
  // }, [currentUser]);
陈前坚's avatar
陈前坚 committed
1044

陈前坚's avatar
陈前坚 committed
1045
  /** ***用户批量操作****** */
陈前坚's avatar
陈前坚 committed
1046
  // 关联角色
陈前坚's avatar
陈前坚 committed
1047
  const relateRoles = () => {
皮倩雯's avatar
皮倩雯 committed
1048
    setMult('Yes');
陈前坚's avatar
陈前坚 committed
1049
    getEmptyRoleList();
1050
    // getCheckList()
陈前坚's avatar
陈前坚 committed
1051
    setRoleVisible(true);
陈前坚's avatar
陈前坚 committed
1052
    setMultiRelateRoles(true);
陈前坚's avatar
陈前坚 committed
1053
  };
1054
  // 批量更改机构
陈前坚's avatar
陈前坚 committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
  const changeOrgs = () => {
    setChangeOrgVisible(true);
    setMultiChangeOrgs(true);
  };
  // 删除用户
  const deleteUsers = () => {
    setDeleteUserVisible(true);
    setMultiDelete(true);
  };

陈前坚's avatar
陈前坚 committed
1065
  /** ***右侧表格相关操作****** */
陈前坚's avatar
陈前坚 committed
1066
  // 关联角色
陈前坚's avatar
陈前坚 committed
1067
  const relateRole = record => {
1068
    // getEmptyRoleList(record.userId);
皮倩雯's avatar
皮倩雯 committed
1069 1070 1071
    setMult('No');
    console.log(record);
    getRoleList(record);
陈前坚's avatar
陈前坚 committed
1072
    setRoleVisible(true);
张烨's avatar
张烨 committed
1073
    setCurrentUser(record);
1074
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
1075
  };
陈前坚's avatar
陈前坚 committed
1076
  // 更改机构
陈前坚's avatar
陈前坚 committed
1077
  const changeOrg = record => {
1078
    setChangeOrgVisible(true);
1079
    setMultiChangeOrgs(false);
张烨's avatar
张烨 committed
1080
    setCurrentUser(record);
1081
    setSelectColor(record);
1082
    setCurrentSelectOldOrg(record.groupId);
陈前坚's avatar
陈前坚 committed
1083
  };
陈前坚's avatar
陈前坚 committed
1084
  // 修改密码
陈前坚's avatar
陈前坚 committed
1085 1086
  const changePassword = record => {
    setPasswordVisible(true);
张烨's avatar
张烨 committed
1087
    setCurrentUser(record);
1088
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
1089
  };
陈前坚's avatar
陈前坚 committed
1090
  // 编辑用户
陈前坚's avatar
陈前坚 committed
1091 1092
  const editUser = record => {
    setEditUserVisible(true);
张烨's avatar
张烨 committed
1093
    setCurrentUser(record);
1094
    setSelectColor(record);
陈前坚's avatar
陈前坚 committed
1095
  };
陈前坚's avatar
陈前坚 committed
1096
  // 冻结用户
陈前坚's avatar
陈前坚 committed
1097
  const freezeUser = record => {
1098
    console.log(currentUser);
皮倩雯's avatar
皮倩雯 committed
1099
    // setFreezeUserVisible(true);
张烨's avatar
张烨 committed
1100
    setCurrentUser(record);
1101
    setSelectColor(record);
皮倩雯's avatar
皮倩雯 committed
1102 1103 1104 1105 1106 1107 1108
    let state = '';
    console.log(record);
    if (record.state === '0' || record.state === null) {
      state = '1';
    } else {
      state = '0';
    }
1109
    UserStateOUNew({ ouid: record.userId })
皮倩雯's avatar
皮倩雯 committed
1110 1111 1112 1113
      .then(res => {
        if (res.code === 0) {
          // 重新获取用户表
          // eslint-disable-next-line no-unused-expressions
1114
          currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
皮倩雯's avatar
皮倩雯 committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
          notification.success({
            message: '提交成功',
            duration: 2,
          });
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
1130
  };
陈前坚's avatar
陈前坚 committed
1131
  // 删除用户
陈前坚's avatar
陈前坚 committed
1132
  const deleteUser = record => {
皮倩雯's avatar
皮倩雯 committed
1133 1134
    console.log(record.userName);
    setCurrentUser(record.userName);
1135
    setSelectColor(record);
皮倩雯's avatar
皮倩雯 committed
1136
    DeleteUserNew({
1137
      userId: record.userId,
皮倩雯's avatar
皮倩雯 committed
1138 1139 1140 1141 1142 1143 1144 1145
    })
      .then(res => {
        if (res.code === 0) {
          notification.success({
            message: '提交成功',
            duration: 2,
          });
          // eslint-disable-next-line no-unused-expressions
1146
          currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
皮倩雯's avatar
皮倩雯 committed
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
        } else {
          notification.error({
            message: '提交失败',
            description: res.msg,
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
陈前坚's avatar
陈前坚 committed
1158
  };
1159

皮倩雯's avatar
皮倩雯 committed
1160
  // 用户鉴权
1161
  //   useEffect(() => {
1162
  //     currentUser.userId
1163
  //     GetUserAuthSet({
1164
  //         UserId: currentUser.userId
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
  //     }).then(
  //         res => {
  //             if(res.code == 0){
  //                 setSelctValue(res.data)
  //                 console.log(selectValue);
  //                 console.log(res.data);
  //             }
  //         }
  //     )
  // }, [currentUser])
  const jianquan = record => {
    GetUserAuthSet({
1177
      UserId: record.userId,
1178
    }).then(res => {
皮倩雯's avatar
皮倩雯 committed
1179
      if (res.code === 0) {
1180 1181 1182 1183 1184 1185
        setSelctValue(res.data);
        console.log(res.data);
      }
    });
  };
  const onTypeChange = value => {
1186
    setSelctValue(value.target.value);
1187
  };
皮倩雯's avatar
皮倩雯 committed
1188
  const authUser = record => {
mayongxin's avatar
mayongxin committed
1189
    setCurrentUser(record);
皮倩雯's avatar
皮倩雯 committed
1190 1191
    console.log(selectValue);
    AddUserAuthSetting({
1192
      userId: record.userId,
皮倩雯's avatar
皮倩雯 committed
1193
      userLevel: selectValue,
1194 1195
    }).then(res => {
      if (res.code === 0) {
1196
        message.info('提交成功');
1197
      }
1198
    });
皮倩雯's avatar
皮倩雯 committed
1199
  };
1200

陈前坚's avatar
陈前坚 committed
1201 1202
  // 查找用户
  const submitSearchUser = () => {
1203 1204 1205 1206
    if (!searchWord || searchWord.trim(' ').length == 0) {
      message.warning('请输入搜索内容');
      return;
    }
1207
    setTableLoading(true);
1208 1209
    let data = searchWord != '' ? { key: searchWord } : '';
    GetUserByKeyNew(data)
陈前坚's avatar
陈前坚 committed
1210
      .then(res => {
1211
        setTableLoading(false);
皮倩雯's avatar
皮倩雯 committed
1212
        if (res.code === 0) {
1213
          setSelectedRowKeys([]); // 重置选中用户数
1214
          setCurrentOrgOperate(true); // 禁止当前机构操作
1215
          setMultiOperate(true); // 禁用批量操作
1216
          setOrgTitle('全部机构搜索结果'); // 设置表头
1217
          setCurrentSelectOrg('-1'); // 清空选中机构
皮倩雯's avatar
皮倩雯 committed
1218
          console.log(res.data);
皮倩雯's avatar
皮倩雯 committed
1219
          setShowSearchStyle(true);
mayongxin's avatar
mayongxin committed
1220 1221
          setTableData(res.data);
          setTableLength(res.data.length);
陈前坚's avatar
陈前坚 committed
1222 1223
        } else {
          notification.error({
皮倩雯's avatar
皮倩雯 committed
1224 1225 1226
            message: '提示',
            duration: 3,
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1227 1228 1229 1230 1231 1232 1233
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
  };
张烨's avatar
张烨 committed
1234

陈前坚's avatar
陈前坚 committed
1235
  /** ***表单提交相关操作****** */
1236
  // 根据当前 userId 获取用户关联角色
1237
  const getRoleList = e => {
1238
    setLoading(true);
1239
    GetUserRelationListNew({ userId: e.userId })
陈前坚's avatar
陈前坚 committed
1240
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
1241 1242
        console.log(111);

皮倩雯's avatar
皮倩雯 committed
1243
        if (res.code === 0) {
mayongxin's avatar
mayongxin committed
1244
          const { roleList, stationList } = res.data;
皮倩雯's avatar
皮倩雯 committed
1245
          console.log(roleList);
1246 1247
          setRolelist(roleList);
          setStationlist(stationList);
1248
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1249
        } else {
皮倩雯's avatar
皮倩雯 committed
1250
          console.log(res);
1251
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1252 1253 1254
        }
      })
      .catch(err => {
1255
        setLoading(false);
陈前坚's avatar
陈前坚 committed
1256 1257 1258 1259
        setTableLoading(false);
        message.error(err);
      });
  };
陈前坚's avatar
陈前坚 committed
1260 1261 1262
  // 获取全部未勾选的角色列表与站点列表
  const getEmptyRoleList = () => {
    setLoading(true);
1263
    GetUserRelationListNew({ userId: 0 })
陈前坚's avatar
陈前坚 committed
1264
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
1265
        console.log(222);
皮倩雯's avatar
皮倩雯 committed
1266
        if (res.code === 0) {
mayongxin's avatar
mayongxin committed
1267
          const { roleList, stationList } = res.data;
陈前坚's avatar
陈前坚 committed
1268 1269
          setRolelist(roleList);
          setStationlist(stationList);
1270
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1271
        } else {
皮倩雯's avatar
皮倩雯 committed
1272
          console.log(res.msg);
1273
          setLoading(false);
陈前坚's avatar
陈前坚 committed
1274 1275 1276 1277 1278 1279 1280 1281
        }
      })
      .catch(err => {
        setLoading(false);
        setTableLoading(false);
        message.error(err);
      });
  };
1282

皮倩雯's avatar
皮倩雯 committed
1283
  const getCheckList = e => {
1284
    console.log(e);
皮倩雯's avatar
皮倩雯 committed
1285 1286 1287 1288 1289 1290 1291 1292 1293
    let aa = [];
    let bb = [];
    loadAllUserRole(e).then(res => {
      if (res.code === 0) {
        if (res.data.roleList !== undefined) {
          // eslint-disable-next-line array-callback-return
          Object.keys(res.data.roleList).map((item, index) => {
            aa.push(item);
          });
1294
        }
皮倩雯's avatar
皮倩雯 committed
1295 1296 1297 1298 1299
        if (res.data.siteList !== undefined) {
          // eslint-disable-next-line array-callback-return
          Object.keys(res.data.siteList).map((item1, index1) => {
            bb.push(item1);
          });
1300
        }
皮倩雯's avatar
皮倩雯 committed
1301 1302 1303 1304
        console.log(aa);
        console.log(bb);
        setMultiRoleList(aa);
        setMultiStationList(bb);
1305
      }
皮倩雯's avatar
皮倩雯 committed
1306 1307
    });
  };
陈前坚's avatar
陈前坚 committed
1308
  // 提交-更改机构
皮倩雯's avatar
皮倩雯 committed
1309
  const submitChangeOrg = () => {
1310
    // addToOrg(currentUser.userId, currentUser.OUID, newOrgID)
mayongxin's avatar
mayongxin committed
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
    // .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);
    // });
1331
    console.log(currentUser);
mayongxin's avatar
mayongxin committed
1332
    JumpToAnotherOUNew({
1333 1334
      userId: currentUser.userId,
      oldOUID: currentUser.groupId,
皮倩雯's avatar
皮倩雯 committed
1335
      newOUID: newOrgID,
mayongxin's avatar
mayongxin committed
1336
    })
陈前坚's avatar
陈前坚 committed
1337
      .then(res => {
陈前坚's avatar
陈前坚 committed
1338 1339 1340 1341
        if (res.code === 0) {
          setChangeOrgVisible(false);
          // 跳转到新组织机构下的用户表
          onSelect([newOrgID]);
皮倩雯's avatar
皮倩雯 committed
1342
          // setExpandedKeys([`${newOrgID}`]);
陈前坚's avatar
陈前坚 committed
1343 1344
          notification.success({
            message: '提交成功',
1345
            duration: 2,
陈前坚's avatar
陈前坚 committed
1346 1347 1348 1349
          });
        } else {
          notification.error({
            message: '提交失败',
陈前坚's avatar
陈前坚 committed
1350
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1351 1352 1353 1354 1355 1356
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
皮倩雯's avatar
皮倩雯 committed
1357
  };
1358

皮倩雯's avatar
皮倩雯 committed
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
  // 提交-批量更改机构
  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
1370 1371
          notification.success({
            message: '提交成功',
1372
            duration: 2,
陈前坚's avatar
陈前坚 committed
1373 1374 1375 1376
          });
        } else {
          notification.error({
            message: '提交失败',
mayongxin's avatar
mayongxin committed
1377
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1378 1379 1380 1381 1382 1383
          });
        }
      })
      .catch(err => {
        message.error(err);
      });
皮倩雯's avatar
皮倩雯 committed
1384 1385 1386 1387 1388 1389 1390 1391 1392

  // 提交-冻结用户
  // const submitFreezeUser = () => {
  //   let state = '';
  //   if (currentUser.state === '0' || currentUser.state === null) {
  //     state = '1';
  //   } else {
  //     state = '0';
  //   }
1393
  //   // postSetUserState(currentUser.userId, state)
皮倩雯's avatar
皮倩雯 committed
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
  //   //   .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);
  //   //   });
1417
  //   UserStateOUNew({ ouid: currentUser.userId, state })
皮倩雯's avatar
皮倩雯 committed
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
  //     .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
1442
  // 提交-删除用户
陈前坚's avatar
陈前坚 committed
1443
  const submitDeleteUser = () => {
皮倩雯's avatar
皮倩雯 committed
1444
    DeleteUserNew({
1445
      userId: currentUser.userId,
皮倩雯's avatar
皮倩雯 committed
1446 1447 1448
    })
      .then(res => {
        if (res.code === 0) {
陈前坚's avatar
陈前坚 committed
1449 1450
          notification.success({
            message: '提交成功',
1451
            duration: 2,
陈前坚's avatar
陈前坚 committed
1452
          });
1453
          // eslint-disable-next-line no-unused-expressions
1454
          currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
陈前坚's avatar
陈前坚 committed
1455 1456 1457
        } else {
          notification.error({
            message: '提交失败',
mayongxin's avatar
mayongxin committed
1458
            description: res.msg,
陈前坚's avatar
陈前坚 committed
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        message.error(err);
      });
  };
  // 提交-批量删除用户
  const submitDeleteUsers = () => {
1469 1470 1471 1472 1473 1474 1475
    let data = [];
    keepDataList.length > 0 &&
      keepDataList.map(i => {
        let aa = userIDs.split(',').indexOf(i);
        console.log(aa);
        if (aa !== -1) {
          data.push(aa);
陈前坚's avatar
陈前坚 committed
1476 1477
        }
      });
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
    console.log(data);
    if (data.length > 0) {
      notification.error({
        message: '操作失败',
        description: '选中项包含不可删除的用户panda或admin',
      });
    } else {
      multiDeleteUsers(userIDs)
        .then(res => {
          if (res.code === 0) {
            setDeleteUserVisible(false);
            notification.success({
              message: '提交成功',
              duration: 2,
            });
            // 重新获取用户表,查找用户时currentSelectOrg为'-1',无需跳转
            // 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
1508
  };
1509
  // 重置默认第一个
1510
  const handleReset = () => {
1511
    GetOUTreeNew({ groupId: -1 })
1512 1513
      .then(newres => {
        if (newres.code === 0) {
1514
          let res = newres.data.list;
1515 1516
          setTreeLoading(false);
          setSearchWord('');
皮倩雯's avatar
皮倩雯 committed
1517
          setFilteredValue([]);
1518
          // 第一次加载,默认选择第一个组织
1519
          onSelect([res[0].id], false);
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
        } else {
          setTreeLoading(false);
          notification.error({
            message: '获取失败',
            // eslint-disable-next-line no-undef
            description: res.message,
          });
        }
      })
      .catch(err => {
        setTreeLoading(false);
        message.error(err);
      });
1533
  };
皮倩雯's avatar
皮倩雯 committed
1534
  const onChangeInput = filters => {
1535
    setFilteredValue(filters.OUName);
皮倩雯's avatar
皮倩雯 committed
1536
  };
1537

皮倩雯's avatar
皮倩雯 committed
1538
  // 更改机构范围
1539
  const submitExtent = (extent, areaName, flags) => {
皮倩雯's avatar
皮倩雯 committed
1540 1541 1542
    setTreeLoading(true);
    console.log(extent);
    console.log(areaName);
1543
    console.log(flags);
皮倩雯's avatar
皮倩雯 committed
1544
    console.log(currentSelectOrg1);
1545
    if (flags === 0) {
1546 1547 1548 1549
      setTreeLoading(false);
      notification.warn({
        message: '提交失败',
        description: '请框选范围',
皮倩雯's avatar
皮倩雯 committed
1550
      });
皮倩雯's avatar
皮倩雯 committed
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
    } else if (extent) {
      setOrgArea({
        OUID: currentSelectOrg1,
        areaName,
        extent,
      }).then(res => {
        if (res.msg === '') {
          setTreeLoading(false);
          setEditOrgExtentVisible(false);
          setSaveExtentFlag(saveExtentFlag + 1);
          message.success('机构范围设置成功!');
        } else {
          setTreeLoading(false);
          setEditOrgExtentVisible(false);
          message.warn(res.Message);
        }
      });
mayongxin's avatar
mayongxin committed
1568
    }
皮倩雯's avatar
皮倩雯 committed
1569
  };
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
  // 返回拖拽完毕后的信息
  const loop = (datas, key, parentID, callback) => {
    for (let i = 0; i < datas.length; i++) {
      if (datas[i].id === key) {
        return callback(datas[i], i, datas, parentID);
      }
      if (datas[i].children) {
        loop(datas[i].children, key, datas[i].id, callback);
      }
    }
  };
  // 树的拖拽
  const handleDrop = infos => {
    console.log(infos);
    const dropKey = infos.node.key;
    const dragKey = infos.dragNode.key;
    const dropPos = infos.node.pos.split('-');
1587
    const dropPosition = infos.dropPosition - Number(dropPos[dropPos.length - 1]);
陈前坚's avatar
陈前坚 committed
1588

1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
    const datas = JSON.parse(JSON.stringify(treeData));
    console.log(dropKey, 'dropKey');
    console.log(dragKey, 'dragKey');
    // 找到拖拽的元素
    let dragObj;
    let dropObj;
    let parId;
    let dragList;
    // 保存拖拽到的节点信息
    loop(datas, dropKey, -1, item => {
      dropObj = item;
    });
    // 保存节点信息并删除节点
    loop(datas, dragKey, -1, (item, index, arr) => {
      arr.splice(index, 1);
      dragObj = item;
    });
    // 将节点插入到正确的位置
    if (!infos.dropToGap) {
      console.log('33333333333');
      dropObj.children = dropObj.children || [];
      // 在哪里插入,示例添加到头部,可以是随意位置
      dropObj.children.unshift(dragObj);
      parId = dropObj.id;
      dragList = dropObj.children.map(val => val.id);
    } else {
      let ar;
      let i;
      loop(datas, dropKey, -1, (item, index, arr, parentID) => {
        ar = arr;
        i = index;
        parId = parentID;
      });
      if (dropPosition === -1) {
        ar.splice(i, 0, dragObj);
      } else {
        ar.splice(i + 1, 0, dragObj);
      }
      dragList = ar.map(ele => ele.id);
    }
    DragGroup({
      dragGroupType: 2,
      groupId: dragKey.toString(),
      groupList: dragList.map(item => item.toString()),
      parentId: parId.toString(),
    }).then(res => {
      if (res.code === 0) {
        updateTrees();
      } else {
        message.error(res.msg);
      }
    });
  };
皮倩雯's avatar
皮倩雯 committed
1642 1643 1644
  const addChange = e => {
    e.domEvent.stopPropagation();
  };
1645

陈前坚's avatar
陈前坚 committed
1646 1647 1648
  /** ***操作按钮**** */
  // 机构操作
  const orgButtonMenu = (
皮倩雯's avatar
皮倩雯 committed
1649
    <Menu onClick={e => addChange(e)}>
1650
      <Menu.Item key="1" onClick={addUser} icon={<UserAddOutlined style={{ marginTop: '5px' }} />}>
陈前坚's avatar
陈前坚 committed
1651 1652
        添加用户
      </Menu.Item>
1653 1654 1655 1656
    </Menu>
  );
  const orgButtonMenu1 = (
    <Menu onClick={e => addChange(e)}>
1657 1658 1659 1660 1661
      <Menu.Item
        key="2"
        onClick={addSubOrg}
        icon={<ClusterOutlined style={{ marginTop: '5px' }} />}
      >
陈前坚's avatar
陈前坚 committed
1662
        添加下级机构
陈前坚's avatar
陈前坚 committed
1663
      </Menu.Item>
1664
      <Menu.Item key="3" onClick={editOrg} icon={<EditOutlined style={{ marginTop: '5px' }} />}>
陈前坚's avatar
陈前坚 committed
1665
        编辑当前机构
陈前坚's avatar
陈前坚 committed
1666
      </Menu.Item>
1667
      <Menu.Item key="4" onClick={deleteOrg} icon={<DeleteOutlined style={{ marginTop: '5px' }} />}>
陈前坚's avatar
陈前坚 committed
1668
        删除当前机构
陈前坚's avatar
陈前坚 committed
1669
      </Menu.Item>
1670
      {/* <Menu.Item
1671 1672 1673 1674
        key="5"
        onClick={EditOrgScope}
        icon={<BorderlessTableOutlined style={{ marginTop: '5px' }} />}
      >
mayongxin's avatar
mayongxin committed
1675
        编辑机构范围
1676
      </Menu.Item> */}
陈前坚's avatar
陈前坚 committed
1677 1678 1679 1680 1681
    </Menu>
  );
  // 用户批量操作
  const userButtonMenu = (
    <Menu>
1682
      <Menu.Item key="1" onClick={relateRoles} icon={<IdcardOutlined />}>
陈前坚's avatar
陈前坚 committed
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
        批量关联角色
      </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
1694 1695 1696
  const kee = () => {
    setUserVisible(false);
  };
1697

1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
  const onSearch = value => {
    setSearchTreeValue(value);
    updateTrees(value);
  };

  // 监听分页
  const paginationChange = (page, pageSizes) => {
    setCurrentPage(page);
    setPageSize(pageSizes);
    onSelect([currentSelectOrg], '', pageSizes, page);
  };

陈前坚's avatar
陈前坚 committed
1710
  return (
1711 1712
    <PageContainer className={styles.userManageContainer}>
      <div className={styles.contentContainer}>
陈前坚's avatar
陈前坚 committed
1713
        {/* 左侧机构树 */}
陈前坚's avatar
陈前坚 committed
1714
        <Spin spinning={treeLoading} tip="loading...">
陈前坚's avatar
陈前坚 committed
1715
          <Card
1716
            style={{ overflowY: 'hidden', height: '100%' }}
陈前坚's avatar
陈前坚 committed
1717 1718 1719 1720 1721
            className={classnames({
              [styles.orgContainer]: true,
              [styles.orgContainerHide]: !treeVisible,
            })}
          >
1722
            <div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
1723 1724 1725
              <div
                style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
              >
1726
                <span
陈前坚's avatar
陈前坚 committed
1727
                  style={{
1728 1729
                    fontSize: '15px ',
                    fontWeight: 'bold',
1730
                    marginLeft: '7px',
陈前坚's avatar
陈前坚 committed
1731
                  }}
1732
                >
1733
                  机构列表({treeDataTotal}个)
1734 1735 1736 1737 1738 1739 1740
                </span>
                <Tooltip title="添加顶级机构">
                  <PlusSquareFilled
                    onClick={() => addOrg()}
                    style={{
                      color: '#1890FF',
                      fontSize: '25px',
1741
                      // marginLeft: '51%',
1742 1743 1744 1745
                    }}
                  />
                </Tooltip>
              </div>
1746
              <hr style={{ width: '97%', color: '#eeecec', marginLeft: '8px' }} />
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
              <Search
                style={{
                  marginBottom: 8,
                  width: '98%',
                  marginLeft: '7px',
                }}
                placeholder="快速搜索机构"
                onSearch={onSearch}
              />
              {searchTreeValue !== '' ? (
                <>
                  {treeData.length > 0 && (
程恺文's avatar
程恺文 committed
1759
                 //   <div style={{ height: '100%', overflowY: 'scroll' }}>
1760
                      <Tree
程恺文's avatar
程恺文 committed
1761
                      height={780}
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771
                        showIcon="true"
                        blockNode
                        defaultExpandAll
                        onSelect={onSelect}
                        treeData={treeData.map(t => mapTree(t))}
                        draggable
                        onDrop={handleDrop}
                        selectedKeys={[menuID]}
                        keepTree={keepTree}
                      />
程恺文's avatar
程恺文 committed
1772
            //        </div>
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
                  )}
                </>
              ) : (
                <>
                  {treeData.length > 0 && (
                    <div style={{ height: '100%', overflowY: 'scroll' }}>
                      <TreeComponents
                        showIcon="true"
                        blockNode
                        autoExpandParent
                        onSelect={onSelect}
                        treeData={treeData.map(t => mapTree(t))}
                        draggable
                        onDrop={handleDrop}
                        selectedKeys={[menuID]}
                        keepTree={keepTree}
                        expandedKeys={expendKey}
                      />
                    </div>
                  )}
                </>
陈前坚's avatar
陈前坚 committed
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
              )}
            </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
1808
          </Card>
陈前坚's avatar
陈前坚 committed
1809
        </Spin>
1810

陈前坚's avatar
陈前坚 committed
1811
        {/* 右侧用户表 */}
陈前坚's avatar
陈前坚 committed
1812
        <div
1813
          ref={userContainer}
陈前坚's avatar
陈前坚 committed
1814
          className={classnames({
1815
            [styles.userContainer]: true,
陈前坚's avatar
陈前坚 committed
1816 1817
          })}
        >
陈前坚's avatar
陈前坚 committed
1818
          <div style={{ height: '50px' }}>
1819
            <span
1820
              className={styles.title}
1821
              title={`${orgTitle}(已选${selectedRowKeys.length}/共${tableLength}人)`}
1822 1823
            >
              {orgTitle}(已选{selectedRowKeys.length}/共{tableLength}人)
1824
            </span>
陈前坚's avatar
陈前坚 committed
1825
            <span style={{ float: 'right', margin: '10px' }}>
陈前坚's avatar
陈前坚 committed
1826
              <Search
1827
                style={{ width: 260, marginRight: '15px' }}
1828
                placeholder="搜索登录名/用户姓名/手机号"
陈前坚's avatar
陈前坚 committed
1829 1830 1831 1832 1833
                onSearch={submitSearchUser}
                onChange={e => handleSearch(e)}
                enterButton
                value={searchWord}
              />
皮倩雯's avatar
皮倩雯 committed
1834

1835
              <Button style={{ marginRight: '15px' }} icon={<SyncOutlined />} onClick={handleReset}>
1836 1837
                重置
              </Button>
皮倩雯's avatar
皮倩雯 committed
1838

陈前坚's avatar
陈前坚 committed
1839 1840 1841 1842 1843
              <Dropdown overlay={userButtonMenu} disabled={multiOperate}>
                <Button type={multiOperateButtonType}>
                  用户批量操作 <DownOutlined />
                </Button>
              </Dropdown>
陈前坚's avatar
陈前坚 committed
1844 1845
            </span>
          </div>
1846 1847 1848 1849 1850 1851 1852 1853 1854
          {userContainer.current && (
            <Table
              // style={{ height: 'calc(100% -50px)' }}
              rowSelection={{
                type: 'checkbox',
                ...rowSelection,
              }}
              rowClassName={setRowClassName}
              size="small"
1855
              rowKey={record => record.userId}
1856 1857 1858 1859 1860 1861 1862 1863 1864
              locale={zhCN}
              bordered
              columns={columns}
              dataSource={tableData}
              loading={tableLoading}
              scroll={{
                x: 'max-content',
                y: `calc(${userContainer.current.clientHeight}px - 150px)`,
              }}
1865
              pagination={false}
1866 1867 1868 1869 1870
              onRow={record => ({
                onDoubleClick: () => {
                  editUser(record);
                },
              })}
1871 1872 1873
              onChange={onChangeInput}
            />
          )}
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
          <div
            style={{
              display: 'flex',
              justifyContent: 'flex-end',
              marginTop: '10px',
              marginRight: '5px',
            }}
          >
            <Pagination
              total={total}
              showTotal={(totals, range) => `第${range[0]}-${range[1]} 条/共 ${totals} 条`}
              defaultPageSize={pageSize}
              defaultCurrent={1}
              showSizeChanger
1888
              pageSizeOptions={[10, 20, 50, 100]}
1889 1890 1891 1892 1893 1894 1895
              current={currentPage}
              onChange={paginationChange}
              style={{ marginBottom: '10px' }}
              size="small"
              showQuickJumper
            />
          </div>
1896
        </div>
1897

陈前坚's avatar
陈前坚 committed
1898
        {/* Modal弹框 */}
1899
        {/* 添加用户 */}
陈前坚's avatar
陈前坚 committed
1900 1901 1902
        <AddUserModal
          visible={userVisible}
          orgID={orgID}
1903
          orgTitle1={orgTitle1}
皮倩雯's avatar
皮倩雯 committed
1904
          onCancel={kee}
1905
          updateTrees1={updateTrees1}
1906
          siteList={siteList}
1907
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
1908
        />
1909
        {/* 添加下级机构 */}
1910
        <AddSubOrgModal
1911
          visible={addOrgVisible}
1912
          orgTitle1={orgTitle1}
1913
          orgID={orgID}
1914
          onCancel={() => setAddOrgVisible(false)}
1915 1916
          onSelect={onSelect}
          updateTrees1={updateTrees1}
1917
        />
1918
        {/* 编辑机构 */}
1919
        <EditOrgModal
1920
          visible={editOrgVisible}
1921
          orgID={orgID}
1922
          orgTitle1={orgTitle1}
1923
          // description={description}
1924
          onCancel={() => setEditOrgVisible(false)}
1925 1926 1927 1928
          updateTrees={updateTrees}
        />
        {/* 删除机构 */}
        <DeleteOrgModal
皮倩雯's avatar
皮倩雯 committed
1929
          title="删除机构"
1930
          visible={deleteOrgVisible}
1931
          orgTitle={orgTitle1}
1932 1933
          orgID={orgID}
          updateTrees={updateTrees}
1934
          onCancel={() => setDeleteOrgVisible(false)}
1935
        />
陈前坚's avatar
陈前坚 committed
1936
        {/* 关联角色 */}
1937 1938 1939 1940
        <RelateRoleModal
          currentUser={currentUser}
          userIDs={userIDs}
          currentSelectOrg={currentSelectOrg}
陈前坚's avatar
陈前坚 committed
1941
          visible={roleVisible}
1942
          rolelist={rolelist}
1943 1944 1945
          multiRoleList={multiRoleList}
          multistationList={multistationList}
          mult={mult}
1946 1947 1948 1949
          loading={loading}
          stationlist={stationlist}
          multiRelateRoles={multiRelateRoles}
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
1950 1951 1952 1953
          onCancel={() => {
            setRoleVisible(false);
            setMultiRelateRoles(false);
          }}
1954
        />
陈前坚's avatar
陈前坚 committed
1955
        {/* 更改机构 */}
1956 1957 1958
        <Modal
          title="更改机构"
          visible={changeOrgVisible}
陈前坚's avatar
陈前坚 committed
1959
          onOk={multiChangeOrgs ? submitChangeOrgs : submitChangeOrg}
1960
          maskClosable={false}
陈前坚's avatar
陈前坚 committed
1961 1962 1963 1964
          onCancel={() => {
            setChangeOrgVisible(false);
            setMultiChangeOrgs(false);
          }}
1965 1966
          okText="确认"
          cancelText="取消"
1967
          width="500px"
1968
        >
1969 1970 1971 1972 1973 1974 1975 1976 1977
          {/* <span>请选择要更改的目标机构:</span> */}
          <Search
            style={{ width: 260, marginBottom: '10px' }}
            placeholder="请输入机构名称"
            onSearch={submitSearch}
            onChange={e => handleSearchOrg(e)}
            enterButton
            value={searchWordOrg}
          />
1978 1979
          <div style={{ height: '500px', overflowY: 'scroll' }}>
            {changeOrgVisible && treeDataCopy.length > 0 && (
1980
              <TreeComponents
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995
                showIcon="true"
                showLine={{ showLeafIcon: false }}
                // defaultExpandAll
                // 未切换时原先的节点,注意要转字符串
                selectedKeys={[`${currentSelectOldOrg}`]}
                onSelect={value => {
                  setNewOrgID(value[0]);
                  // 切换后选中的节点
                  setCurrentSelectOldOrg(value[0]);
                }}
                expandedKeys={expendKeyOrg}
                treeData={treeDataCopy.map(t => mapTree1(t))}
              />
            )}
          </div>
1996
        </Modal>
陈前坚's avatar
陈前坚 committed
1997
        {/* 修改密码 */}
1998
        <ChangePasswordModal
陈前坚's avatar
陈前坚 committed
1999
          visible={passwordVisible}
2000
          currentUser={currentUser}
2001 2002
          submitSearchUser={submitSearchUser}
          currentSelectOrg={currentSelectOrg}
2003
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
2004
          onCancel={() => setPasswordVisible(false)}
2005
        />
陈前坚's avatar
陈前坚 committed
2006
        {/* 编辑用户 */}
2007
        <EditUserModal
陈前坚's avatar
陈前坚 committed
2008
          visible={editUserVisible}
2009
          currentUser={currentUser}
2010 2011
          submitSearchUser={submitSearchUser}
          currentSelectOrg={currentSelectOrg}
2012
          onSelect={onSelect}
陈前坚's avatar
陈前坚 committed
2013
          onCancel={() => setEditUserVisible(false)}
2014
        />
陈前坚's avatar
陈前坚 committed
2015
        {/* 冻结用户 */}
皮倩雯's avatar
皮倩雯 committed
2016
        {/* <Modal
2017
          title="请确认"
陈前坚's avatar
陈前坚 committed
2018 2019 2020 2021 2022 2023
          visible={freezeUserVisible}
          onOk={submitFreezeUser}
          onCancel={() => setFreezeUserVisible(false)}
          okText="确认"
          cancelText="取消"
        >
张烨's avatar
张烨 committed
2024 2025
          <p>
            即将{+currentUser.state ? '激活' : '冻结'}用户{' '}
2026 2027 2028
            <span className={styles.redText}>
              {voca.stripTags(currentUser.loginName)}
            </span>
张烨's avatar
张烨 committed
2029 2030 2031
            ,是否确认
            {+currentUser.state ? '激活' : '冻结'}?
          </p>
皮倩雯's avatar
皮倩雯 committed
2032
        </Modal> */}
2033
        {/* 多选删除用户 */}
2034 2035 2036
        <Modal
          title="确认删除用户"
          visible={deleteUserVisible}
陈前坚's avatar
陈前坚 committed
2037
          onOk={multiDelete ? submitDeleteUsers : submitDeleteUser}
2038
          maskClosable={false}
陈前坚's avatar
陈前坚 committed
2039 2040 2041 2042
          onCancel={() => {
            setDeleteUserVisible(false);
            setMultiDelete(false);
          }}
2043 2044 2045
          okText="确认"
          cancelText="取消"
        >
2046
          <p>将删除多个用户, 是否确认删除?</p>
2047
        </Modal>
2048
        {/* <MapScopeEditModal
皮倩雯's avatar
皮倩雯 committed
2049
          title={id}
mayongxin's avatar
mayongxin committed
2050
          mapId={createGuid()}
mayongxin's avatar
mayongxin committed
2051
          visible={editOrgExtentVisible}
皮倩雯's avatar
皮倩雯 committed
2052
          stationId={currentSelectOrg1}
mayongxin's avatar
mayongxin committed
2053 2054 2055 2056
          onCancel={() => setEditOrgExtentVisible(false)}
          confirmModal={submitExtent}
          distinct={currentOrgDistinct}
          extent={currentOrgArea}
2057
        /> */}
2058
        {/* <AuthModal
皮倩雯's avatar
皮倩雯 committed
2059 2060 2061
          visible={authUserVisible}
          currentUser={currentUser}
          onCancel={() => setAuthUserVisible(false)}
2062
        /> */}
陈前坚's avatar
陈前坚 committed
2063 2064
      </div>
    </PageContainer>
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106
    // <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
2107 2108 2109 2110
  );
};

export default UserManage;