SiteManage.jsx 29.4 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);
皮倩雯's avatar
皮倩雯 committed
231
        console.log(lodash.cloneDeep(list));
tianfen's avatar
tianfen committed
232
        setdataList(lodash.cloneDeep(list));
233
        setTotal(res.data.count);
tianfen's avatar
tianfen committed
234
      } else {
235
        setCheckLoading(false);
tianfen's avatar
tianfen committed
236 237
        handleShowModal('loading', false);
        setdataList(lodash.cloneDeep([]));
tianfen's avatar
tianfen committed
238
      }
tianfen's avatar
tianfen committed
239
    });
tianfen's avatar
tianfen committed
240
  };
241 242 243 244 245 246
  // 搜索状态时获取当前站点可编辑用户(已勾选和未勾选)分页展示
  const getSearchList = value => {
    let params = {
      PageIndex: 1,
      PageSize: 10,
    };
247
    setCheckLoading(true);
248 249
    if (value) params = { ...params, key: value };
    getGroupUserTree(params).then(res => {
250
      setCheckLoading(false);
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 276 277 278
      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([]));
      }
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
    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;
                }
              }
            });
310 311
          });
        }
312 313 314 315 316 317 318 319 320 321 322 323 324 325
        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);
326
    handleSearch(e.target.value);
327 328 329 330 331 332 333 334 335 336 337
  };

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

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

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

522
        if (res.code === 0) {
tianfen's avatar
tianfen committed
523
          setSelectList([]);
524
          setUpdateCheck(updateCheck + 1);
Maofei94's avatar
Maofei94 committed
525 526 527 528 529 530 531 532
          notification.success({
            message: '提示',
            duration: 3,
            description: '设置成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
533
            duration: 15,
534
            description: res.msg,
Maofei94's avatar
Maofei94 committed
535 536 537 538
          });
        }
      })
      .catch(err => {
tianfen's avatar
tianfen committed
539
        handleShowModal('btnLoading', false);
Maofei94's avatar
Maofei94 committed
540
      });
tianfen's avatar
tianfen committed
541
  };
tianfen's avatar
tianfen committed
542 543 544
  // 分页
  const handleChangePage = (pageNum, pageSize) => {
    setPage({ pageNum, pageSize });
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
    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
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 628 629 630
  // 返回拖拽完毕后的信息
  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);
      }
    });
  };
皮倩雯's avatar
皮倩雯 committed
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652

  const indeterminate = i => {
    let aa = [];
    i.users.map(i => {
      if (i.isChecked) {
        aa.push(i.userName);
      }
    });
    if (i.isChecked) {
      console.log(12);
      return false;
    }
    if (!i.isChecked && aa.length < i.users.length && aa.length != 0) {
      console.log(34);
      return true;
    }
    if (!i.isChecked && aa.length == 0) {
      console.log(56);
      return false;
    }
  };

653
  const Panels = React.memo(props => {
皮倩雯's avatar
皮倩雯 committed
654
    let { index, groupId, groupName, users, isChecked, isShow, color, item } = props;
655
    return (
656
      <div className={styles.sitePanel} key={groupId} id={`siteId${groupId}`}>
657 658 659 660 661 662 663 664 665
        {/* 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} />
666
          {searchStyle(groupName)}
667 668 669 670
          <Checkbox
            key="0"
            className={styles.siteListTitle}
            checked={isChecked}
皮倩雯's avatar
皮倩雯 committed
671
            indeterminate={indeterminate(item)}
672 673 674 675 676 677
            onClick={e => props.handleChangeAll(e, index)}
          >
            全选
          </Checkbox>
        </div>
        <div className={styles.sitePanelCon}>
678 679
          {users.length > 0 &&
            users.map((v, vIndex) => (
680 681 682 683
              <CheckBoxRow
                {...v}
                index={index}
                vIndex={vIndex}
684
                key={v.userId}
685 686 687 688 689 690 691 692
                handleChangeSignel={props.handleChangeSignel}
              />
            ))}
        </div>
      </div>
    );
  });

693
  return (
694 695
    <PageContainer className={styles.siteManageContainer}>
      <div className={styles.contentContainer}>
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
        <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',
                }}
712
              />
713 714
            </Tooltip>
            {treeData.length > 0 && (
715
              <div style={{ height: '100%', overflowY: 'scroll' }}>
716 717 718 719 720 721 722 723 724 725 726 727 728 729
                <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>
730
            )}
731 732 733 734 735 736 737 738 739 740 741 742 743 744
            <div className={styles.switcher}>
              {treeVisible && (
                <Tooltip title="隐藏站点列表">
                  <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                </Tooltip>
              )}
              {!treeVisible && (
                <Tooltip title="显示站点列表">
                  <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                </Tooltip>
              )}
            </div>
          </Card>
        </Spin>
745 746 747 748 749 750 751
        {/* 右侧用户表 */}
        <div
          className={classnames({
            [styles.userContainer]: true,
            [styles.userContainerHide]: !treeVisible,
          })}
        >
Maofei94's avatar
Maofei94 committed
752
          <AddModal
tianfen's avatar
tianfen committed
753
            visible={visibleParams.modalVisible}
tianfen's avatar
tianfen committed
754
            onCancel={() => handleShowModal('modalVisible', false)}
Maofei94's avatar
Maofei94 committed
755 756
            confirmModal={confirmModal}
          />
757 758 759 760 761 762
          <AddChildModal
            visible={visibleParams.addChildVisible}
            pid={currentStation}
            onCancel={() => handleShowModal('addChildVisible', false)}
            confirmModal={addChildModal}
          />
Maofei94's avatar
Maofei94 committed
763
          <DelModal
tianfen's avatar
tianfen committed
764
            visible={visibleParams.delVisible}
765
            stationId={currentStation}
tianfen's avatar
tianfen committed
766
            onCancel={() => handleShowModal('delVisible', false)}
Maofei94's avatar
Maofei94 committed
767 768 769
            confirmModal={delModal}
          />
          <EditModal
tianfen's avatar
tianfen committed
770
            visible={visibleParams.editVisible}
771 772
            stationObj={currentStationMsg}
            des={des}
tianfen's avatar
tianfen committed
773
            onCancel={() => handleShowModal('editVisible', false)}
Maofei94's avatar
Maofei94 committed
774 775
            confirmModal={editModal}
          />
776
          <div
Maofei94's avatar
Maofei94 committed
777
            className={classnames({
778 779
              [styles.boxR]: true,
              [styles.boxH]: treeVisible,
Maofei94's avatar
Maofei94 committed
780 781
            })}
          >
tianfen's avatar
tianfen committed
782 783
            <Card
              className={classnames({
784 785
                [styles.cardBoxTop]: true,
                [styles.boxH]: treeVisible,
tianfen's avatar
tianfen committed
786 787
              })}
            >
皮倩雯's avatar
皮倩雯 committed
788 789 790 791 792
              <Search
                style={{ width: 260 }}
                allowClear
                placeholder={placeholder}
                onSearch={handleSearch}
793 794
                // value={name}
                // onChange={e => handleChange(e)}
皮倩雯's avatar
皮倩雯 committed
795 796 797 798
                enterButton
              />

              <Button onClick={restButton}>重置</Button>
799
            </Card>
800
            <div style={{ background: '#fff', height: 'calc(100% - 64px)', paddingBottom: '10px' }}>
801 802 803 804 805 806
              <Spin spinning={checkLoading} tip="loading...">
                <Card
                  className={classnames({
                    [styles.boxH]: treeVisible,
                    [styles.cardBoxR]: true,
                  })}
807 808 809
                >
                  <div
                    style={{
810 811
                      display: 'flex',
                      flexDirection: 'column ',
812
                      height: '100%',
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 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
                    {/* <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',
                      }}
                    >
878 879 880 881
                      {dataList.map((item, index) => (
                        <Panels
                          {...item}
                          index={index}
882
                          key={item.groupId}
883 884 885
                          handleChangeCollpase={handleChangeCollpase}
                          handleChangeAll={handleChangeAll}
                          handleChangeSignel={handleChangeSignel}
皮倩雯's avatar
皮倩雯 committed
886
                          item={item}
887
                        />
tianfen's avatar
tianfen committed
888
                      ))}
889
                    </div>
tianfen's avatar
tianfen committed
890
                  </div>
891 892
                </Card>
              </Spin>
893
              {dataList.length > 0 && !visibleParams.loading ? (
894
                <div style={{ textAlign: 'right', marginTop: '25px' }}>
895 896 897 898 899 900 901 902 903
                  <Pagination
                    size="small"
                    total={total}
                    current={page.pageNum}
                    defaultPageSize="10"
                    onChange={handleChangePage}
                    pageSizeOptions={['10']}
                  />
                </div>
tianfen's avatar
tianfen committed
904
              ) : (
905
                ''
tianfen's avatar
tianfen committed
906 907 908
              )}
            </div>
          </div>
Maofei94's avatar
Maofei94 committed
909 910
        </div>
      </div>
911
    </PageContainer>
Maofei94's avatar
Maofei94 committed
912 913
  );
};
914

tianfen's avatar
tianfen committed
915 916 917 918 919 920 921 922 923 924 925 926
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>
  );
});
927
export default SiteManageV2;