CommonJurisdictionEvent.js 21.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 74 75 76 77 78 79 80 81 82 83 84 85 86 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 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 377 378 379 380 381 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
/* eslint-disable array-callback-return,no-undef,prefer-destructuring */
import React, { Component } from 'react';
import { Modal, message } from 'antd-v4';
import commonConfig from '../../utils/config';
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import * as commonServices from './../../services/services'; /*   服务类   */

const { confirm } = Modal;

export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {};
      this.form = {};
      /*   表单对象   */
    }

    componentWillReceiveProps(nextProps) {
      const {
        formData, currentId, groupConfig, treeData,
      } = nextProps;
      let { bReceived } = nextProps;
      const sId = currentId !== undefined ? currentId : '';

      if (commonUtils.isEmptyObject(groupConfig) && bReceived === undefined) {
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        this.handleGetChangeData({ name: 'tree' }, 'SysjurisdictionTree');
        bReceived = true;
        const group = this.imitateTableColumnConfig('group', [this.imitateTableColumn('组权限', 'sName', 'sId')]);
        const user = this.imitateTableColumnConfig('user', [this.imitateTableColumn('用户账号', 'sUserName', 'sId')]);

        const userGroup = this.imitateTableColumnConfig('userGroup', [this.imitateTableColumn('组成员', 'sUserName', 'sUsersId')]);
        const groupUser = this.imitateTableColumnConfig('groupUser', [this.imitateTableColumn('所属分组', 'sGroupName', 'sGroupsId')]);

        const checkedNodes = this.imitateTableColumnConfig('checkedNodes', [this.imitateTableColumn('名称', 'showName', 'sId')]);

        const tree = this.imitateTableColumnConfig('tree', [this.imitateTableColumn('名称', 'showName', 'key')]);

        const search = this.imitateTableColumnConfig('search', [this.imitateTableColumn('名称', 'showName', 'sAllId')]);

        this.props.onSaveState({
          masterConfig,
          sId,
          bReceived,
          treeKeyName: 'key',
          showLine: false,
          // pageLoading: false,
          ...tree,
          ...group,
          ...user,
          ...userGroup,
          ...groupUser,
          ...checkedNodes,
          ...search,
        });
      }
      if (commonUtils.isNotEmptyArr(treeData) && bReceived) {
        this.handleGetChangeData({ name: 'group' }, 'GroupData');
        this.handleGetChangeData({ name: 'user' }, 'UserData');
        this.props.onSaveState({
          bReceived: false,
          pageLoading: false,
        });
      }
    }


    shouldComponentUpdate(nextProps, nextState) {
      let flag = true;
      /* 追加弹出框数值回填放行判断ppopupPane */
      if (nextProps.sTabId === nextProps.app.currentPane.key || ((nextProps.app.ppopupPane !== undefined
        && nextProps.app.ppopupPane.mainConfig !== undefined)
        ? nextProps.sTabId === nextProps.app.ppopupPane.mainConfig.key : false)) {
        if (nextState.disabled !== this.state.disabled) {
          return true;
        }
        flag = true;
      } else {
        flag = false;
      }
      return flag;
    }

    componentWillUpdate(nextProps) {
      const { masterData, sModelsType, elemachineData } = nextProps;
      if (sModelsType === 'element/teamInfo' && masterData !== undefined) {
        if (commonUtils.isNotEmptyObject(elemachineData)) {
          elemachineData.forEach((row, index) => {
            if (row.sMachineId === masterData.sMachineId) {
              elemachineData[index].bDefault = true;
            } else {
              elemachineData[index].bDefault = false;
            }
          });
        }
      }
    }


    /**   表单回带   */
    handleForm = (form) => {
      this.form = form;
    };
    /** 主表控件是否全部显示 */
    handleToggle = () => {
      const { expand } = this.props;
      this.props.onSaveState({ expand: !expand });
    };

    handleValidateSave = async (componentName) => {
      const {
        token, sModelsId, sJurisdictionClassifyId, sUserId, treeAllNodes, [`${componentName}KeyName`]: skeyName, treeCheckedKeys, treeAllCheckKeys,
        app,
      } = this.props;
      const value = {};
      if ((commonUtils.isEmptyArr(sJurisdictionClassifyId) && commonUtils.isEmptyArr(sUserId))) {
        message.warn(commonFunc.showMessage(app.commonConst, 'NotEmptyJurisdictionGroup'));/*  组员,所属或权限组不能为空!   */
        this.props.onSaveState({
          loading: false,
        });
        return;
      }
      if (commonUtils.isNotEmptyArr(sJurisdictionClassifyId) && commonUtils.isEmptyArr(sUserId)) {
        value.sJurisdictionClassifyId = sJurisdictionClassifyId[0];
      } else if (commonUtils.isNotEmptyArr(sUserId) && commonUtils.isEmptyArr(sJurisdictionClassifyId)) {
        value.sUserId = sUserId[0];
      } else {
        message.warn(commonFunc.showMessage(app.commonConst, 'NotEmptyGroup'));/* 组或者组员不能为空 */
        this.props.onSaveState({
          loading: false,
        });
        return;
      }
      /*
      if (commonUtils.isNotEmptyArr(treeCheckedKeys) && treeCheckedKeys.length === treeAllCheckKeys.length) {
        message.warn('请选择不需要的权限!');
        return;
      }
      */
      const newUncheckedKeys = [];
      const saveData = [];

      treeAllCheckKeys.forEach((key) => {
        const iIndex = treeCheckedKeys.indexOf(key);
        if (iIndex === -1) {
          newUncheckedKeys.push(key);
        }
      });
      newUncheckedKeys.forEach((key) => {
        const nodes = treeAllNodes.get(key);
        saveData.push({ sKey: nodes[`${skeyName}`], sAction: nodes.sName });
      });

      value.data = saveData;
      value.sTreeAllKet = treeAllCheckKeys;

      const dataUrl = `${commonConfig.server_host}/sysjurisdiction/addSysjurisdiction?sModelsId=${sModelsId}`;
      const dataReturn = (await commonServices.postValueService(token, value, dataUrl)).data;
      /*   成功的话返回数据   */
      if (dataReturn.code === 1) { /*   成功   */
        message.success(dataReturn.msg);
        this.props.onSaveState({ enabled: false, loading: false });
        return dataReturn;
      } else { /*   失败   */
        this.props.getServiceError(dataReturn);
        this.props.onSaveState({
          loading: false,
        });
        return false;
      }
    }

    /**   点击修改按钮操作   */
    handleEdit = () => {
      this.props.onSaveState({ enabled: true, loading: false });
    }
    handleCancel = (obj) => {
      const { groupUserData } = this.props;
      const onGetChangeData = this.handleGetChangeData;
      const onSaveStateOk = this.props.onSaveState;
      confirm({
        title: obj.title,
        onOk() {
          const sId = groupUserData.length > 0 ? groupUserData[0].sId : '';
          onSaveStateOk({ enabled: false });
          onGetChangeData({ name: 'authority', sId }, 'GroupAuthority');
        },
        onCancel() {
        },
      });
    }

    handleGetSisformulaData = (masterConfig) => {
      this.handleGetSlaveData('One', null, masterConfig);
    }

    handleGetSlaveData = (getType, sName, currConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      if (getType === 'One') {
        this.props.handleGetDataOne({
          name: 'master', configData: currConfig, condition: { sId, pageSize: '', pageNum: '' },
        });
      }
      if (getType === 'Set') {
        this.props.handleGetDataSet({
          name: sName, configData: currConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
    }
    /*  获取分组列表
    yw_权限分配
    获取分组列表
    获取人员列表
    qx_获取权限树
    qx_根据组sId获取已选择权限
    qx_根据人sId获取已选择权限
    qx_根据组sId获取组人员
    根据人员sId获取所属分组
    保存组已选权限
    * */
    handleGetChangeData = async (params, urlKey) => {
      const { app, sModelsId } = this.props;
      const { token } = app;
      const { name, sId, treeComponentName } = params; // name,
      let dataUrl = '';
      if (urlKey === 'SysjurisdictionTree') { // 树结构
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getSysjurisdictionTree?sModelsId=${sModelsId}`;
      } else if (urlKey === 'GroupData') { // 组
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getGroupData?sModelsId=${sModelsId}`;
      } else if (urlKey === 'UserData') { // 用户
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getUserData?sModelsId=${sModelsId}`;
      } else if (urlKey === 'UserGroupId') { // 组成员
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getsUserGroupId/${sId}?sModelsId=${sModelsId}`;
      } else if (urlKey === 'GroupUserId') { // 用户所属组
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getGroupUserId/${sId}?sModelsId=${sModelsId}`;
      } else if (urlKey === 'GroupAuthority') { // 组权限
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getHaveAuthorityGroupId/${sId}?sModelsId=${sModelsId}`;
      } else if (urlKey === 'UserAuthority') { // 用户所有权限查询 :用户权限,组权限
        dataUrl = `${commonConfig.server_host}sysjurisdiction/getHaveAuthorityUserId/${sId}?sModelsId=${sModelsId}`;
      }
      const dataReturn = (await commonServices.getService(token, dataUrl)).data;
      if (dataReturn.code === 1) {
        const returnData = dataReturn.dataset.rows;
        let addState = {};
        if (urlKey === 'SysjurisdictionTree') { // 树结构
          const allInitArr = [];
          const allInitMap = new Map();
          this.handleAllCheckKeys(allInitArr, allInitMap, returnData);
          this.props.onSaveState({ [`${name}Data`]: returnData, treeAllCheckKeys: allInitArr, treeAllNodes: allInitMap });
        } else if (urlKey === 'GroupData') { // 获取组后默认查询组权限,以及组成员
          this.props.onSaveState({ [`${name}Data`]: returnData });
          if (commonUtils.isNotEmptyArr(returnData)) {
            this.handleTableSelectRowChange('group', [returnData[0].sId]); // 查询第一组成员
          }
        } else if (urlKey === 'UserData') { // 获取成员后默认 成员自己的权限,以及成员所属组
          this.props.onSaveState({ [`${name}Data`]: returnData });
          if (commonUtils.isNotEmptyArr(returnData)) {
            this.handleGetChangeData({ name: 'groupUser', sId: returnData[0].sId }, 'GroupUserId'); // 查询第一个成员归属组
          }
        } else if (urlKey === 'GroupAuthority') {
          let groupAuth = '';
          let groupAuthData = [];
          if (commonUtils.isNotEmptyArr(returnData)) {
            if (commonUtils.isNotEmptyObject(returnData[0])) {
              groupAuth = commonUtils.isNotEmptyObject(returnData[0]) ? returnData[0].sKeys : [];
              groupAuthData = commonUtils.isNotEmptyObject(groupAuth) ? groupAuth.split(',') : [];
            }
          }
          addState = this.handleUnCheckedForFunction(treeComponentName, groupAuthData);
          this.props.onSaveState({
            [`${name}Data`]: returnData, userAuth: undefined, sJurisdictionClassifyId: sId, sUserId: undefined, ...addState,
          });
        } else if (urlKey === 'UserAuthority') {
          let gAuth = '';
          let groupAuthData = [];
          let uAuth = '';
          let userAuthData = [];
          if (commonUtils.isNotEmptyArr(returnData)) {
            if (commonUtils.isNotEmptyObject(returnData[0])) {
              const { groupAuth, userAuth } = returnData[0];
              if (commonUtils.isNotEmptyObject(groupAuth)) {
                gAuth = groupAuth.sKeys;
                groupAuthData = gAuth.split(',');
              }

              if (commonUtils.isNotEmptyObject(userAuth)) {
                uAuth = userAuth.sKeys;
                userAuthData = uAuth.split(',');
              }
            }
          }
          addState = this.handleGroupForFunction(treeComponentName, groupAuthData, userAuthData);
          this.props.onSaveState({
            [`${name}Data`]: returnData, userAuthData, sJurisdictionClassifyId: undefined, sUserId: sId, ...addState,
          });
        } else {
          this.props.onSaveState({ [`${name}Data`]: returnData });
        }
      } else {
        this.props.getServiceError(dataReturn);
      }
    }

    // 模拟 列
    imitateTableColumn = (title, dataIndex, key) => {
      return {
        title, dataIndex, key, width: '120',
      };
    }
    // 模拟config的 gdsconfigformslave 配置
    imitateTableConfig = (title, dataIndex) => {
      return {
        bCanInput: false,
        bFilter: false,
        bFind: false,
        bFirstEmpty: false,
        bIsOther: false,
        bNewRecord: false,
        bNotEmpty: false,
        bNotRepeat: false,
        bReadonly: true,
        bSum: false,
        bTree: false,
        bVisible: true,
        iColValue: 1,
        iFitWidth: 0,
        sBrandsId: '1111111111',
        sChinese: title,
        sChineseDropDown: '',
        sControlName: 'BtnLast',
        sId: commonUtils.createSid(),
        sParentId: '11811781131121915102156308120',
        sSubsidiaryId: '1111111111',
        showName: title,
        sName: dataIndex,
      };
    }
    // 根据模拟列,模拟列配置
    imitateTableColumnConfig = (name, columns) => {
      const gdsconfigformslave = [];
      columns.forEach((itmes) => {
        gdsconfigformslave.push(this.imitateTableConfig(itmes.title, itmes.dataIndex));
      });
      const config = { bGrd: true, gdsconfigformslave };
      return { [`${name}Column`]: columns, [`${name}Config`]: config };
    }
    /**   处理选择行发生改变   */
    handleTableSelectRowChange = (name, selectedRowKeys) => {
      const addState = {};
      if (name === 'group') {
        this.handleGetChangeData({ name: 'userGroup', sId: selectedRowKeys }, 'UserGroupId');
        this.handleGetChangeData({ name: 'master', sId: selectedRowKeys, treeComponentName: 'tree' }, 'GroupAuthority');
        addState.groupSelectedRowKeys = selectedRowKeys;
      } else if (name === 'user') {
        this.handleGetChangeData({ name: 'groupUser', sId: selectedRowKeys }, 'GroupUserId');
        this.handleGetChangeData({ name: 'master', sId: selectedRowKeys, treeComponentName: 'tree' }, 'UserAuthority');
        addState.userSelectedRowKeys = selectedRowKeys;
      } else if (name === 'userGroup') {
        this.handleGetChangeData({ name: 'master', sId: selectedRowKeys, treeComponentName: 'tree' }, 'UserAuthority');
        addState.userGroupSelectedRowKeys = selectedRowKeys;
      } else if (name === 'groupUser') {
        this.handleGetChangeData({ name: 'master', sId: selectedRowKeys, treeComponentName: 'tree' }, 'GroupAuthority');
        addState.groupUserSelectedRowKeys = selectedRowKeys;
      }
      this.props.onSaveState({ ...addState });
    }

    handleCheckBoxCheck = (componentName, checkedKeys) => {
      this.handleCheckedForFunction(componentName, checkedKeys);
    }

    /* 选择权限同时处理保存的数据以及将要展现的已选择权限  */
    handleCheckedForFunction = (componentName, checkedKeys) => {
      const {
        treeAllNodes,
      } = this.props;
      const data = [];
      const checkedData = [];
      if (commonUtils.isNotEmptyArr(treeAllNodes) && treeAllNodes.size > 0) {
        const newCheckedKeys = [];
        if (commonUtils.isNotEmptyArr(checkedKeys) && checkedKeys[0] !== null) {
          checkedKeys.forEach((key, i) => {
            if (checkedKeys.indexOf(key) === i) {
              newCheckedKeys.push(key);
            }
          });
          newCheckedKeys.forEach((key) => {
            const nodes = treeAllNodes.get(key);
            if (commonUtils.isNotEmptyObject(nodes)) {
              checkedData.push({ sId: nodes.sId, showName: nodes.showName });
            }
          });
        }
        this.props.onSaveState({
          [`${componentName}CheckedKeys`]: newCheckedKeys,
          treeSaveParams: data,
          checkedNodesData: checkedData,
        });
      }
    }

    handleUnCheckedForFunction = (componentName, unCheckedKeys) => {
      const { treeAllNodes, treeAllCheckKeys } = this.props;
      const addState = {};
      const checkedData = [];
      let checkKeys = [];
      checkKeys = checkKeys.concat(treeAllCheckKeys);

      if (commonUtils.isNotEmptyArr(unCheckedKeys)) {
        for (const checkId of unCheckedKeys) {
          treeAllCheckKeys.forEach((key) => {
            if (checkId.includes(key)) {
              checkKeys.forEach((item, index) => {
                if (item === key) {
                  checkKeys.splice(index, 1);
                }
              });
            }
          });
        }
      }
      checkKeys.forEach((key) => {
        const nodes = treeAllNodes.get(key);
        if (commonUtils.isNotEmptyObject(nodes)) {
          checkedData.push({ sId: nodes.sId, showName: nodes.showName });
        }
      });
      addState[`${componentName}CheckedKeys`] = checkKeys;
      addState.checkedNodesData = checkedData;
      addState.disabledCheckedKeys = [];
      return addState;
    }

    handleGroupForFunction = (treeComponentName, groupAuthData, userAuthData) => {
      const { treeAllNodes, treeAllCheckKeys } = this.props;
      const addState = {};
      const checkedData = [];
      let checkKeys = [];
      let userAuthDataNew = [];
      checkKeys = checkKeys.concat(treeAllCheckKeys);
      if (commonUtils.isEmptyArr(userAuthData)) { /* 只有组权限 没有用户权限时 */
        userAuthDataNew = JSON.parse(JSON.stringify(groupAuthData)); /* 深拷贝  */
        userAuthData = userAuthDataNew;
      }
      if (commonUtils.isNotEmptyArr(userAuthData)) {
        treeAllCheckKeys.forEach((key) => {
          for (const checkId of userAuthData) {
            if (checkId.includes(key)) {
              checkKeys.forEach((item, index) => {
                if (item === key) {
                  checkKeys.splice(index, 1);
                }
              });
            }
          }
        });
        checkKeys.forEach((key) => {
          const nodes = treeAllNodes.get(key);
          if (commonUtils.isNotEmptyObject(nodes)) {
            checkedData.push({ sId: nodes.sId, showName: nodes.showName });
          }
        });
      }

      let groupCheckKeys = [];
      if (commonUtils.isNotEmptyArr(groupAuthData)) {
        groupCheckKeys = groupCheckKeys.concat(treeAllCheckKeys);
        treeAllCheckKeys.forEach((key) => {
          for (const checkId of groupAuthData) {
            if (checkId === key) {
              groupCheckKeys.splice(groupCheckKeys.indexOf(key), 1);
            }
          }
        });
      } else {
        groupCheckKeys = treeAllCheckKeys; /* 组权限没有 */
      }
      addState[`${treeComponentName}CheckedKeys`] = checkKeys.concat(groupCheckKeys);
      addState.checkedNodesData = checkedData;
      addState.disabledCheckedKeys = groupCheckKeys;
      return addState;
    };

    handleAllCheckKeys = (arrObj, mapObj, returnData) => {
      const { treeKeyName } = this.props;
      returnData.forEach((item) => {
        if (item.children.length > 0) {
          arrObj.push(item[`${treeKeyName}`]);
          mapObj.set(item[`${treeKeyName}`], item);
          this.handleAllCheckKeys(arrObj, mapObj, item.children);
        } else {
          arrObj.push(item[`${treeKeyName}`]);
          mapObj.set(item[`${treeKeyName}`], item);
        }
      });
    };
    handleRefresh = () => {
      this.handleGetChangeData({ name: 'tree' }, 'SysjurisdictionTree');
      this.handleGetChangeData({ name: 'group' }, 'GroupData');
      this.handleGetChangeData({ name: 'user' }, 'UserData');
      this.props.onSaveState({
        treeAllCheckKeys: undefined,
        treeAllNodes: undefined,
      });
    }
    handleSearch = async (sSearchValue) => {
      const { sModelsId } = this.props;
      const url = `${commonConfig.server_host}gdsmodule/getGdsmoduleList?sModelsId=${sModelsId}&sName=${sSearchValue}`;
      const dataReturn = (await commonServices.getService(this.props.app.token, url)).data;
      if (dataReturn.code === 1) {
        /*   数据查询成功   */
        this.props.onSaveState({ searchData: dataReturn.dataset.rows });
      } else { /*   失败   */
        this.props.getServiceError(dataReturn);
      }
    }
    handleSetTreeOptionData = (name, optionName, value) => {
      this.props.onSaveState({ [`${name}${optionName}Keys`]: value });
    }
    render() {
      const { masterData } = this.props;
      const imgSrc = commonBusiness.handleAddIcon(masterData);
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          onReturnForm={this.handleForm}
          onSubmit={this.handleValidateSave.bind(this, 'tree')}
          onEdit={this.handleEdit}
          onTableSelectRowChange={this.handleTableSelectRowChange}
          onCancel={this.handleCancel}
          imgSrc={imgSrc}
          onToggle={this.handleToggle}
          onTreeCheck={this.handleCheckBoxCheck}
          onRefresh={this.handleRefresh}
          onSearch={this.handleSearch}
          onDoubleClick={this.handleDoubleClick}
          onSetTreeOptionKeys={this.handleSetTreeOptionData}
        />
      );
    }
  };
};