index.js 28.1 KB
Newer Older
1 2 3
/* eslint-disable no-use-before-define */
/* eslint-disable eqeqeq */
import React, { useState, useEffect, useRef } from 'react';
4 5 6
import { Modal, Checkbox, Tabs, Input, Button, Pagination, Empty, Tag, Divider, Radio } from 'antd';
import { appService } from '@/api';

7
import { cloneDeep } from 'lodash';
8 9 10 11 12 13 14 15 16 17 18 19 20
import styles from './index.less';
const CheckboxGroup = Checkbox.Group;
const { TabPane } = Tabs;
const RMSComponents = props => {
  const {
    callBackSubmit = () => {},
    pickItem,
    visible,
    newCheckedList,
    groupName,
    chooseGroupName,
    dataType,
    isRadio,
21
    allData,
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  } = props;
  const [checkedList, setCheckedList] = useState([]); // 选中复选框内容
  const [searchWord, setSearchWord] = useState(''); // 关键字
  const { Search } = Input;
  const [total, setTotal] = useState();
  const [pageSize, setPageSize] = useState(45);
  const [currentPage, setCurrentPage] = useState(1);
  const [checkDataRole, setCheckDataRole] = useState([]);
  const [checkDataPm, setCheckDataPm] = useState([]);
  const [checkDataSite, setCheckDataSite] = useState([]);
  const [saveCheckValue, setSaveCheckValue] = useState([]); // 保存选中值
  const [keepTabKey, setKeepTabKey] = useState(0); // 保存tabs的key
  const [keyValue, setKeyValue] = useState('0');
  const [emptyValue, setEmptyValue] = useState(0);
  const [selected, setSelected] = useState(new Map()); // 已勾选角色列表
  const [optionValue, setOptionValue] = useState([]);
  const [indeterminate, setIndeterminate] = useState(false);
  const [checkAll, setCheckAll] = useState(false);
  const [indeterminate1, setIndeterminate1] = useState(false);
  const [checkAll1, setCheckAll1] = useState(false);
  const [indeterminate2, setIndeterminate2] = useState(false);
  const [checkAll2, setCheckAll2] = useState(false);
  const keepFiled = useRef({});
  const [radioValue, setRadioValue] = useState();

  const radioChange = e => {
    setRadioValue(e.target.value);
    const data = optionValue['站点'].find(i => i.value === e.target.value);
    const cs = new Map();
    cs.set(data.value, {
      value: data.label,
      type: 2,
    });
    setSelected(cs);
  };

  const onSubmit = () => {
    const selectData = [];
    const ids = [];
    selected.forEach((val, key) => {
      selectData.push(val.value);
      ids.push(key);
    });
    callBackSubmit({
      str: selectData.join(','),
      pickItem,
      stt: selectData,
      ids,
    });
    setKeyValue('0');
    setSearchWord('');
  };
74
  const init = async () => {
75
    if (visible) {
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
      let mData = cloneDeep(allData);
      if (!mData) {
        const res = await appService.LoadDepartmentAndRole();
        mData = res.data?.data || [];
      }
      keepFiled.current = groupArr(mData, 'groupType');
      if (groupName == '角色') {
        setKeyValue('0');
        setKeepTabKey(0);
      } else if (groupName == '部门') {
        setKeyValue('1');
        setKeepTabKey(1);
      } else if (groupName == '站点') {
        setKeyValue('2');
        setKeepTabKey(2);
      }
92

93 94 95 96 97 98 99 100 101 102 103 104
      const checkArr = [];
      // 角色
      const listdata = [];
      const listId = [];
      newCheckedList.map(checkItem => {
        keepFiled.current['角色'] &&
          keepFiled.current['角色'].map(i => {
            const canSave = dataType === 'name' ? i.label == checkItem : i.value == checkItem;
            if (canSave) {
              listdata.push(i);
              listId.push(i.value.toString());
            }
105
          });
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
      });
      const cs = selected;
      listdata.map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 0,
        });
      });
      setSelected(cs);
      const dataId = Array.from(new Set(listId));
      setCheckDataRole(dataId); // 用于设置首次展示已选列表角色数据
      checkArr[0] = dataId;
      // 部门
      const pmdata = [];
      const pmId = [];
      newCheckedList.map(checkItem => {
        keepFiled.current['部门'] &&
          keepFiled.current['部门'].map(i => {
            const canSave = dataType === 'name' ? i.label == checkItem : i.value == checkItem;
            if (canSave) {
              pmdata.push(i);
              pmId.push(i.value.toString());
            }
129
          });
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
      });
      const cs1 = selected;
      pmdata.map(i => {
        cs1.set(i.value, {
          value: i.label,
          type: 1,
        });
      });
      setSelected(cs1);
      const datapmId = Array.from(new Set(pmId));
      setCheckDataPm(datapmId);
      checkArr[1] = datapmId;
      // 站点
      const sitedata = [];
      const siteId = [];
      newCheckedList.map(checkItem => {
        keepFiled.current['站点'] &&
          keepFiled.current['站点'].map(i => {
            const canSave = dataType === 'name' ? i.label == checkItem : i.value == checkItem;
            if (canSave) {
              sitedata.push(i);
              siteId.push(i.value.toString());
            }
153 154
          });
      });
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
      const cs2 = selected;
      sitedata.map(i => {
        cs2.set(i.value, {
          value: i.label,
          type: 2,
        });
      });
      setSelected(cs2);
      const datasiteId = Array.from(new Set(siteId));
      setCheckDataSite(datasiteId);
      checkArr[2] = datasiteId;
      if (isRadio) {
        setRadioValue(siteId[0]);
      }
      setSaveCheckValue(checkArr);
      setCheckedList(checkArr);
      getRoles(groupName, '', pageSize, 1, 0, checkArr);
172 173 174 175 176 177 178 179 180 181
    } else {
      setSelected(new Map());
      setPageSize(45);
      setCurrentPage(1);
      setIndeterminate(false);
      setCheckAll(false);
      setCheckedList([]);
      setRadioValue();
      setOptionValue([]);
    }
182 183 184
  };
  useEffect(() => {
    init();
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  }, [visible]);

  const submitSearchUser = () => {
    if (keepTabKey == 0) {
      sreachRoles('角色', searchWord, pageSize, 1);
    }
    if (keepTabKey == 1) {
      sreachRoles('部门', searchWord, pageSize, 1);
    }
    if (keepTabKey == 2) {
      sreachRoles('站点', searchWord, pageSize, 1);
    }
  };

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

  // 搜索时获取数据
205 206 207 208
  const sreachRoles = async (type, keywords, pageSizes, pageIndex) => {
    let mData = cloneDeep(allData);
    if (!mData) {
      const res = await appService.LoadDepartmentAndRole({
209 210
        type,
        keywords,
211 212 213 214 215 216 217 218 219
        pageSize: 999,
        pageIndex: 1,
      });
      mData = res.data?.data || [];
    }
    if (keywords && allData) {
      mData = mData.map(m => {
        if (m.root) {
          m.root = m.root.filter(a => a.Name.includes(keywords));
220
        }
221
        return m;
222
      });
223 224 225 226 227 228 229 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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    }

    setOptionValue(groupArr(mData, 'groupType'));
    const aa = groupArr(mData, 'groupType');
    const list = [];
    let data = '';
    if (type == '角色') {
      data = 0;
    } else if (type === '部门') {
      data = 1;
    } else if (type === '站点') {
      data = 2;
    }
    aa[type] &&
      aa[type].map(i => {
        if (checkedList[data].indexOf(i.value) != -1) {
          list.push(i.value);
        }
      });
    if (list.length === aa[type].length) {
      if (type === '角色') {
        setCheckAll(true);
        setIndeterminate(false);
      } else if (type === '部门') {
        setCheckAll1(true);
        setIndeterminate1(false);
      } else if (type === '站点') {
        setCheckAll2(true);
        setIndeterminate2(false);
      }
    } else if (list.length < aa[type].length && list.length !== 0) {
      if (type === '角色') {
        setCheckAll(false);
        setIndeterminate(true);
      } else if (type === '部门') {
        setCheckAll1(false);
        setIndeterminate1(true);
      } else if (type === '站点') {
        setCheckAll2(false);
        setIndeterminate2(true);
      }
    } else if (list.length === 0) {
      if (type === '角色') {
        setCheckAll(false);
        setIndeterminate(false);
      } else if (type === '部门') {
        setCheckAll1(false);
        setIndeterminate1(false);
      } else if (type === '站点') {
        setCheckAll2(false);
        setIndeterminate2(false);
      }
    }
    setCurrentPage(1);
    setTotal(mData.length);
    if (mData.length === 0) {
      setEmptyValue(1);
    } else {
      setEmptyValue(0);
    }
283 284
  };

285 286 287 288
  const getRoles = async (type, keywords, pageSizes, pageIndex, flag, check) => {
    let mData = cloneDeep(allData);
    if (!mData) {
      const res = await appService.LoadDepartmentAndRole({
289 290
        type,
        keywords,
291 292 293 294 295
        pageSize: 999,
        pageIndex: 1,
      });
      mData = res.data?.data || [];
    }
296

297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
    setTotal(mData.length);
    setOptionValue(groupArr(mData, 'groupType'));
    const aa = groupArr(mData, 'groupType');
    const list = [];
    let data = '';
    if (type === '角色') {
      data = 0;
    } else if (type === '部门') {
      data = 1;
    } else if (type === '站点') {
      data = 2;
    }
    // 首次进入调用
    if (flag != undefined) {
      const listId = [];
      newCheckedList.map(checkItem => {
        if (keepFiled.current[groupName]) {
          keepFiled.current[groupName].map(i => {
            const canSave = dataType === 'name' ? i.label == checkItem : i.value == checkItem;
            if (canSave) {
              listId.push(i.value.toString());
318
            }
319
          });
320 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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
      aa[type] &&
        aa[type].map(i => {
          if (listId.indexOf(i.value) != -1) {
            list.push(i.value);
          }
        });
    } else {
      aa[type] &&
        aa[type].map(i => {
          if (checkedList[data].indexOf(i.value) != -1) {
            list.push(i.value);
          }
        });
    }

    if (list.length === aa[type].length) {
      if (type == '角色') {
        setCheckAll(true);
        setIndeterminate(false);
      } else if (type == '部门') {
        setCheckAll1(true);
        setIndeterminate1(false);
      } else if (type == '站点') {
        setCheckAll2(true);
        setIndeterminate2(false);
      }
    } else if (list.length < aa[type].length && list.length !== 0) {
      if (type == '角色') {
        setCheckAll(false);
        setIndeterminate(true);
      } else if (type == '部门') {
        setCheckAll1(false);
        setIndeterminate1(true);
      } else if (type == '站点') {
        setCheckAll2(false);
        setIndeterminate2(true);
      }
    } else if (list.length === 0) {
      if (type == '角色') {
        setCheckAll(false);
        setIndeterminate(false);
      } else if (type == '部门') {
        setCheckAll1(false);
        setIndeterminate1(false);
      } else if (type == '站点') {
        setCheckAll2(false);
        setIndeterminate2(false);
      }
    }
    if (mData.length === 0) {
      setEmptyValue(1);
    } else {
      setEmptyValue(0);
    }
  };
377 378 379

  const groupArr = (initialArr, name) => {
    const list = {};
380 381
    if (!Array.isArray(initialArr)) return list;
    initialArr.map(i => {
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 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 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 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
      const ar = [];
      i.root.map(j => {
        const ss = {};
        ss.label = j.Name;
        ss.value = j.ID.toString();
        ar.push(ss);
      });
      list[i.groupType] = ar;
    });
    return list;
  };

  const handleParChange = key => {
    setKeyValue(key);
    // setSearchWord('');
    setCurrentPage(1);
    setKeepTabKey(key);
    if (key == 0) {
      getRoles('角色', searchWord, pageSize, 1);
    }
    if (key == 1) {
      getRoles('部门', searchWord, pageSize, 1);
    }
    if (key == 2) {
      getRoles('站点', searchWord, pageSize, 1);
    }
  };

  const onChangeListNew = list => {
    const checkedListArr = [...saveCheckValue];
    const data = checkDataRole;
    const DataValue = [];
    if (optionValue['角色']) {
      optionValue['角色'].map(i => {
        if (checkDataRole.indexOf(i.value) != -1) {
          DataValue.push(i.value);
        }
      });
    }
    // del
    if (DataValue.length > list.length) {
      DataValue.forEach(item => {
        if (list.indexOf(item) == -1) {
          data.splice(data.findIndex(ele => ele === item), 1);
          const hhh = selected;
          hhh.delete(item);
          setSelected(hhh);
        }
      });
    } else {
      // add
      list.forEach(item => {
        if (data.indexOf(item) == -1) {
          data.push(item);
        }
      });
      const arrList = [];
      keepFiled.current['角色'] &&
        keepFiled.current['角色'].map(k => {
          if (data.indexOf(k.value) != -1) {
            arrList.push(k);
          }
        });
      const cs = selected;
      arrList.map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 0,
        });
      });
      setSelected(cs);
    }
    checkedListArr[0] = data;
    const listdata = [];
    optionValue['角色'].map(i => {
      if (data.indexOf(i.value) != -1) {
        listdata.push(i.value);
      }
    });
    if (listdata.length === optionValue['角色'].length) {
      setCheckAll(true);
      setIndeterminate(false);
    } else if (listdata.length < optionValue['角色'].length && listdata.length !== 0) {
      setCheckAll(false);
      setIndeterminate(true);
    } else if (listdata.length === 0) {
      setCheckAll(false);
      setIndeterminate(false);
    }
    setCheckDataRole(data);
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
  };
  const onChangeListNew1 = list => {
    const checkedListArr = [...saveCheckValue];
    const data = checkDataPm;
    const DataValue = [];
    // 拿到当前页数据
    if (optionValue['部门']) {
      optionValue['部门'].map(i => {
        if (checkDataPm.indexOf(i.value) != -1) {
          DataValue.push(i.value);
        }
      });
    }
    // del
    if (DataValue.length > list.length) {
      DataValue.forEach(item => {
        if (list.indexOf(item) == -1) {
          data.splice(data.findIndex(ele => ele === item), 1);
          const hhh = selected;
          hhh.delete(item);
          setSelected(hhh);
        }
      });
    } else {
      // add
      list.forEach(item => {
        if (data.indexOf(item) == -1) {
          data.push(item);
        }
      });
      const arrList = [];
      keepFiled.current['部门'] &&
        keepFiled.current['部门'].map(k => {
          if (data.indexOf(k.value) != -1) {
            arrList.push(k);
          }
        });
      const cs = selected;
      arrList.map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 1,
        });
      });
      setSelected(cs);
    }
    checkedListArr[1] = data;
    const listdata = [];
    optionValue['部门'].map(i => {
      if (data.indexOf(i.value) != -1) {
        listdata.push(i.value);
      }
    });
    if (listdata.length === optionValue['部门'].length) {
      setCheckAll1(true);
      setIndeterminate1(false);
    } else if (listdata.length < optionValue['部门'].length && listdata.length !== 0) {
      setCheckAll1(false);
      setIndeterminate1(true);
    } else if (listdata.length === 0) {
      setCheckAll1(false);
      setIndeterminate1(false);
    }
    setCheckDataPm(data);
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
  };
  const onChangeListNew2 = list => {
    const checkedListArr = [...saveCheckValue];
    const data = checkDataSite;
    const DataValue = [];
    // 拿到当前页数据
    if (optionValue['站点']) {
      optionValue['站点'].map(i => {
        if (checkDataSite.indexOf(i.value) != -1) {
          DataValue.push(i.value);
        }
      });
    }
    // del
    if (DataValue.length > list.length) {
      DataValue.forEach(item => {
        if (list.indexOf(item) == -1) {
          data.splice(data.findIndex(ele => ele === item), 1);
          const hhh = selected;
          hhh.delete(item);
          setSelected(hhh);
        }
      });
    } else {
      // add
      list.forEach(item => {
        if (data.indexOf(item) == -1) {
          data.push(item);
        }
      });
      const arrList = [];
      keepFiled.current['站点'] &&
        keepFiled.current['站点'].map(k => {
          if (data.indexOf(k.value) != -1) {
            arrList.push(k);
          }
        });
      const cs = selected;
      arrList.map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 2,
        });
      });
      setSelected(cs);
    }
    checkedListArr[2] = data;
    const listdata = [];
    optionValue['站点'].map(i => {
      if (data.indexOf(i.value) != -1) {
        listdata.push(i.value);
      }
    });
    if (listdata.length === optionValue['站点'].length) {
      setCheckAll2(true);
      setIndeterminate2(false);
    } else if (listdata.length < optionValue['站点'].length && listdata.length !== 0) {
      setCheckAll2(false);
      setIndeterminate2(true);
    } else if (listdata.length === 0) {
      setCheckAll2(false);
      setIndeterminate2(false);
    }
    setCheckDataSite(data);
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
  };

  const changeColor = e => {
    if (e === 0) {
      return 'cyan';
    }
    if (e === 1) {
      return 'orange';
    }
    return 'purple';
  };

  // 删除已选中列表
  const delSelected = value => {
    setRadioValue('');
    const aa = selected.get(value).type;
    const list = [];
    const checkedListArr = saveCheckValue;
    checkedListArr[aa].map(i => {
      if (i != value) {
        list.push(i);
      }
    });
    checkedListArr[aa] = list;
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
    let name = '';
    if (aa === 0) {
      setCheckDataRole(list);
      name = '角色';
    } else if (aa === 1) {
      setCheckDataPm(list);
      name = '部门';
    } else if (aa === 2) {
      setCheckDataSite(list);
      name = '站点';
    }
    const hhh = selected;
    hhh.delete(value);
    setSelected(hhh);
    const keepValue = [];
    optionValue[name].map(i => {
      if (list.indexOf(i.value) != -1) {
        keepValue.push(i);
      }
    });
    if (keepValue.length === optionValue[name].length) {
      if (aa == 0) {
        setCheckAll(true);
        setIndeterminate(false);
      } else if (aa == 1) {
        setCheckAll1(true);
        setIndeterminate1(false);
      } else if (aa == 2) {
        setCheckAll2(true);
        setIndeterminate2(false);
      }
    } else if (keepValue.length < optionValue[name].length && keepValue.length != 0) {
      if (aa == 0) {
        setCheckAll(false);
        setIndeterminate(true);
      } else if (aa == 1) {
        setCheckAll1(false);
        setIndeterminate1(true);
      } else if (aa == 2) {
        setCheckAll2(false);
        setIndeterminate2(true);
      }
    } else if (keepValue.length === 0) {
      if (aa == 0) {
        setCheckAll(false);
        setIndeterminate(false);
      } else if (aa == 1) {
        setCheckAll1(false);
        setIndeterminate1(false);
      } else if (aa == 2) {
        setCheckAll2(false);
        setIndeterminate2(false);
      }
    }
  };

  const onCheckAllChange = e => {
    setIndeterminate(false);
    setCheckAll(e.target.checked);
    const checkedListArr = [...saveCheckValue];
    const data = [];
    optionValue['角色'] &&
      optionValue['角色'].map(i => {
        data.push(i.value);
      });
    let list = [];
    if (e.target.checked) {
      // 复选框
      list = Array.from(new Set([...checkedList[0], ...data]));
      checkedListArr[0] = list;
      // 已选列表
      const cs = selected;
      optionValue['角色'].map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 0,
        });
      });
      setSelected(cs);
    } else {
      checkedListArr[0].map(i => {
        if (data.indexOf(i) == -1) {
          list.push(i);
        }
      });
      checkedListArr[0] = list;
      // 已选列表
      const hhh = selected;
      data.map(i => {
        hhh.delete(i);
      });
      setSelected(hhh);
    }
    setCheckDataRole(list);
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
  };

  const onCheckAllChange1 = e => {
    setIndeterminate1(false);
    setCheckAll1(e.target.checked);
    const checkedListArr = [...saveCheckValue];
    const data = [];
    optionValue['部门'] &&
      optionValue['部门'].map(i => {
        data.push(i.value);
      });
    let list = [];
    if (e.target.checked) {
      // 复选框
      list = Array.from(new Set([...checkedList[1], ...data]));
      checkedListArr[1] = list;
      // 已选列表
      const cs = selected;
      optionValue['部门'].map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 1,
        });
      });
      setSelected(cs);
    } else {
      checkedListArr[1].map(i => {
        if (data.indexOf(i) == -1) {
          list.push(i);
        }
      });
      checkedListArr[1] = list;
      // 已选列表
      const hhh = selected;
      data.map(i => {
        hhh.delete(i);
      });
      setSelected(hhh);
    }
    setCheckDataPm(list);
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
  };

  const onCheckAllChange2 = e => {
    setIndeterminate2(false);
    setCheckAll2(e.target.checked);
    const checkedListArr = [...saveCheckValue];
    const data = [];
    optionValue['站点'] &&
      optionValue['站点'].map(i => {
        data.push(i.value);
      });
    let list = [];
    if (e.target.checked) {
      // 复选框
      list = Array.from(new Set([...checkedList[2], ...data]));
      checkedListArr[2] = list;
      // 已选列表
      const cs = selected;
      optionValue['站点'].map(i => {
        cs.set(i.value, {
          value: i.label,
          type: 2,
        });
      });
      setSelected(cs);
    } else {
      checkedListArr[2].map(i => {
        if (data.indexOf(i) == -1) {
          list.push(i);
        }
      });
      checkedListArr[2] = list;
      // 已选列表
      const hhh = selected;
      data.map(i => {
        hhh.delete(i);
      });
      setSelected(hhh);
    }
    setCheckDataSite(list);
    setSaveCheckValue(checkedListArr);
    setCheckedList(checkedListArr);
  };

  return (
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
    <Modal
      title="权限选择"
      bodyStyle={{ width: '100%', height: '590px', overflowY: 'scorll' }}
      width="1000px"
      style={{ top: '-20px' }}
      destroyOnClose
      centered
      cancelText="取消"
      okText="确认"
      {...props}
      onOk={() => onSubmit()}
      forceRender
      // getContainer={false}
      afterClose={() => {
        setKeyValue('0');
        setSearchWord('');
      }}
      wrapClassName="roleModalContainer"
    >
      <div className={styles.pageContent}>
        {/* 可选列表 */}
        <div className={styles.optionalList}>
          <div className={styles.header} />
          <Search
            className={styles.searchInput}
            allowClear
            placeholder="搜索"
            onSearch={submitSearchUser}
            onChange={e => handleSearch(e)}
            value={searchWord}
          />
          <div className={styles.tabContent}>
            {visible && (
              <Tabs type="card" activeKey={keyValue} onChange={handleParChange}>
849
                {chooseGroupName.indexOf('角色') !== -1 ? (
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
                  <TabPane tab="角色" key="0">
                    <div className={styles.checkContent}>
                      {emptyValue == 0 ? (
                        <div className={styles.check}>
                          <Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
                            全选
                          </Checkbox>
                          <Divider />
                          <CheckboxGroup
                            options={optionValue['角色']}
                            value={checkedList[0]}
                            onChange={onChangeListNew}
                          />
                        </div>
                      ) : (
                        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无数据" />
                      )}
                    </div>
                  </TabPane>
869 870 871 872
                ) : (
                  <></>
                )}
                {chooseGroupName.indexOf('部门') !== -1 ? (
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
                  <TabPane tab="部门" key="1">
                    <div className={styles.checkContent}>
                      {emptyValue == 0 ? (
                        <div className={styles.check}>
                          <Checkbox indeterminate={indeterminate1} onChange={onCheckAllChange1} checked={checkAll1}>
                            全选
                          </Checkbox>
                          <Divider />
                          <CheckboxGroup
                            options={optionValue['部门']}
                            value={checkedList[1]}
                            onChange={onChangeListNew1}
                          />
                        </div>
                      ) : (
                        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无数据" />
                      )}
                    </div>
                  </TabPane>
892 893 894 895
                ) : (
                  <></>
                )}
                {chooseGroupName.indexOf('站点') !== -1 ? (
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
                  <TabPane tab="站点" key="2">
                    <div className={styles.checkContent}>
                      {emptyValue == 0 ? (
                        <div className={styles.check}>
                          {isRadio ? (
                            <Radio.Group onChange={radioChange} value={radioValue}>
                              {optionValue['站点']?.map(i => <Radio value={i.value}>{i.label}</Radio>)}
                            </Radio.Group>
                          ) : (
                            <>
                              <Checkbox indeterminate={indeterminate2} onChange={onCheckAllChange2} checked={checkAll2}>
                                全选
                              </Checkbox>
                              <Divider />
                              <CheckboxGroup
                                options={optionValue['站点']}
                                value={checkedList[2]}
                                onChange={onChangeListNew2}
                              />
                            </>
                          )}
                        </div>
                      ) : (
                        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无数据" />
                      )}
                    </div>
                  </TabPane>
923 924 925
                ) : (
                  <></>
                )}
926 927 928 929 930 931 932 933 934 935 936 937 938
              </Tabs>
            )}
          </div>
        </div>
        {/* 已选列表 */}
        <div className={styles.selectedList}>
          <div className={styles.header}>
            <div className={styles.title}>已选列表</div>
            <div className={styles.tagHead}>
              {chooseGroupName.indexOf('角色') !== -1 ? (
                <div className={styles.tagContent}>
                  <div className={styles.tagRol} />
                  <div>角色</div>
939 940
                </div>
              ) : (
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
                <></>
              )}
              {chooseGroupName.indexOf('部门') !== -1 ? (
                <div className={styles.tagContent}>
                  <div className={styles.tagOrg} />
                  <div>部门</div>
                </div>
              ) : (
                <></>
              )}
              {chooseGroupName.indexOf('站点') !== -1 ? (
                <div className={styles.tagContent}>
                  <div className={styles.tagSite} />
                  <div>站点</div>
                </div>
              ) : (
                <></>
958 959 960
              )}
            </div>
          </div>
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
          <div className={styles.selectBox}>
            {[...selected].length > 0 ? (
              <div className={styles.selectContent}>
                {[...selected].map(item => (
                  <div className={styles.selectValue} key={item[0]}>
                    <Tag closable color={changeColor(item[1].type)} onClose={() => delSelected(item[0])}>
                      {item[1].value}
                    </Tag>
                  </div>
                ))}
              </div>
            ) : (
              <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={`请选择${chooseGroupName.toString()}`} />
            )}
          </div>
976
        </div>
977 978
      </div>
    </Modal>
979 980 981 982
  );
};

export default RMSComponents;