forked from shen100/wemall
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
287 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
nodejs/static/javascripts/admin/actions/category/requestSaveCategory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
REQUEST_SAVE_CATEGORY, | ||
REQUEST_SAVE_CATEGORY_SUCCESS, | ||
} from '../../constants'; | ||
|
||
function receive(data) { | ||
return { | ||
type : REQUEST_SAVE_CATEGORY_SUCCESS, | ||
category : data.category | ||
}; | ||
} | ||
|
||
export default function(category) { | ||
return dispatch => { | ||
var url = pageConfig.apiPath + '/admin/category/update'; | ||
return fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(category) | ||
}) | ||
.then(response => response.json()) | ||
.then(json => dispatch(receive(json.data))); | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
nodejs/static/javascripts/admin/containers/category/EditCategory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { | ||
Button, | ||
Row, | ||
Col, | ||
Form, | ||
Input, | ||
InputNumber, | ||
TreeSelect | ||
} from 'antd'; | ||
|
||
import requestCategory from '../../actions/category/requestCategory'; | ||
import requestSaveCategory from '../../actions/category/requestSaveCategory'; | ||
import requestCategoryList from '../../actions/category/requestCategoryList'; | ||
import Software from '../Software'; | ||
import utils from '../../utils'; | ||
import analyze from '../../../sdk/analyze'; | ||
import '../../../../styles/admin/category/editCategory.css'; | ||
|
||
/* | ||
* 管理后台,新建或编辑商品分类 | ||
*/ | ||
class EitCategory extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.onNameBlur = this.onNameBlur.bind(this); | ||
this.onCategoryChange = this.onCategoryChange.bind(this); | ||
this.onRemarkBlur = this.onRemarkBlur.bind(this); | ||
this.onSubmit = this.onSubmit.bind(this); | ||
|
||
this.state = { | ||
categoryId : this.props.routeParams.id, | ||
parentId : '', | ||
parentKey : [], //父分类, 初始为数组是为了让树形控件显示placeholder | ||
name : '', | ||
remark : '', | ||
treeData : [] | ||
}; | ||
} | ||
componentDidMount() { | ||
analyze.pv(); | ||
const { dispatch } = this.props; | ||
if (this.state.categoryId) { | ||
dispatch(requestCategory(this.state.categoryId)); | ||
} | ||
dispatch(requestCategoryList()); | ||
} | ||
componentWillReceiveProps(nextProps) { | ||
var category = nextProps.data.category; | ||
var categories = nextProps.data.categories; | ||
if (category && categories && categories.length > 0) { | ||
this.setState({ | ||
categoryId : category.id, | ||
parentId : category.parentId, | ||
parentKey : utils.parseTreeNodeKey(categories, category.parentId), | ||
name : category.name, | ||
remark : category.remark, | ||
treeData : utils.parseTree(categories, { | ||
withRoot: true | ||
}) | ||
}); | ||
} | ||
} | ||
onNameBlur(event) { | ||
this.setState({ name: event.target.value }); | ||
} | ||
onCategoryChange(value) { | ||
var arr = value.split('-'); | ||
this.setState({ | ||
parentId : arr[arr.length - 1], | ||
parentKey : value | ||
}); | ||
} | ||
onRemarkBlur(event) { | ||
this.setState({ remark: event.target.value }); | ||
} | ||
onSubmit() { | ||
const { dispatch } = this.props; | ||
dispatch(requestSaveCategory({ | ||
id : this.state.categoryId, | ||
name : this.state.name, | ||
parentId : this.state.parentId, | ||
remark : this.state.remark | ||
})); | ||
} | ||
render() { | ||
let { data } = this.props; | ||
let editLabel = this.state.categoryId ? '编辑' : '添加'; | ||
let isLoading = this.state.categoryId | ||
&& (!data.category || !data.categories || data.categories.length <= 0) | ||
? true : false; | ||
|
||
let name = this.state.name; | ||
let remark = this.state.remark; | ||
let treeData = this.state.treeData; | ||
|
||
const FormItem = Form.Item; | ||
const formItemLayout = { | ||
labelCol: { | ||
xs: { span: 24 }, | ||
sm: { span: 3 }, | ||
}, | ||
wrapperCol: { | ||
xs: { span: 24 }, | ||
sm: { span: 12 }, | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Row gutter={24}> | ||
<Col span={24}> | ||
<div className="category-box"> | ||
<div className="category-title">{editLabel}商品分类</div> | ||
{ | ||
isLoading ? null : | ||
<Form> | ||
<FormItem {...formItemLayout} label="名称"> | ||
<Input defaultValue={name} onBlur={this.onNameBlur}/> | ||
</FormItem> | ||
<FormItem {...formItemLayout} label="父分类"> | ||
<TreeSelect | ||
style={{ width: '100%' }} | ||
value={this.state.parentKey} | ||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} | ||
treeData={treeData} | ||
placeholder="请选择父分类" | ||
treeDefaultExpandAll | ||
onChange={this.onCategoryChange} /> | ||
</FormItem> | ||
<FormItem {...formItemLayout} label="备注"> | ||
<Input type="textarea" defaultValue={remark} rows={4} onBlur={this.onRemarkBlur}/> | ||
</FormItem> | ||
</Form> | ||
} | ||
</div> | ||
</Col> | ||
<Col span={24}> | ||
<Col span={15} className="submit-box"> | ||
<Button onClick={this.onSubmit} type="primary" size="large">保存</Button> | ||
<Button className="submit-cancel-btn" size="large">取消</Button> | ||
</Col> | ||
</Col> | ||
</Row> | ||
<Software /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
data: state.category | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(EitCategory); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.