前端:商品分类模块完成

pull/1/head
YunaiV 2019-03-15 22:09:26 +08:00
parent 888151f523
commit fd1d1d3074
4 changed files with 76 additions and 48 deletions

View File

@ -1,6 +1,5 @@
import { message } from 'antd';
import { addResource, updateResource, deleteResource, resourceTree } from '../../services/admin';
import { productCategoryTree } from '../../services/product';
import { productCategoryTree, productCategoryAdd, productCategoryUpdate, productCategoryUpdateStatus, productCategoryDelete } from '../../services/product';
export default {
namespace: 'productCategoryList',
@ -12,7 +11,7 @@ export default {
effects: {
*add({ payload }, { call, put }) {
const { callback, body } = payload;
const response = yield call(addResource, body);
const response = yield call(productCategoryAdd, body);
if (callback) {
callback(response);
}
@ -23,7 +22,18 @@ export default {
},
*update({ payload }, { call, put }) {
const { callback, body } = payload;
const response = yield call(updateResource, body);
const response = yield call(productCategoryUpdate, body);
if (callback) {
callback(response);
}
yield put({
type: 'tree',
payload: {},
});
},
*updateStatus({ payload }, { call, put }) {
const { callback, body } = payload;
const response = yield call(productCategoryUpdateStatus, body);
if (callback) {
callback(response);
}
@ -33,13 +43,11 @@ export default {
});
},
*delete({ payload }, { call, put }) {
const response = yield call(deleteResource, payload);
const response = yield call(productCategoryDelete, payload);
message.info('删除成功!');
yield put({
type: 'treeSuccess',
payload: {
list: response.data,
},
type: 'tree',
payload: {},
});
},
*tree({ payload }, { call, put }) {

View File

@ -3,7 +3,7 @@
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import { Card, Form, Input, Select, Button, Modal, message, Table, Divider } from 'antd';
import {Card, Form, Input, Select, Button, Modal, message, Table, Divider, InputNumber} from 'antd';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from './ProductCategoryList.less';
@ -43,46 +43,34 @@ const CreateForm = Form.create()(props => {
okText={okText}
onCancel={() => handleModalVisible()}
>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="菜单展示名">
{form.getFieldDecorator('displayName', {
rules: [{ required: true, message: '请输入菜单展示名字!', min: 2 }],
initialValue: initValues.displayName,
})(<Input placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="操作">
{form.getFieldDecorator('handler', {
initialValue: initValues.handler,
})(<Input placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="资源名字">
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="分类名">
{form.getFieldDecorator('name', {
rules: [{ required: true, message: '请输入资源名字!' }],
rules: [{ required: true, message: '请输入分类名!', min: 2 }],
initialValue: initValues.name,
})(<Input placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="父级资源编号">
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="分类图片">
{form.getFieldDecorator('picUrl', {
initialValue: initValues.handler,
})(<Input placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="父分类编号">
{form.getFieldDecorator('pid', {
rules: [{ required: true, message: '请输入父级编号!' }],
rules: [{ required: true, message: '请输入父分类编号!' }],
initialValue: initValues.pid,
})(<Input placeholder="请输入" />)}
<span>根节点为 0</span>
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="排序">
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="排序">
{form.getFieldDecorator('sort', {
rules: [{ required: true, message: '请输入菜单排序!' }],
rules: [{ required: true, message: '请输入排序' }],
initialValue: initValues.sort,
})(<Input placeholder="请输入" />)}
})(<InputNumber placeholder="请输入" />)}
</FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="资源类型">
{form.getFieldDecorator('type', {
rules: [{ required: true, message: '请选择资源类型!' }],
initialValue: 1,
})(
<Select showSearch style={selectStyle} placeholder="请选择">
<Option value={1}>菜单</Option>
<Option value={2}>Url</Option>
</Select>
)}
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="描述">
{form.getFieldDecorator('description', {
rules: [{ required: true, message: '请输入描述!' }],
initialValue: initValues.description,
})(<Input.TextArea placeholder="请输入" />)}
</FormItem>
</Modal>
);
@ -149,6 +137,30 @@ class ProductCategoryList extends PureComponent {
}
};
handleStatus(row) {
const { dispatch, data } = this.props;
const title = row.status === 1 ? '确认禁用?' : '确认开启?';
const updateStatus = row.status === 1 ? 2 : 1;
Modal.confirm({
title: `${title}`,
content: `${row.name}`,
onOk() {
dispatch({
type: 'productCategoryList/updateStatus',
payload: {
body: {
id: row.id,
status: updateStatus,
}
},
});
},
onCancel() {},
});
}
handleDelete(row) {
const { dispatch } = this.props;
Modal.confirm({
@ -223,7 +235,6 @@ class ProductCategoryList extends PureComponent {
<Fragment>
<a onClick={() => this.handleModalVisible(true, 'update', record)}>更新</a>
<Divider type="vertical"/>
<Divider type="vertical"/>
<a className={styles.tableDelete} onClick={() => this.handleStatus(record)}>
{statusText}
</a>

View File

@ -9,22 +9,29 @@ export async function productCategoryTree(params) {
});
}
export async function dictionaryAdd(params) {
return request(`/admin-api/admins/data_dict/add?${stringify(params)}`, {
export async function productCategoryAdd(params) {
return request(`/product-api/admins/category/add?${stringify(params)}`, {
method: 'POST',
body: {},
});
}
export async function dictionaryUpdate(params) {
return request(`/admin-api/admins/data_dict/update?${stringify(params)}`, {
export async function productCategoryUpdate(params) {
return request(`/product-api/admins/category/update?${stringify(params)}`, {
method: 'POST',
body: {},
});
}
export async function dictionaryDelete(params) {
return request(`/admin-api/admins/data_dict/delete?${stringify(params)}`, {
export async function productCategoryUpdateStatus(params) {
return request(`/product-api/admins/category/update_status?${stringify(params)}`, {
method: 'POST',
body: {},
});
}
export async function productCategoryDelete(params) {
return request(`/product-api/admins/category/delete?${stringify(params)}`, {
method: 'POST',
});
}

View File

@ -93,7 +93,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_STATUS_EQUALS.getCode());
}
// 更新商品分类
ProductCategoryDO updateProductCategory = new ProductCategoryDO().setStatus(status);
ProductCategoryDO updateProductCategory = new ProductCategoryDO()
.setId(productCategoryId).setStatus(status);
productCategoryMapper.update(updateProductCategory);
// TODO 操作日志
return CommonResult.success(true);
@ -113,7 +114,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
// TODO 芋艿:考虑下,是否需要判断下该分类下是否有商品
// TODO 芋艿,需要补充下,还有子分类
// 标记删除商品分类
ProductCategoryDO updateProductCategory = new ProductCategoryDO().setId(productCategoryId);
ProductCategoryDO updateProductCategory = new ProductCategoryDO()
.setId(productCategoryId);
updateProductCategory.setDeleted(BaseDO.DELETED_YES);
productCategoryMapper.update(updateProductCategory);
// TODO 操作日志