import React, { Component } from 'react'; import { connect } from 'dva'; import { Form, Input, Button, Menu, Icon, message, Modal, Select, Tooltip } from 'antd'; import './less/role.less'; import PTable from '../../../components/Pro/PTable'; import NewRole from './NewRole'; import UpdateRole from './UpdateRole'; import UpdateRoleGroup from './UpdateRoleGroup'; import RoleAllow from './RoleAllow'; import APPRoleAllow from './APPRoleAllow'; import NewRoleGroup from './NewRoleGroup'; import DataPermissionsSet from './DataPermissionsSet'; import { searchRoleAndRoleGroupList, //查询角色组与角色列表功能 batchesDelete, //批量删除角色中人员功能 systemComRoleInsertPerRole, //批量添加角色中人员功能 enterpriseRoleGet //GET获取角色权限 } from '../../../services/api'; import PartmentButton from '../../../components/PartmentButton'; import $perModal from '../../../utils/modal/perModal'; const { Search } = Input; const { SubMenu } = Menu; const { Option } = Select; const { confirm } = Modal; // const { Option } = Select; // const { MenuItemGroup } = Menu; @connect(state => ({ profile: state.profile })) @Form.create() /** * 部门管理组件 */ export default class Role extends Component { constructor(props, context) { super(props, context); this.state = { /** * 各个抽屉 */ roleOpen: false, updateRoleOpen: false, roleGroupOpen: false, updateroleGroupOpen: false, roleAllowOpen: false, dataPermissionsSetOpen: false, appRoleAllowOpen: false, /** * 抽屉需要 */ selectedRowIds: [], //需要删除的信息id值集合 selectedRowKeys: [], roleGroupList: [], /** * 删除模态框 */ ModalText: '请先移除当前部门下的人员,再删除当前角色!', visible: false, confirmLoading: false, /** * 批量离职删除模态框 */ BulkDeparturesModalText: 'XXX(手机号)离职后将取消关联的任务及审批流程。是否确定离职处理?', bulkDeparturesVisible: false, bulkDeparturesConfirmLoading: false, // company: '百川信(厦门)网络服务信息有限公司', placeholder: '请输入内容', // openKeys: ['a1'], forceUpdate: false, roleGroupSequence: '', //菜单组序列 roleGroupdefault: [], edit: { roleId: '', roleGroupId: '' }, pageParm: { pageSize: '10', pageNumber: '1', roleId: '' // comId: "", }, roleGroupData: [ { roleGroupName: '', roleGroupId: '', comRolesList: [ { roleName: '', roleId: '', personCount: '', sid: '' } ] } ], caption: '', personCount: '', mainManageAllow: true }; } //批量添加角色中人员功能 systemComRoleInsertPerRole = () => { systemComRoleInsertPerRole({ perIds: JSON.stringify(this.state.chargePerIdStr), roleId: this.state.roleId }) .then(res => { console.log(res, '批量添加角色中人员功能-res1'); this.refs.PTable.ajaxRequest(); }) .catch(err => { console.log(err, '批量添加角色中人员功能-err'); }); }; componentWillMount = () => { }; componentDidMount() { this.getSearchRoleAndRoleGroupList(); // this.getEnterpriseRoleGroupGet(); // this.getEnterpriseRoleGet(); } getEnterpriseRoleGet = roleId => { // enterpriseRoleGet({ roleId: this.state.roleId }).then(data => { enterpriseRoleGet({ roleId }).then(data => { if (data.data.roleName === '主管理员') { this.setState({ mainManageAllow: true }); } else { this.setState({ mainManageAllow: false }); } data.data.personCount ? this.setState({ personCount: data.data.personCount }) : null; }); }; onSelect = (selectedKeys, info) => { console.log('onSelect', info); }; getSearchRoleAndRoleGroupList = () => { searchRoleAndRoleGroupList({}).then(data => { if (data) { this.setState({ roleGroupData: data.data, roleGroupList: data.data }); const pageParm = { ...this.state.pageParm }; // 寻找与当前roleid匹配的数据 let currentRoleInfo = []; data.data.forEach(item => { if (item.comRolesList) { const temp = item.comRolesList.filter( subItem => subItem.roleId === this.state.roleId ); if (temp.length) { currentRoleInfo = temp; } } }); if (currentRoleInfo.length) { pageParm.roleId = this.state.roleId; this.getEnterpriseRoleGet(pageParm.roleId); ///获取该角色的权限 const roleGroupdefault1 = this.state.roleGroupdefault; roleGroupdefault1.push(currentRoleInfo[0].roleGroupId.toString()); console.log('菜单的第一个组key', roleGroupdefault1); this.setState({ pageParm, caption: currentRoleInfo[0].roleName, roleGroupdefault: roleGroupdefault1, personCount: currentRoleInfo[0].personCount }); } else { this.setState({ roleGroupData: data.data, personCount: this.state.roleGroupData[0].comRolesList[0] .personCount, caption: this.state.roleGroupData[0].comRolesList[0].roleName }); pageParm.roleId = this.state.roleGroupData[0].comRolesList[0].roleId; this.getEnterpriseRoleGet(pageParm.roleId); ///获取该角色的权限 const roleGroupdefault1 = this.state.roleGroupdefault; roleGroupdefault1.push( this.state.roleGroupData[0].roleGroupId.toString() ); this.setState({ roleGroupSequence: '', //菜单组序列 pageParm, caption: this.state.roleGroupData[0].comRolesList[0].roleName, roleGroupdefault: roleGroupdefault1, personCount: this.state.roleGroupData[0].comRolesList[0].personCount }); } } }); }; getEnterpriseRoleGroupGet = () => { // console.log("getComId:", comId); searchRoleAndRoleGroupList().then(data => { console.log('getRoleList', data.data); if (data) { this.setState({ roleGroupList: data.data }); } }); }; // 批量删除 handleDeleteList = () => { const that = this; const keyNumber = this.state.selectedRowIds.length; const keyId = this.state.selectedRowIds; console.log('id集合' + keyId); if (keyNumber <= 0) { message.warning('请选择移除的人员!'); } else { console.log(this.state.selectedRowIds); confirm({ title: '是否确认移除人员', okText: '确认', cancelText: '取消', onOk() { that.comJobDelete(keyId); that.getSearchRoleAndRoleGroupList(); }, onCancel() { console.log('Cancel'); } }); } }; // 订单删除 comJobDelete = perIds => { console.log('perIds', perIds); perIds = perIds.join(','); batchesDelete({ perIds, roleId: this.state.pageParm.roleId.toString() }).then( data => { console.log('角色人员删除', data); this.setState({ selectedRowIds: [], selectedRowKeys: [], forceUpdate: true }, () => { this.setState({ forceUpdate: false, }); }); message.info('角色人员删除成功!'); // this.resetting(); }, err => { console.log('角色人员删除失败', err); message.warning('角色人员删除失败!' + err); } ); }; // rootSubmenuKeys = ['a1', 'a2', 'a3']; /** * 删除模态框 */ showModal = () => { this.setState({ visible: true }); }; roleMenuClick = e => { const pageParm = { ...this.state.pageParm }; console.log('ClickedroleMenu', e); console.log('角色组Id-roleGroupId:', e.keyPath[1]); console.log('角色Id-roleId:', e.key); pageParm.roleId = e.key; this.setState({ roleId: e.key, pageParm, roleGroupSequence: e.keyPath[1] !== this.state.roleGroupData[0].roleGroupId ? e.keyPath[1] : '', caption: e.item.props.title, personCount: e.item.props.personCount, selectedRowIds: [], //当切换菜单时,清空列表中选择的行 selectedRowKeys: [] }); this.getEnterpriseRoleGet(e.key); }; handleOk = () => { this.setState({ ModalText: '请先移除当前部门下的人员,再删除当前部门!', confirmLoading: true }); setTimeout(() => { this.setState({ visible: false, confirmLoading: false }); }, 2000); }; handleCancel = () => { console.log('Clicked cancel button'); this.setState({ visible: false }); }; /** * 批量离职删除模态框 */ showBulkDeparturesModal = () => { this.setState({ bulkDeparturesVisible: true }); }; handleBulkDeparturesOk = () => { this.setState({ BulkDeparturesModalText: 'XXX(手机号)离职后将取消关联的任务及审批流程。是否确定离职处理?', confirmLoading: true }); setTimeout(() => { this.setState({ bulkDeparturesVisible: false, confirmLoading: false }); }, 2000); }; handleBulkDeparturesCancel = () => { console.log('Clicked cancel button'); this.setState({ bulkDeparturesVisible: false }); }; handleHeart = item => { console.log(item); }; // 下级角色组别 handleList = () => { const listName = this.state.caption; const ertContent = []; this.state.roleGroupData.forEach(val => { if (val.roleGroupName === listName) { if (val.comRolesList.length !== 0) { val.comRolesList.forEach(text => { console.log(text.roleName); return ertContent.push(
{ModalText}
{BulkDeparturesModalText}