import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { Button, Icon, Modal,Alert, Input, message, Menu, Row, Col } from 'antd' import { autobind } from 'core-decorators'; import axios from 'axios'; import { withRouter } from 'react-router'; const { TextArea } = Input; const Search = Input.Search; const TYPE_EDIT = 'edit'; const confirm = Modal.confirm; import UsernameAutoComplete from '../../../components/UsernameAutoComplete/UsernameAutoComplete.js'; import { fetchGroupList, setCurrGroup, setGroupList } from '../../../reducer/modules/group.js' import './GroupList.scss' @connect( state => ({ groupList: state.group.groupList, currGroup: state.group.currGroup, curUserRole: state.user.role }), { fetchGroupList, setCurrGroup, setGroupList } ) @withRouter export default class GroupList extends Component { static propTypes = { groupList: PropTypes.array, currGroup: PropTypes.object, fetchGroupList: PropTypes.func, setCurrGroup: PropTypes.func, setGroupList: PropTypes.func, match: PropTypes.object, history: PropTypes.object, curUserRole: PropTypes.string } state = { addGroupModalVisible: false, editGroupModalVisible: false, newGroupName: '', newGroupDesc: '', currGroupName: '', currGroupDesc: '', groupList: [], owner_uid: 0 } constructor(props) { super(props) } async componentWillMount() { const groupName = this.props.match.params.groupName; await this.props.fetchGroupList(); let currGroup = this.props.groupList[0] || { group_name: '', group_desc: '' }; if(this.props.groupList.length && groupName){ for(let i = 0;i { return +group._id === +groupId }); this.props.setCurrGroup(currGroup); this.props.history.replace(`${currGroup._id}`); } @autobind onUserSelect(childState) { this.setState({ owner_uid: childState.uid }) } showConfirm =()=> { let that = this; confirm({ title: "确认删除 "+that.props.currGroup.group_name+" 分组吗?", content:

请输入分组名称确认此操作:

, onOk() { let groupName = document.getElementById('group_name').value; if(that.props.currGroup.group_name !== groupName){ message.error('分组名称有误') return new Promise((resolve, reject)=>{ reject('error') }) }else{ that.deleteGroup() } }, iconType: 'delete', onCancel() { } }); } @autobind async deleteGroup() { const self = this; const { currGroup } = self.props; const res = await axios.post('/api/group/del', {id: currGroup._id}) if (res.data.errcode) { message.error(res.data.errmsg); } else { message.success('删除成功') await self.props.fetchGroupList() const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' }; self.setState({groupList: self.props.groupList}); self.props.setCurrGroup(currGroup) } } @autobind searchGroup(e, value) { const v = value || e.target.value; const { groupList } = this.props; if (v === '') { this.setState({groupList}) } else { this.setState({groupList: groupList.filter(group => new RegExp(v, 'i').test(group.group_name))}) } } render () { const { currGroup } = this.props; const delmark = this.showModal(TYPE_EDIT)}/> const editmark = {this.showConfirm()}} type="delete" title="删除分组"/> return (
{currGroup.group_name}
{ this.props.curUserRole === "admin"?(editmark):'' } { this.props.curUserRole === "admin"?(delmark):'' }
简介:{currGroup.group_desc}
this.searchGroup(null, v)}/>
{ this.props.curUserRole === "admin"?():'' }
{ this.state.groupList.map((group) => ( {group.group_name} )) }
分组名:
简介:
组长:
this.hideModal(TYPE_EDIT)} className="add-group-modal" >
分组名:
this.inputNewGroupName(e, TYPE_EDIT)}>
简介:
) } }