SiteManage.jsx 28.8 KB
Newer Older
1 2 3 4 5
/* eslint-disable no-shadow */
/* eslint-disable array-callback-return */
/* eslint-disable consistent-return */
/* eslint-disable react/no-multi-comp */
/* eslint-disable eqeqeq */
6
import React, { useEffect, useState } from 'react';
Maofei94's avatar
Maofei94 committed
7
import {
8 9
  // Tree,
  message,
Maofei94's avatar
Maofei94 committed
10
  Input,
11
  notification,
Maofei94's avatar
Maofei94 committed
12
  Tooltip,
13
  Card,
Maofei94's avatar
Maofei94 committed
14 15
  Button,
  Spin,
16
  Empty,
17 18
  Pagination,
  Checkbox,
Maofei94's avatar
Maofei94 committed
19
} from 'antd';
20 21

import classnames from 'classnames';
tianfen's avatar
tianfen committed
22
import {
23 24 25
  PlusSquareOutlined,
  FormOutlined,
  DeleteOutlined,
tianfen's avatar
tianfen committed
26 27
  DoubleLeftOutlined,
  DoubleRightOutlined,
28 29 30 31
  PlusOutlined,
  ApartmentOutlined,
  CaretUpOutlined,
  CaretDownOutlined,
tianfen's avatar
tianfen committed
32
} from '@ant-design/icons';
33

34
import PageContainer from '@/components/BasePageContainer';
35 36 37 38 39 40 41
import Tree from '@/components/ExpendableTree';
import voca from 'voca';
import zhCN from 'antd/es/locale/zh_CN';
import qs from 'qs';
import lodash, { clone } from 'lodash';
import styles from './SiteManage.less';

tianfen's avatar
tianfen committed
42 43 44
import {
  chooseUserToStation,
  getStationUserList,
45 46 47
  getSiteTree,
  getStationUsers,
  DragGroup,
48
  getGroupUserTree,
邓超's avatar
邓超 committed
49
} from '@/services/siteManage/api';
Maofei94's avatar
Maofei94 committed
50 51 52
import AddModal from './AddModal';
import DelModal from './DelModal';
import EditModal from './EditModal';
53
import AddChildModal from './AddChildModal';
54
const { Search } = Input;
55
const placeholder = '请输入查询条件';
56 57 58 59 60 61 62
const SiteManageV2 = () => {
  const [showSearchStyle, setShowSearchStyle] = useState(false); // 是否显示模糊查询样式
  const [treeVisible, setTreeVisible] = useState(true); // 树是否可见
  const [treeData, setTreeData] = useState([]); // 用户站点树
  const [treeDataCopy, setTreeDataCopy] = useState([]); // 机构树数据备份,用于更改机构
  const [treeState, setTreeState] = useState(true); // 树第一次加载
  const [treeLoading, setTreeLoading] = useState(false);
63
  const [checkLoading, setCheckLoading] = useState(false);
tianfen's avatar
tianfen committed
64
  const [currentStation, setCurrentStation] = useState(''); // 当前选中站点
65 66 67
  const [currentStationMsg, setCurrentStationMsg] = useState({}); // 当前编辑节点信息
  const [dataList, setdataList] = useState([]); // 当前站点对应的分页用户列表
  const [selectedState, setSelectedState] = useState(false); // 已选列表展开状态true为展开false为收起
tianfen's avatar
tianfen committed
68 69 70 71 72 73 74 75 76
  const [visibleParams, setvisibleParams] = useState({
    modalVisible: false, // 新增弹窗
    delVisible: false, // 删除弹窗
    editVisible: false, // 修改弹窗
    spinLoading: false, // 加载弹窗
    btnLoading: false,
    loading: false,
    checkBoxLoading: false,
  });
tianfen's avatar
tianfen committed
77
  const [total, setTotal] = useState(0); // 分页总数
78
  const [page, setPage] = useState({ pageNum: 1, pageSize: 10 });
79
  const [selectList, setSelectList] = useState([]); // 已勾选列表数据
80 81
  const [updatePageUser, setUpdatePageUser] = useState(1); //
  const [updateCheck, setUpdateCheck] = useState(1);
tianfen's avatar
tianfen committed
82
  const [name, setName] = useState('');
83 84 85
  const [des, setDes] = useState('');
  const [data, setData] = useState('');
  const [ch, setCh] = useState('');
86
  const [keepTree, setKeepTree] = useState([]); // 保存所有一级id用于控制只展开一项一级菜单
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

  let a = [];

  // 渲染机构树
  const mapTree = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
    return {
      title: (
        <div className={styles.title}>
          <div className={styles.titleText}>{org.text}</div>
          <div className={styles.tip}>
            <Tooltip title="添加下级站点" className={styles.fs}>
              <PlusSquareOutlined
                style={{ fontSize: '16px', color: '#1890FF' }}
                onClick={e => addSite(e, org)}
              />
            </Tooltip>
            <Tooltip title="编辑当前站点" className={styles.fs}>
              <FormOutlined
                style={{ fontSize: '16px', color: '#1890FF' }}
                onClick={e => editorSite(e, org)}
              />
            </Tooltip>
            <Tooltip title="删除当前站点" className={styles.fs}>
              <DeleteOutlined
                style={{ fontSize: '16px', color: '#1890FF' }}
                onClick={e => delSite(e, org)}
              />
            </Tooltip>
          </div>
        </div>
      ),
      key: org.id,
      // icon: <UserOutlined style={{ display: 'inline' }} />,
      // 判断它是否存在子集,若果存在就进行再次进行遍历操作,知道不存在子集便对其他的元素进行操作
      children: haveChildren ? org.children.map(i => mapTree(i)) : [],
    };
  };
  // 添加下级站点
  const addSite = (e, recode) => {
    e.stopPropagation();
128
    e.nativeEvent.stopImmediatePropagation();
129 130 131 132 133 134
    setCurrentStation(recode.id);
    handleShowModal('addChildVisible', true);
  };
  // 删除当前站点
  const delSite = (e, recode) => {
    e.stopPropagation();
135
    e.nativeEvent.stopImmediatePropagation();
136 137 138 139 140 141
    setCurrentStation(recode.id);
    handleShowModal('delVisible', true);
  };
  // 编辑当前站点
  const editorSite = (e, recode) => {
    e.stopPropagation();
142
    e.nativeEvent.stopImmediatePropagation();
143 144 145 146 147 148 149 150 151 152 153 154
    // 保存编辑回显信息
    setCurrentStationMsg(recode);
    // setCurrentStation(recode.id);
    handleShowModal('editVisible', true);
  };
  // 重新渲染树
  const updateTrees = () => {
    setTreeLoading(true);
    getSiteTree({ selectNode: -1 }).then(res => {
      if (res.data.length > 0) {
        setTreeLoading(false);
        setTreeData(res.data);
155 156 157 158 159
        let aa = [];
        res.data.forEach(i => {
          aa.push(i.id);
        });
        setKeepTree(aa);
160 161 162 163 164
        setTreeDataCopy(res.data);
        // 第一次加载,默认选择第一个组织
        if (treeState) {
          onSelect([res.data[0].id], false); // 待会儿要改
          setTreeState(false);
张烨's avatar
张烨 committed
165
        }
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
      } else {
        setTreeLoading(false);
        notification.error({
          message: '提示',
          duration: 15,
          description: res.msg,
        });
      }
    });
  };

  // 获取用户机构树
  // useEffect(() => {
  //   updateTrees();
  // }, [flag]);

Maofei94's avatar
Maofei94 committed
182
  useEffect(() => {
183 184 185 186 187 188 189
    getValue();
    updateTrees();
  }, []);

  // 切换站点,点击分页按钮,提交
  useEffect(() => {
    if (!currentStation) return;
tianfen's avatar
tianfen committed
190
    getList();
191 192 193
    setShowSearchStyle(false);
  }, [updatePageUser]);
  // 切换站点,提交时触发已勾选列表更新
tianfen's avatar
tianfen committed
194
  useEffect(() => {
195 196 197 198 199
    if (!currentStation) return;
    // getAllcheckList();
    getAllCheckListNew();
  }, [currentStation, updateCheck]);

tianfen's avatar
tianfen committed
200
  const getList = () => {
tianfen's avatar
tianfen committed
201 202 203 204
    let params = {
      PageIndex: +page.pageNum,
      PageSize: +page.pageSize,
    };
205
    if (name) params = { ...params, key: name };
206
    setCheckLoading(true);
207
    getGroupUserTree(params).then(res => {
tianfen's avatar
tianfen committed
208
      if (res.code === 0 && res.data) {
209
        setCheckLoading(false);
210
        setShowSearchStyle(true);
211
        let list = res.data.data;
tianfen's avatar
tianfen committed
212
        // 还原选择的数据
tianfen's avatar
tianfen committed
213 214 215
        if (selectList.length > 0) {
          selectList.forEach(item => {
            list.forEach((value, index) => {
216 217 218 219
              if (item.groupId == value.groupId) {
                list[index].users.forEach((user, userIndex) => {
                  if (user.userId === item.userId) {
                    list[index].users[userIndex].isChecked = true;
tianfen's avatar
tianfen committed
220 221
                  }
                });
222 223
                let checkedLen = list[index].users.filter(v => v.isChecked).length;
                if (checkedLen === list[index].users.length) {
tianfen's avatar
tianfen committed
224 225 226 227 228 229
                  list[index].isChecked = true;
                }
              }
            });
          });
        }
tianfen's avatar
tianfen committed
230
        handleShowModal('loading', false);
tianfen's avatar
tianfen committed
231
        setdataList(lodash.cloneDeep(list));
232
        setTotal(res.data.count);
tianfen's avatar
tianfen committed
233
      } else {
234
        setCheckLoading(false);
tianfen's avatar
tianfen committed
235 236
        handleShowModal('loading', false);
        setdataList(lodash.cloneDeep([]));
tianfen's avatar
tianfen committed
237
      }
tianfen's avatar
tianfen committed
238
    });
tianfen's avatar
tianfen committed
239
  };
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  // 搜索状态时获取当前站点可编辑用户(已勾选和未勾选)分页展示
  const getSearchList = value => {
    let params = {
      PageIndex: 1,
      PageSize: 10,
    };
    if (value) params = { ...params, key: value };
    getGroupUserTree(params).then(res => {
      if (res.code === 0 && res.data) {
        setShowSearchStyle(true);
        let list = res.data.data;
        // 还原选择的数据
        if (selectList.length > 0) {
          selectList.forEach(item => {
            list.forEach((value, index) => {
              if (item.groupId == value.groupId) {
                list[index].users.forEach((user, userIndex) => {
                  if (user.userId === item.userId) {
                    list[index].users[userIndex].isChecked = true;
                  }
                });
                let checkedLen = list[index].users.filter(v => v.isChecked).length;
                if (checkedLen === list[index].users.length) {
                  list[index].isChecked = true;
                }
              }
            });
          });
        }
        handleShowModal('loading', false);
        setdataList(lodash.cloneDeep(list));
        setTotal(res.data.count);
      } else {
        handleShowModal('loading', false);
        setdataList(lodash.cloneDeep([]));
      }
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
    setPage({ pageNum: 1, pageSize: 10 });
  };

  // 重置
  const restButton = () => {
    let params = {
      PageIndex: 1,
      PageSize: 10,
    };
    params = { ...params };
    getGroupUserTree(params).then(res => {
      if (res.code === 0 && res.data) {
        setShowSearchStyle(true);
        let list = res.data.data;
        // 还原选择的数据
        if (selectList.length > 0) {
          selectList.forEach(item => {
            list.forEach((value, index) => {
              if (item.groupId == value.groupId) {
                list[index].users.forEach((user, userIndex) => {
                  if (user.userId === item.userId) {
                    list[index].users[userIndex].isChecked = true;
                  }
                });
                let checkedLen = list[index].users.filter(v => v.isChecked).length;
                if (checkedLen === list[index].users.length) {
                  list[index].isChecked = true;
                }
              }
            });
307 308
          });
        }
309 310 311 312 313 314 315 316 317 318 319 320 321 322
        handleShowModal('loading', false);
        setdataList(lodash.cloneDeep(list));
        setTotal(res.data.count);
      } else {
        handleShowModal('loading', false);
        setdataList(lodash.cloneDeep([]));
      }
    });
    setName('');
    setPage({ pageNum: 1, pageSize: 10 });
  };

  const handleChange = e => {
    setName(e.target.value);
323 324 325 326 327 328 329 330 331 332 333
  };

  // 获取当前站点所有已经勾选的用户新接口
  const getAllCheckListNew = () => {
    getStationUsers({
      stationId: currentStation,
    }).then(res => {
      let list = [];
      if (res.data.length > 0) {
        res.data.map((item, index) => {
          list.push({
334 335
            groupId: +item.OUID,
            groupName: item.OUName,
336
            userName: item.userName,
337
            userId: item.userID,
338 339 340 341 342 343 344 345 346 347
          });
        });
      }
      setSelectList(lodash.cloneDeep(list));
      setUpdatePageUser(updatePageUser + 1);
    });
  };
  // 选中某个站点
  const onSelect = (props, e) => {
    setCh(props[0]);
348
    console.log(props[0], 'props[0]');
349 350 351 352 353 354
    if (!props[0]) {
      setCurrentStation(currentStation);
    } else {
      setCurrentStation(props[0]);
    }
    setPage({ pageNum: 1, pageSize: 10 });
355 356 357 358 359 360 361
    if (data) {
      data.map((item, index) => {
        if (item.id == props[0]) {
          setDes(item.describe);
        }
      });
    }
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  };

  const getValue = () => {
    getSiteTree({ selectNode: -1 }).then(res => {
      getData1(res.data);
    });
  };
  const getData1 = e => {
    e.map((i, j) => {
      a.push(i);
      if (i.children.length > 0) {
        getData1(i.children);
      }
    });
    setData(a);
  };

tianfen's avatar
tianfen committed
379 380 381 382
  // 弹出模态框
  const handleShowModal = (key, value) => {
    setvisibleParams({ ...visibleParams, [key]: value });
  };
Maofei94's avatar
Maofei94 committed
383 384
  // 获取搜索框的值
  const handleSearch = value => {
385 386
    // setName(value);
    getSearchList(value);
387
  };
Maofei94's avatar
Maofei94 committed
388
  const confirmModal = e => {
tianfen's avatar
tianfen committed
389
    handleShowModal('modalVisible', false);
390 391
    updateTrees();
    // setFlag(flag + 1);
Maofei94's avatar
Maofei94 committed
392 393
  };
  const delModal = () => {
tianfen's avatar
tianfen committed
394
    handleShowModal('delVisible', false);
395 396
    updateTrees();
    // setFlag(flag + 1);
Maofei94's avatar
Maofei94 committed
397 398
  };
  const editModal = () => {
tianfen's avatar
tianfen committed
399
    handleShowModal('editVisible', false);
400 401
    updateTrees();
    // setFlag(flag + 1);
Maofei94's avatar
Maofei94 committed
402
  };
403 404 405 406
  const addChildModal = () => {
    handleShowModal('addChildVisible', false);
    updateTrees();
    // setFlag(flag + 1);
Maofei94's avatar
Maofei94 committed
407
  };
408

tianfen's avatar
tianfen committed
409
  const handleChangeCollpase = (groupId, isShow) => {
410
    let index = dataList.findIndex(item => item.groupId === groupId);
tianfen's avatar
tianfen committed
411 412
    if (dataList[index].children && dataList[index].children.length > 0) {
      setdataList(lodash.cloneDeep(dataList));
tianfen's avatar
tianfen committed
413 414
      return;
    }
tianfen's avatar
tianfen committed
415
    handleShowModal('loading', true);
416 417 418 419 420 421 422
    getStationUserList({ stationID: currentStation, groupId }).then(res => {
      if (res.code === 0 && res.data) {
        handleShowModal('loading', false);
        dataList[index].children = res.data;
        setdataList(lodash.cloneDeep(dataList));
      }
    });
tianfen's avatar
tianfen committed
423 424 425 426
  };
  // 每组全选全不选
  const handleChangeAll = (e, index) => {
    dataList[index].isChecked = e.target.checked;
427
    dataList[index].users.forEach(item => {
tianfen's avatar
tianfen committed
428
      item.isChecked = e.target.checked;
tianfen's avatar
tianfen committed
429
      let delIndex = selectList.findIndex(
430
        v => v.groupId == dataList[index].groupId && v.userId == item.userId,
tianfen's avatar
tianfen committed
431
      );
tianfen's avatar
tianfen committed
432
      if (e.target.checked) {
tianfen's avatar
tianfen committed
433 434
        if (delIndex === -1) {
          selectList.push({
435 436
            groupId: dataList[index].groupId,
            groupName: dataList[index].groupName,
tianfen's avatar
tianfen committed
437
            userName: item.userName,
438
            userId: item.userId,
tianfen's avatar
tianfen committed
439 440
          });
        }
tianfen's avatar
tianfen committed
441 442 443 444 445 446
      }
      if (!e.target.checked) {
        selectList.splice(delIndex, 1);
      }
    });
    setSelectList(lodash.cloneDeep(selectList));
tianfen's avatar
tianfen committed
447 448 449 450
    setdataList(lodash.cloneDeep(dataList));
  };
  // 单个选择checkbox
  const handleChangeSignel = (e, index, vIndex) => {
451
    dataList[index].users[vIndex].isChecked = e.target.checked;
tianfen's avatar
tianfen committed
452 453
    let checked = isAllChecked(index);
    let hasIndex = selectList.findIndex(
tianfen's avatar
tianfen committed
454
      item =>
455 456
        item.userId == dataList[index].users[vIndex].userId &&
        item.groupId == dataList[index].groupId,
tianfen's avatar
tianfen committed
457
    );
tianfen's avatar
tianfen committed
458
    dataList[index].isChecked = checked;
tianfen's avatar
tianfen committed
459
    if (e.target.checked && hasIndex === -1) {
tianfen's avatar
tianfen committed
460
      selectList.push({
461 462 463 464
        groupId: dataList[index].groupId,
        groupName: dataList[index].groupName,
        userName: dataList[index].users[vIndex].userName,
        userId: dataList[index].users[vIndex].userId,
tianfen's avatar
tianfen committed
465 466 467 468
      });
    } else {
      selectList.splice(hasIndex, 1);
    }
469
    setSelectList(lodash.cloneDeep(selectList));
tianfen's avatar
tianfen committed
470 471 472
    setdataList(lodash.cloneDeep(dataList));
  };
  const isAllChecked = index =>
473
    dataList[index].users.filter(item => item.isChecked).length === dataList[index].users.length;
tianfen's avatar
tianfen committed
474 475
  // 删除已选列表
  const handleDel = index => {
476 477
    let { groupId, userId } = selectList[index];
    let outerIndex = dataList.findIndex(item => item.groupId == groupId);
tianfen's avatar
tianfen committed
478
    if (outerIndex > -1) {
479 480
      let innerIndex = dataList[outerIndex].users.findIndex(item => item.userId == userId);
      dataList[outerIndex].users[innerIndex].isChecked = false;
tianfen's avatar
tianfen committed
481 482
      dataList[outerIndex].isChecked = isAllChecked(outerIndex);
    }
tianfen's avatar
tianfen committed
483 484
    selectList.splice(index, 1);
    setSelectList(lodash.cloneDeep(selectList));
tianfen's avatar
tianfen committed
485 486 487 488 489 490
    setdataList(lodash.cloneDeep(dataList));
  };
  // 提交
  const handleCommitBtn = () => {
    handleShowModal('btnLoading', true);
    let result = [];
tianfen's avatar
tianfen committed
491 492
    let obj = {};
    selectList.forEach(item => {
493 494
      if (obj[item.groupId]) {
        obj[item.groupId].push(item.userId);
tianfen's avatar
tianfen committed
495
      } else {
496
        obj[item.groupId] = [item.userId];
tianfen's avatar
tianfen committed
497 498
      }
    });
499 500 501 502 503
    // dataList.forEach(item => {
    //     if (obj[item.GroupId] && item.Users.length === obj[item.GroupId].length) {
    //         obj[item.GroupId].push(item.GroupId);
    //     }
    // });
tianfen's avatar
tianfen committed
504 505
    result = Object.values(obj);
    // 数据处理成后台需要的格式
tianfen's avatar
tianfen committed
506 507 508
    if (result.length === 0)
      return notification.warning({
        message: '提示',
tianfen's avatar
tianfen committed
509
        description: '请至少选择选择一个用户!',
tianfen's avatar
tianfen committed
510
      });
511 512 513 514
    chooseUserToStation({
      userList: String(result.flat()),
      stationID: currentStation,
    })
Maofei94's avatar
Maofei94 committed
515
      .then(res => {
tianfen's avatar
tianfen committed
516 517
        handleShowModal('btnLoading', false);

518
        if (res.code === 0) {
tianfen's avatar
tianfen committed
519
          setSelectList([]);
520
          setUpdateCheck(updateCheck + 1);
Maofei94's avatar
Maofei94 committed
521 522 523 524 525 526 527 528
          notification.success({
            message: '提示',
            duration: 3,
            description: '设置成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
529
            duration: 15,
530
            description: res.msg,
Maofei94's avatar
Maofei94 committed
531 532 533 534
          });
        }
      })
      .catch(err => {
tianfen's avatar
tianfen committed
535
        handleShowModal('btnLoading', false);
Maofei94's avatar
Maofei94 committed
536
      });
tianfen's avatar
tianfen committed
537
  };
tianfen's avatar
tianfen committed
538 539 540
  // 分页
  const handleChangePage = (pageNum, pageSize) => {
    setPage({ pageNum, pageSize });
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    setUpdatePageUser(updatePageUser + 1);
  };
  /** ***操作按钮**** */
  // 机构操作
  const addTopStation = () => {
    handleShowModal('modalVisible', true);
  };

  // 模糊查询匹配的样式
  const searchStyle = val => {
    let n;
    if (showSearchStyle) {
      n = val.replace(new RegExp(name, 'g'), `<span style='color:red'>${name}</span>`);
    } else {
      n = val;
    }
    return <div dangerouslySetInnerHTML={{ __html: n }} />;
tianfen's avatar
tianfen committed
558
  };
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
  // 返回拖拽完毕后的信息
  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 => {
    const dropKey = infos.node.key;
    const dragKey = infos.dragNode.key;
    const dropPos = infos.node.pos.split('-');
    const dropPosition = infos.dropPosition - Number(dropPos[dropPos.length - 1]);

    const datas = JSON.parse(JSON.stringify(treeData));
    // 找到拖拽的元素
    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) {
      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: 3,
      groupId: dragKey.toString(),
      groupList: dragList.map(item => item.toString()),
      parentId: parId.toString(),
    }).then(res => {
      if (res.code === 0) {
        updateTrees();
      } else {
        message.error(res.msg);
      }
    });
  };
  const Panels = React.memo(props => {
628
    let { index, groupId, groupName, users, isChecked, isShow, color } = props;
629
    return (
630
      <div className={styles.sitePanel} key={groupId} id={`siteId${groupId}`}>
631 632 633 634 635 636 637 638 639
        {/* onClick={() => props.handleChangeCollpase(GroupId, isShow)} */}
        <div className={styles.sitePanelHead}>
          {/* {isShow ? (
                <UpOutlined className={styles.siteIcon} />
              ) : (
                <DownOutlined className={styles.siteIcon} />
              )} */}
          {/* <UpOutlined className={styles.siteIcon} /> */}
          <ApartmentOutlined className={styles.siteIcon} />
640
          {searchStyle(groupName)}
641 642 643 644 645 646 647 648 649 650
          <Checkbox
            key="0"
            className={styles.siteListTitle}
            checked={isChecked}
            onClick={e => props.handleChangeAll(e, index)}
          >
            全选
          </Checkbox>
        </div>
        <div className={styles.sitePanelCon}>
651 652
          {users.length > 0 &&
            users.map((v, vIndex) => (
653 654 655 656
              <CheckBoxRow
                {...v}
                index={index}
                vIndex={vIndex}
657
                key={v.userId}
658 659 660 661 662 663 664 665
                handleChangeSignel={props.handleChangeSignel}
              />
            ))}
        </div>
      </div>
    );
  });

666
  return (
667 668
    <PageContainer className={styles.siteManageContainer}>
      <div className={styles.contentContainer}>
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
        <Spin spinning={treeLoading} tip="loading...">
          <Card
            className={classnames({
              [styles.orgContainer]: true,
              [styles.orgContainerHide]: !treeVisible,
            })}
          >
            <span style={{ margin: '0 190px  0 10px' }}>站点列表</span>
            <Tooltip title="添加顶级站点">
              <PlusOutlined
                onClick={() => addTopStation()}
                style={{
                  color: '#1890FF',
                  fontSize: '18px',
                  verticalAlign: '0.04em',
                }}
685
              />
686 687
            </Tooltip>
            {treeData.length > 0 && (
688
              <div style={{ height: '100%', overflowY: 'scroll' }}>
689 690 691 692 693 694 695 696 697 698 699 700 701 702
                <Tree
                  showIcon="true"
                  showLine={{ showLeafIcon: false }}
                  blockNode
                  autoExpandParent
                  selectedKeys={[currentStation]}
                  onSelect={onSelect}
                  treeData={treeData.map(t => mapTree(t))}
                  expandedKeys={treeData[0].id}
                  draggable
                  onDrop={handleDrop}
                  keepTree={keepTree}
                />
              </div>
703
            )}
704 705 706 707 708 709 710 711 712 713 714 715 716 717
            <div className={styles.switcher}>
              {treeVisible && (
                <Tooltip title="隐藏站点列表">
                  <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                </Tooltip>
              )}
              {!treeVisible && (
                <Tooltip title="显示站点列表">
                  <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                </Tooltip>
              )}
            </div>
          </Card>
        </Spin>
718 719 720 721 722 723 724
        {/* 右侧用户表 */}
        <div
          className={classnames({
            [styles.userContainer]: true,
            [styles.userContainerHide]: !treeVisible,
          })}
        >
Maofei94's avatar
Maofei94 committed
725
          <AddModal
tianfen's avatar
tianfen committed
726
            visible={visibleParams.modalVisible}
tianfen's avatar
tianfen committed
727
            onCancel={() => handleShowModal('modalVisible', false)}
Maofei94's avatar
Maofei94 committed
728 729
            confirmModal={confirmModal}
          />
730 731 732 733 734 735
          <AddChildModal
            visible={visibleParams.addChildVisible}
            pid={currentStation}
            onCancel={() => handleShowModal('addChildVisible', false)}
            confirmModal={addChildModal}
          />
Maofei94's avatar
Maofei94 committed
736
          <DelModal
tianfen's avatar
tianfen committed
737
            visible={visibleParams.delVisible}
738
            stationId={currentStation}
tianfen's avatar
tianfen committed
739
            onCancel={() => handleShowModal('delVisible', false)}
Maofei94's avatar
Maofei94 committed
740 741 742
            confirmModal={delModal}
          />
          <EditModal
tianfen's avatar
tianfen committed
743
            visible={visibleParams.editVisible}
744 745
            stationObj={currentStationMsg}
            des={des}
tianfen's avatar
tianfen committed
746
            onCancel={() => handleShowModal('editVisible', false)}
Maofei94's avatar
Maofei94 committed
747 748
            confirmModal={editModal}
          />
749
          <div
Maofei94's avatar
Maofei94 committed
750
            className={classnames({
751 752
              [styles.boxR]: true,
              [styles.boxH]: treeVisible,
Maofei94's avatar
Maofei94 committed
753 754
            })}
          >
tianfen's avatar
tianfen committed
755 756
            <Card
              className={classnames({
757 758
                [styles.cardBoxTop]: true,
                [styles.boxH]: treeVisible,
tianfen's avatar
tianfen committed
759 760
              })}
            >
皮倩雯's avatar
皮倩雯 committed
761 762 763 764 765 766 767 768 769 770 771
              <Search
                style={{ width: 260 }}
                allowClear
                placeholder={placeholder}
                onSearch={handleSearch}
                value={name}
                onChange={e => handleChange(e)}
                enterButton
              />

              <Button onClick={restButton}>重置</Button>
772
            </Card>
773
            <div style={{ background: '#fff', height: 'calc(100% - 64px)', paddingBottom: '10px' }}>
774 775 776 777 778 779
              <Spin spinning={checkLoading} tip="loading...">
                <Card
                  className={classnames({
                    [styles.boxH]: treeVisible,
                    [styles.cardBoxR]: true,
                  })}
780 781 782
                >
                  <div
                    style={{
783 784
                      display: 'flex',
                      flexDirection: 'column ',
785
                      height: '100%',
786 787
                    }}
                  >
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 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 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
                    {/* <Checkbox className={styles.siteAll}>全选/反选</Checkbox> */}
                    {dataList.length > 0 && !visibleParams.loading ? (
                      <>
                        <p className={styles.siteline}>已选择列表:</p>
                        <div
                          className={styles.siteSelectList}
                          style={{
                            height: selectedState ? '1200px' : '220px',
                            transition: 'height 0.5s',
                          }}
                        >
                          <ul className={styles.siteSelectUl}>
                            {selectList.map((item, index) => (
                              <li
                                key={`${item.userName}${item.groupId}${index}`}
                                onClick={() => handleDel(index)}
                              >
                                {`${item.userName}(${item.groupName})`}
                              </li>
                            ))}
                          </ul>
                        </div>
                        <div style={{ textAlign: 'center', margin: '10px 0' }}>
                          <Tooltip title="收起">
                            <CaretUpOutlined
                              style={{
                                fontSize: '20px',
                                color: '#178BF6',
                                display: selectedState ? 'block' : 'none',
                              }}
                              onClick={() => setSelectedState(false)}
                            />
                          </Tooltip>
                          <Tooltip title="展开">
                            <CaretDownOutlined
                              style={{
                                fontSize: '20px',
                                color: '#178BF6',
                                display: selectedState ? 'none' : 'block',
                              }}
                              onClick={() => setSelectedState(true)}
                            />
                          </Tooltip>
                        </div>
                        <div className={styles.siteBtn}>
                          <Button
                            type="primary"
                            className={styles.siteCommit}
                            onClick={handleCommitBtn}
                          >
                            提交
                          </Button>
                        </div>
                      </>
                    ) : (
                      <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
                    )}
                    <div
                      style={{
                        overflowY: 'scroll',
                        flexGrow: '1',
                      }}
                    >
851 852 853 854
                      {dataList.map((item, index) => (
                        <Panels
                          {...item}
                          index={index}
855
                          key={item.groupId}
856 857 858 859
                          handleChangeCollpase={handleChangeCollpase}
                          handleChangeAll={handleChangeAll}
                          handleChangeSignel={handleChangeSignel}
                        />
tianfen's avatar
tianfen committed
860
                      ))}
861
                    </div>
tianfen's avatar
tianfen committed
862
                  </div>
863 864
                </Card>
              </Spin>
865
              {dataList.length > 0 && !visibleParams.loading ? (
866
                <div style={{ textAlign: 'right', marginTop: '25px' }}>
867 868 869 870 871 872 873 874 875
                  <Pagination
                    size="small"
                    total={total}
                    current={page.pageNum}
                    defaultPageSize="10"
                    onChange={handleChangePage}
                    pageSizeOptions={['10']}
                  />
                </div>
tianfen's avatar
tianfen committed
876
              ) : (
877
                ''
tianfen's avatar
tianfen committed
878 879 880
              )}
            </div>
          </div>
Maofei94's avatar
Maofei94 committed
881 882
        </div>
      </div>
883
    </PageContainer>
Maofei94's avatar
Maofei94 committed
884 885
  );
};
886

tianfen's avatar
tianfen committed
887 888 889 890 891 892 893 894 895 896 897 898
const CheckBoxRow = React.memo(props => {
  let { vIndex, index, isChecked, userName } = props;
  return (
    <Checkbox
      className={styles.siteList}
      checked={isChecked}
      onClick={e => props.handleChangeSignel(e, index, vIndex)}
    >
      {userName}
    </Checkbox>
  );
});
899
export default SiteManageV2;