Skip to content

Commit

Permalink
1.增加商品分类管理页面
Browse files Browse the repository at this point in the history
2.商品上架,下架功能完成
3.商品分类,开启,关闭功能完成
  • Loading branch information
刘珅 committed May 2, 2017
1 parent 3ec442c commit f0f597f
Show file tree
Hide file tree
Showing 14 changed files with 332 additions and 11 deletions.
10 changes: 9 additions & 1 deletion go/controller/category/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,16 @@ func List(ctx *iris.Context) {
pageNo = 1
}

//默认按创建时间,降序来排序
var orderStr = "created_at"
if ctx.FormValue("asc") == "1" {
orderStr += " asc"
} else {
orderStr += " desc"
}

offset := (pageNo - 1) * config.ServerConfig.PageSize
queryErr := db.Offset(offset).Limit(config.ServerConfig.PageSize).Find(&categories).Error
queryErr := db.Offset(offset).Limit(config.ServerConfig.PageSize).Order(orderStr).Find(&categories).Error

if queryErr != nil {
ctx.JSON(iris.StatusOK, iris.Map{
Expand Down
31 changes: 31 additions & 0 deletions nodejs/static/javascripts/admin/actions/changeCategoryStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
CHANGE_CATEGORY_STATUS
} from '../constants';

function receiveCategoryStatus(data) {
return {
type : CHANGE_CATEGORY_STATUS,
id : data.id,
status : data.status
};
}

export default function(reqData) {
return dispatch => {
var url = pageConfig.apiURL + '/admin/category/status/update';
return fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
id : reqData.id,
status : reqData.status
})
})
.then(response => response.json())
.then(json => dispatch(receiveCategoryStatus(json.data)));
};
};

22 changes: 22 additions & 0 deletions nodejs/static/javascripts/admin/actions/changeProductStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
CHANGE_PRODUCT_STATUS
} from '../constants';

function receiveProductStatus(data) {
return {
type : CHANGE_PRODUCT_STATUS,
id : data.id,
status : data.status
};
}

export default function(reqData) {
return dispatch => {
var url = pageConfig.apiURL + '/admin/product/status/update/:id/:status';
url = url.replace(':id', reqData.id);
url = url.replace(':status', reqData.status);
return fetch(url)
.then(response => response.json())
.then(json => dispatch(receiveProductStatus(json.data)));
};
}
19 changes: 19 additions & 0 deletions nodejs/static/javascripts/admin/actions/requestCategoryList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
REQUEST_CATEGORY_LIST
} from '../constants';

function receiveCategories(data) {
return {
type: REQUEST_CATEGORY_LIST,
categories: data.categories
};
}

export default function() {
return dispatch => {
var url = pageConfig.apiURL + '/admin/categories';
return fetch(url)
.then(response => response.json())
.then(json => dispatch(receiveCategories(json.data)))
};
}
1 change: 0 additions & 1 deletion nodejs/static/javascripts/admin/components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Sidebar extends React.Component {
this.setState({
current: event.key
});

hashHistory.push(url.substr(1));
}
onMouseEnterSubMenu(event) {
Expand Down
2 changes: 1 addition & 1 deletion nodejs/static/javascripts/admin/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var sidebarData = [
{
id : getId(),
title : '商品分类管理',
url : '/admin/category/list'
url : '/category/manage'
},
{
id : getId(),
Expand Down
5 changes: 5 additions & 0 deletions nodejs/static/javascripts/admin/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ export const REQUEST_HOT_PRODUCT_LIST = 'requestHotProductList';

export const REQUEST_PRODUCT_LIST = 'requestProductList';

export const CHANGE_PRODUCT_STATUS = 'changeProductStatus';

export const REQUEST_CATEGORY_LIST = 'requestCategoryList';

export const CHANGE_CATEGORY_STATUS = 'changeCategoryStatus';

146 changes: 146 additions & 0 deletions nodejs/static/javascripts/admin/containers/CategoryManage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';

import {
Icon,
Row,
Col,
Popconfirm,
Table
} from 'antd';

import requestCategoryList from '../actions/requestCategoryList';
import changeCategoryStatus from '../actions/changeCategoryStatus';
import Software from './Software';
import analyze from '../../sdk/analyze';
import '../../../styles/admin/categoryManage.css';

/*
* 管理后台,商品分类管理
*/
class CategoryManage extends Component {
constructor(props) {
super(props);
var self = this;
this.state = {
columns: [
{
title: '分类名称',
dataIndex: 'name'
},
{
title: '排序',
dataIndex: 'order'
},
{
title: '创建时间',
dataIndex: 'createdAt'
},
{
title: '操作',
render: (text, record) => {
let openEnabled = false;
let closeEnabled = false;
//1: 已开启
//2: 已关闭
if (record.status == 1) {
closeEnabled = true;
} else if (record.status == 2) {
openEnabled = true;
}
return (
<span>
<a>
<Icon type="eye"/>
<span>查看</span>
</a>
<span className="ant-divider category-manage-divider" />
<a>
<Icon type="edit"/>
<span>编辑</span>
</a>
<span className="ant-divider category-manage-divider" />
{
openEnabled ?
<Popconfirm title="确定要开启?" okText="确定" cancelText="取消"
onConfirm={self.onMenuOpen.bind(self, record)}>
<a>
<Icon type="arrow-up"/>
<span>开启</span>
</a>
</Popconfirm>
:
(
closeEnabled ?
<Popconfirm title="确定要关闭?" okText="确定" cancelText="取消"
onConfirm={self.onMenuClose.bind(self, record)}>
<a>
<Icon type="arrow-down"/>
<span>关闭</span>
</a>
</Popconfirm>
:
null
)
}
</span>
);
}
}
]
};
}
componentDidMount() {
const { dispatch } = this.props;
dispatch(requestCategoryList());
analyze.pv();
}
onMenuOpen(record) {
const { dispatch } = this.props;
//1: 已开启
//2: 已关闭
dispatch(changeCategoryStatus({
id : record.id,
status : 1
}));
}
onMenuClose(record) {
const { dispatch } = this.props;
//1: 已开启
//2: 已关闭
dispatch(changeCategoryStatus({
id : record.id,
status : 2
}));
}
render() {
let { data } = this.props;
let { columns } = this.state;
let isLoading = data.categories.length > 0 ? false : true;
return (
<div>
<Row gutter={24}>
<Col span={24}>
<div className="category-list-box">
<div className="category-list-title">商品分类列表</div>
<Table rowKey="id" columns={columns}
loading={isLoading} pagination={false}
dataSource={data.categories} bordered />
</div>
</Col>
</Row>
<Software />
</div>
);
}
}

const mapStateToProps = (state) => {
return {
data: state.category
};
}

export default connect(mapStateToProps)(CategoryManage);

23 changes: 21 additions & 2 deletions nodejs/static/javascripts/admin/containers/ProductManage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'antd';

import requestProductList from '../actions/requestProductList';
import changeProductStatus from '../actions/changeProductStatus';
import Software from './Software';
import analyze from '../../sdk/analyze';
import '../../../styles/admin/productManage.css';
Expand All @@ -36,6 +37,10 @@ class ProductManage extends Component {
title: '购买量',
dataIndex: 'buyCount'
},
{
title: '创建时间',
dataIndex: 'createdAt'
},
{
title: '销售额',
dataIndex: 'totalSale'
Expand Down Expand Up @@ -106,10 +111,24 @@ class ProductManage extends Component {
analyze.pv();
}
onProductUp(record) {
console.log(11, record)
const { dispatch } = this.props;
//1: 商品已上架
//2: 商品已下架
//3: 商品未上架
dispatch(changeProductStatus({
id : record.id,
status : 1
}));
}
onProductDown(record) {
console.log(11, record)
const { dispatch } = this.props;
//1: 商品已上架
//2: 商品已下架
//3: 商品未上架
dispatch(changeProductStatus({
id : record.id,
status : 2
}));
}
render() {
let { data } = this.props;
Expand Down
35 changes: 35 additions & 0 deletions nodejs/static/javascripts/admin/reducers/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
REQUEST_CATEGORY_LIST,
CHANGE_CATEGORY_STATUS
} from '../constants';

let initState = {
categories: []
};

export default (state = initState, action) => {
switch (action.type) {
case REQUEST_CATEGORY_LIST: {
return {
...state,
categories: action.categories
};
}
case CHANGE_CATEGORY_STATUS: {
let categories = state.categories.slice(0);
for (let i = 0; i < categories.length; i++) {
if (categories[i].id == action.id) {
categories[i].status = action.status;
break;
}
}
return {
...state,
categories: categories
};
}
default: {
return state
}
}
}
4 changes: 3 additions & 1 deletion nodejs/static/javascripts/admin/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import systemIndex from './systemIndex';
import userAnalyze from './userAnalyze';
import orderAnalyze from './orderAnalyze';
import productAnalyze from './productAnalyze';
import category from './category';

const reducers = {
software,
systemIndex,
userAnalyze,
orderAnalyze,
productAnalyze
productAnalyze,
category
};

export default reducers;
16 changes: 15 additions & 1 deletion nodejs/static/javascripts/admin/reducers/productAnalyze.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
REQUEST_HOT_PRODUCT_LIST,
REQUEST_PRODUCT_LIST
REQUEST_PRODUCT_LIST,
CHANGE_PRODUCT_STATUS
} from '../constants';

let initState = {
Expand All @@ -22,6 +23,19 @@ export default (state = initState, action) => {
products: action.products
};
}
case CHANGE_PRODUCT_STATUS: {
let products = state.products.slice(0);
for (let i = 0; i < products.length; i++) {
if (products[i].id == action.id) {
products[i].status = action.status;
break;
}
}
return {
...state,
products: products
};
}
default: {
return state
}
Expand Down
Loading

0 comments on commit f0f597f

Please sign in to comment.