import React, { Component } from 'react' import { Table, Card, Badge, Select, Button, Modal, Row, Col, message, Popconfirm } from 'antd'; import PropTypes from 'prop-types'; import { autobind } from 'core-decorators'; import { connect } from 'react-redux'; import ErrMsg from '../../../../components/ErrMsg/ErrMsg.js'; import { fetchGroupMemberList } from '../../../../reducer/modules/group.js'; import { getProjectMsg, getProjectMemberList, addMember, delMember, changeMemberRole } from '../../../../reducer/modules/project.js'; import UsernameAutoComplete from '../../../../components/UsernameAutoComplete/UsernameAutoComplete.js'; import '../Setting.scss'; const Option = Select.Option; const arrayAddKey = (arr) => { return arr.map((item, index) => { return { ...item, key: index } }); } @connect( state => { return { projectMsg: state.project.projectMsg, uid: state.user.uid } }, { fetchGroupMemberList, getProjectMsg, getProjectMemberList, addMember, delMember, changeMemberRole } ) class ProjectMember extends Component { constructor(props) { super(props); this.state = { groupMemberList: [], projectMemberList: [], groupName: '', role: '', visible: false, dataSource: [], inputUid: 0, inputRole: 'dev' } } static propTypes = { projectId: PropTypes.number, projectMsg: PropTypes.object, uid: PropTypes.number, addMember: PropTypes.func, delMember: PropTypes.func, changeMemberRole: PropTypes.func, fetchGroupMemberList: PropTypes.func, getProjectMsg: PropTypes.func, getProjectMemberList: PropTypes.func } @autobind showAddMemberModal() { this.setState({ visible: true }); } // 重新获取列表 @autobind reFetchList() { this.props.getProjectMemberList(this.props.projectId).then((res) => { this.setState({ projectMemberList: arrayAddKey(res.payload.data.data), visible: false }); }); } // 增 - 添加成员 @autobind handleOk() { this.props.addMember({ id: this.props.projectId, member_uid: this.state.inputUid, role: this.state.inputRole }).then((res) => { if (!res.payload.data.errcode) { message.success('添加成功!'); this.reFetchList(); // 添加成功后重新获取分组成员列表 } }); } // 添加成员时 选择新增成员权限 @autobind changeNewMemberRole(value) { this.setState({ inputRole: value }); } // 删 - 删除分组成员 @autobind deleteConfirm(member_uid) { return () => { const id = this.props.projectId; this.props.delMember({ id, member_uid }).then((res) => { if (!res.payload.data.errcode) { message.success(res.payload.data.errmsg); this.reFetchList(); // 添加成功后重新获取分组成员列表 } }); } } // 改 - 修改成员权限 @autobind changeUserRole(e) { const id = this.props.projectId; const role = e.split('-')[0]; const member_uid = e.split('-')[1]; this.props.changeMemberRole({ id, member_uid, role }).then((res) => { if (!res.payload.data.errcode) { message.success(res.payload.data.errmsg); this.reFetchList(); // 添加成功后重新获取分组成员列表 } }); } // 关闭模态框 @autobind handleCancel() { this.setState({ visible: false }); } @autobind onUserSelect(childState) { this.setState({ inputUid: childState.uid }) } async componentWillMount() { const groupMemberList = await this.props.fetchGroupMemberList(this.props.projectMsg.group_id); const rojectMsg = await this.props.getProjectMsg(this.props.projectId); const projectMemberList = await this.props.getProjectMemberList(this.props.projectId); this.setState({ groupMemberList: groupMemberList.payload.data.data, groupName: this.props.projectMsg.group_name, projectMemberList: arrayAddKey(projectMemberList.payload.data.data), role: rojectMsg.payload.data.data.role }) } render () { const columns = [{ title: ' 项目成员 ('+this.state.projectMemberList.length + ') 人', dataIndex: 'username', key: 'username', render: (text, record) => { return (
{text}
{item.username}{item.uid === this.props.uid ?
组长
: null} {item.role === 'dev' ?开发者
: null}