import React, { useState, useRef, useEffect } from "react"; import { connect } from "react-redux"; import { Modal, Form } from "@douyinfe/semi-ui"; import { IconAlertCircle } from '@douyinfe/semi-icons'; function pushModal (props) { const { close, cancel, visible, dispatch, pepList, actions, adminEdit,//是否是编辑 editObj, } = props; const { install } = actions; const form = useRef();//表单 const [disablePeople, setDisablePeople] = useState(true); //页码信息 const [peopleList, setPeopleList] = useState([]); //人员List const [departmentId, setDepartmentId] = useState(); //部门id const [peopleId, setPeopleId] = useState(); //人员id //初始化 useEffect(() => { if (editObj.id) { let departmentList = [] for (let i = 0; i < pepList.length; i++) { if (pepList[i].id == editObj.departments[0].id) { departmentList = pepList[i].users } } setPeopleList(departmentList) setDepartmentId(editObj.departments[0].id) setPeopleId(editObj.pepUserId) setDisablePeople(false) } }, []); function handleOk () { //点击弹框确定 右边按钮 form.current .validate() .then((values) => { if (adminEdit) { dispatch(install.deteleOrganizationAdmin({id:editObj.id,msg:''})).then( dispatch(install.postOrganizationUser({ role: ['admin'], pepUserId: values.pepUserId, msg: '修改管理员' })).then((res) => {//获取项企(PEP)全部部门及其下用户 if (res.success) { close(); } }) ) } else { dispatch(install.postOrganizationUser({ role: ['admin'], pepUserId: values.pepUserId, msg: '新增管理员' })).then((res) => {//获取项企(PEP)全部部门及其下用户 if (res.success) { close(); } }) } }) } function handleCancel () { cancel(); //点击弹框取消 左边按钮 } return ( <>
成员成为管理员后,拥有平台所有权限和项目,成员的普通角色会被禁用。
{ for (var key in field) { if (key == 'department') { if (values.department >= 0) { let departmentList = [] for (let i = 0; i < pepList.length; i++) { if (pepList[i].id == values.department) { departmentList = pepList[i].users } } setPeopleList(departmentList) setDisablePeople(false) form.current.setValue('pepUserId', undefined); } else { setPeopleList([]) setDisablePeople(true) form.current.setValue('pepUserId', undefined); } } } }} getFormApi={(formApi) => (form.current = formApi)} >
{ pepList.map((item, index) => { return ( {item.name} ) }) }
{ peopleList.map((item, index) => { return ( {item.name} ) }) }
); } function mapStateToProps (state) { const { auth, global, members } = state; return { // loading: members.isRequesting, user: auth.user, actions: global.actions, // members: members.data, }; } export default connect(mapStateToProps)(pushModal);