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';
const Search = Input.Search;
const TYPE_EDIT = 'edit';
import {
fetchGroupList,
@ -40,6 +41,7 @@ export default class GroupList extends Component {
state = {
addGroupModalVisible: false,
editGroupModalVisible: false,
newGroupName: '',
newGroupDesc: ''
}
@ -56,11 +58,32 @@ export default class GroupList extends Component {
}
@autobind
showModal() {
showModal(type) {
if (type === 'edit') {
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
addGroup() {
const { newGroupName: group_name, newGroupDesc: group_desc } = this.state;
@ -76,27 +99,42 @@ export default class GroupList extends Component {
});
}
@autobind
handleCancel(e) {
console.log(e);
editGroup() {
const { currGroupName: group_name, currGroupDesc: group_desc } = this.state;
const id = this.props.currGroup._id;
axios.post('/group/up', { group_name, group_desc, id }).then(res => {
if (res.data.errcode) {
message.error(res.data.errmsg);
} else {
this.setState({
addGroupModalVisible: false
editGroupModalVisible: false
});
this.props.setCurrGroup({ group_name, group_desc, _id: id });
}
});
}
@autobind
inputNewGroupName(e) {
inputNewGroupName(e, type) {
if (type === TYPE_EDIT) {
this.setState({ currGroupName: e.target.value})
} else {
this.setState({newGroupName: e.target.value});
}
}
@autobind
inputNewGroupDesc(e) {
inputNewGroupDesc(e, type) {
if (type === TYPE_EDIT) {
this.setState({ currGroupDesc: e.target.value})
} else {
this.setState({newGroupDesc: e.target.value});
}
}
@autobind
selectGroup(e) {
const groupId = e.key;
const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId });
this.props.setCurrGroup(currGroup);
// this.props.fetchProjectList(groupId);
}
render () {
@ -106,7 +144,10 @@ export default class GroupList extends Component {
<div>
<div className="group-bar">
<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>
<div className="group-operate">
@ -137,7 +178,7 @@ export default class GroupList extends Component {
title="添加分组"
visible={this.state.addGroupModalVisible}
onOk={this.addGroup}
onCancel={this.handleCancel}
onCancel={this.hideModal}
className="add-group-modal"
>
<Row gutter={6} className="modal-input">
@ -153,6 +194,26 @@ export default class GroupList extends Component {
</Col>
</Row>
</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>
)
}

View File

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