feat: 编辑分组

This commit is contained in:
zwjamnsss 2017-07-19 14:53:51 +08:00
parent 8945e71308
commit 9ddac64fee
2 changed files with 78 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import { autobind } from 'core-decorators';
import axios from 'axios'; import axios from 'axios';
const Search = Input.Search; const Search = Input.Search;
const TYPE_EDIT = 'edit';
import { import {
fetchGroupList, fetchGroupList,
@ -40,6 +41,7 @@ export default class GroupList extends Component {
state = { state = {
addGroupModalVisible: false, addGroupModalVisible: false,
editGroupModalVisible: false,
newGroupName: '', newGroupName: '',
newGroupDesc: '' newGroupDesc: ''
} }
@ -56,10 +58,31 @@ export default class GroupList extends Component {
} }
@autobind @autobind
showModal() { showModal(type) {
this.setState({ if (type === 'edit') {
addGroupModalVisible: true const { currGroup } = this.props;
}); this.setState({
currGroupName: currGroup.group_name,
currGroupDesc: currGroup.group_desc,
editGroupModalVisible: true
});
} else {
this.setState({
addGroupModalVisible: true
});
}
}
@autobind
hideModal(type) {
if (type === TYPE_EDIT) {
this.setState({
editGroupModalVisible: false
});
} else {
this.setState({
addGroupModalVisible: false
});
}
} }
@autobind @autobind
addGroup() { addGroup() {
@ -76,19 +99,35 @@ export default class GroupList extends Component {
}); });
} }
@autobind @autobind
handleCancel(e) { editGroup() {
console.log(e); const { currGroupName: group_name, currGroupDesc: group_desc } = this.state;
this.setState({ const id = this.props.currGroup._id;
addGroupModalVisible: false axios.post('/group/up', { group_name, group_desc, id }).then(res => {
if (res.data.errcode) {
message.error(res.data.errmsg);
} else {
this.setState({
editGroupModalVisible: false
});
this.props.setCurrGroup({ group_name, group_desc, _id: id });
}
}); });
} }
@autobind @autobind
inputNewGroupName(e) { inputNewGroupName(e, type) {
this.setState({newGroupName: e.target.value}); if (type === TYPE_EDIT) {
this.setState({ currGroupName: e.target.value})
} else {
this.setState({newGroupName: e.target.value});
}
} }
@autobind @autobind
inputNewGroupDesc(e) { inputNewGroupDesc(e, type) {
this.setState({newGroupDesc: e.target.value}); if (type === TYPE_EDIT) {
this.setState({ currGroupDesc: e.target.value})
} else {
this.setState({newGroupDesc: e.target.value});
}
} }
@autobind @autobind
@ -96,7 +135,6 @@ export default class GroupList extends Component {
const groupId = e.key; const groupId = e.key;
const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId }); const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId });
this.props.setCurrGroup(currGroup); this.props.setCurrGroup(currGroup);
// this.props.fetchProjectList(groupId);
} }
render () { render () {
@ -106,7 +144,10 @@ export default class GroupList extends Component {
<div> <div>
<div className="group-bar"> <div className="group-bar">
<div className="curr-group"> <div className="curr-group">
<div className="curr-group-name">{currGroup.group_name}<Icon className="edit-group" type="edit"/></div> <div className="curr-group-name">
{currGroup.group_name}
<Icon className="edit-group" type="edit" onClick={() => this.showModal(TYPE_EDIT)}/>
</div>
<div className="curr-group-desc">简介{currGroup.group_desc}</div> <div className="curr-group-desc">简介{currGroup.group_desc}</div>
</div> </div>
<div className="group-operate"> <div className="group-operate">
@ -137,7 +178,7 @@ export default class GroupList extends Component {
title="添加分组" title="添加分组"
visible={this.state.addGroupModalVisible} visible={this.state.addGroupModalVisible}
onOk={this.addGroup} onOk={this.addGroup}
onCancel={this.handleCancel} onCancel={this.hideModal}
className="add-group-modal" className="add-group-modal"
> >
<Row gutter={6} className="modal-input"> <Row gutter={6} className="modal-input">
@ -153,6 +194,26 @@ export default class GroupList extends Component {
</Col> </Col>
</Row> </Row>
</Modal> </Modal>
<Modal
title="编辑分组"
visible={this.state.editGroupModalVisible}
onOk={this.editGroup}
onCancel={() => this.hideModal(TYPE_EDIT)}
className="add-group-modal"
>
<Row gutter={6} className="modal-input">
<Col span="5"><div className="label">分组名</div></Col>
<Col span="15">
<Input placeholder="请输入分组名称" value={this.state.currGroupName} onChange={(e) => this.inputNewGroupName(e, TYPE_EDIT)}></Input>
</Col>
</Row>
<Row gutter={6} className="modal-input">
<Col span="5"><div className="label">简介</div></Col>
<Col span="15">
<Input placeholder="请输入分组描述" value={this.state.currGroupDesc} onChange={(e) => this.inputNewGroupDesc(e, TYPE_EDIT)}></Input>
</Col>
</Row>
</Modal>
</div> </div>
) )
} }

View File

@ -30,7 +30,8 @@
} }
} }
.group-list { .group-list {
// background: #fff; max-height: 650px;
overflow: scroll;
border-bottom: 1px solid #e9e9e9; border-bottom: 1px solid #e9e9e9;
padding-bottom: 24px; padding-bottom: 24px;
border-radius: 0 0 6px 6px; border-radius: 0 0 6px 6px;