From 795314ca049cddabb7b3e1f212c38370cff2b676 Mon Sep 17 00:00:00 2001 From: zhenxianyimeng <1920405993@qq.com> Date: Mon, 26 Aug 2019 23:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E6=A0=BC=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/config/router.config.js | 5 + admin-web/src/locales/zh-CN/menu.js | 2 + .../src/models/product/productAttrList.js | 28 +++- .../src/pages/Product/ProductAttrList.js | 158 ++++++++++++++++++ .../src/pages/Product/ProductAttrList.less | 11 ++ admin-web/src/services/product.js | 56 ++++--- .../service/ProductAttrServiceImpl.java | 2 +- .../controller/admins/AdminController.java | 2 +- .../controller/admins/DeptmentController.java | 6 +- 9 files changed, 238 insertions(+), 32 deletions(-) create mode 100644 admin-web/src/pages/Product/ProductAttrList.js create mode 100644 admin-web/src/pages/Product/ProductAttrList.less diff --git a/admin-web/config/router.config.js b/admin-web/config/router.config.js index a058ce557..3bf367c03 100644 --- a/admin-web/config/router.config.js +++ b/admin-web/config/router.config.js @@ -125,6 +125,11 @@ export default [ name: 'product-brand-list', component: './Product/ProductBrandList', }, + { + path: '/product/product-attr-list', + name: 'product-attr-list', + component: './Product/ProductAttrList', + }, ], }, // promotion diff --git a/admin-web/src/locales/zh-CN/menu.js b/admin-web/src/locales/zh-CN/menu.js index 2dcf49161..0e9ef9d14 100644 --- a/admin-web/src/locales/zh-CN/menu.js +++ b/admin-web/src/locales/zh-CN/menu.js @@ -52,6 +52,8 @@ export default { 'menu.product.product-spu-update': '商品编辑', 'menu.product.product-category-list': '商品分类', 'menu.product.product-brand-list': '商品品牌', + 'menu.product.product-attr-list': '规格管理', + // 订单 'menu.order': '订单管理', 'menu.order.order-list': '订单管理', diff --git a/admin-web/src/models/product/productAttrList.js b/admin-web/src/models/product/productAttrList.js index 54ffaf64c..db3b6cc1d 100644 --- a/admin-web/src/models/product/productAttrList.js +++ b/admin-web/src/models/product/productAttrList.js @@ -1,11 +1,14 @@ import { message } from 'antd'; -import { productAttrTree, productAttrValueAdd } from '../../services/product'; +import { productAttrTree, productAttrValueAdd, productAttrPage } from '../../services/product'; +import PaginationHelper from '../../../helpers/PaginationHelper'; export default { namespace: 'productAttrList', state: { list: [], + attrData: [], + pagination: PaginationHelper.defaultPaginationConfig, }, effects: { @@ -51,6 +54,21 @@ export default { // }); // }, + *page({ payload }, { call, put }) { + const result = yield call(productAttrPage, payload); + let attrData = {}; + if (result.code === 0) { + attrData = result.data; + } + yield put({ + type: 'save', + payload: { + attrData, + pagination: PaginationHelper.formatPagination(attrData, payload), + }, + }); + }, + *tree({ payload }, { call, put }) { const { queryParams } = payload; const response = yield call(productAttrTree, queryParams); @@ -84,10 +102,16 @@ export default { callback(response.data); } } - } + }, }, reducers: { + save(state, action) { + return { + ...state, + ...action.payload, + }; + }, treeSuccess(state, { payload }) { return { ...state, diff --git a/admin-web/src/pages/Product/ProductAttrList.js b/admin-web/src/pages/Product/ProductAttrList.js new file mode 100644 index 000000000..45566077c --- /dev/null +++ b/admin-web/src/pages/Product/ProductAttrList.js @@ -0,0 +1,158 @@ +import React, { PureComponent, Fragment, Component } from 'react'; +import { Form, Card, Table, Button, Divider, Modal, Input } from 'antd'; +import moment from 'moment'; +import { connect } from 'dva'; +import PageHeaderWrapper from '@/components/PageHeaderWrapper'; +import PaginationHelper from '../../../helpers/PaginationHelper'; +import styles from './ProductAttrList.less'; + +const FormItem = Form.Item; +const CreateForm = Form.create()(props => { + const { modalVisible, form, handleAdd, handleModalVisible, modalType, initValues } = props; + + const okHandle = () => { + form.validateFields((err, fieldsValue) => { + if (err) return; + let pid = fieldsValue.pid; + if (fieldsValue.pid) { + pid = pid.split('-')[1]; + fieldsValue.pid = pid; + } + form.resetFields(); + handleAdd({ + fields: fieldsValue, + modalType, + initValues, + }); + }); + }; + + const selectStyle = { + width: 200, + }; + + function onTypeChange(event) { + initValues.type = parseInt(event.target.value); + } + + const title = modalType === 'add' ? '添加规格' : '编辑规格'; + const okText = modalType === 'add' ? '添加' : '编辑'; + return ( + handleModalVisible()} + > + + {form.getFieldDecorator('name', { + initialValue: initValues ? initValues.name : null, + rules: [{ required: true, message: '请输入规格名称!', min: 2 }], + })()} + + + ); +}); + +@connect(({ productAttrList, loading }) => ({ + productAttrList, + attrData: productAttrList.attrData, + loading: loading.models.productAttrList, +})) +@Form.create() +export default class ProductAttrList extends PureComponent { + state = { + modalVisible: false, + modalType: 'add', //add or update + initValues: {}, + }; + + componentDidMount() { + const { dispatch } = this.props; + dispatch({ + type: 'productAttrList/page', + payload: { + ...PaginationHelper.defaultPayload, + }, + }); + } + + handleModalVisible = (flag, modalType, initValues) => { + this.setState({ + modalVisible: !!flag, + initValues: initValues || {}, + modalType: modalType || 'add', + }); + }; + + render() { + const { attrData, productAttrList, loading, pagination } = this.props; + const columns = [ + { + title: '规格名称', + dataIndex: 'name', + }, + { + title: '状态', + dataIndex: 'status', + render: val => {val === 1 ? '开启' : '禁用'}, + }, + { + title: '创建时间', + dataIndex: 'createTime', + sorter: true, + render: val => {moment(val).format('YYYY-MM-DD')}, + }, + { + title: '操作', + render: (text, record) => ( + + this.handleModalVisible(true, 'update', record)}>编辑 + + this.handleDelete(record)}> + 删除 + + + ), + }, + ]; + + const { modalVisible, modalType, initValues } = this.state; + + const parentMethods = { + handleAdd: this.handleAdd, + handleModalVisible: this.handleModalVisible, + modalType, + initValues, + }; + + return ( + + + + + this.handleModalVisible(true, 'add', {})} + > + 新建规格 + + + + + + {modalVisible ? : null} + + ); + } +} diff --git a/admin-web/src/pages/Product/ProductAttrList.less b/admin-web/src/pages/Product/ProductAttrList.less new file mode 100644 index 000000000..22e257421 --- /dev/null +++ b/admin-web/src/pages/Product/ProductAttrList.less @@ -0,0 +1,11 @@ +@import '~antd/lib/style/themes/default.less'; +@import '~@/utils/utils.less'; + +.tableList { + .tableListOperator { + margin-bottom: 16px; + button { + margin-right: 8px; + } + } +} diff --git a/admin-web/src/services/product.js b/admin-web/src/services/product.js index a8929dd4e..0e3014ac9 100644 --- a/admin-web/src/services/product.js +++ b/admin-web/src/services/product.js @@ -4,23 +4,23 @@ import request from '@/utils/request'; // product category export async function productCategoryTree(params) { - return request(`/product-api/admins/category/tree?${stringify(params)}`, { - method: 'GET', - }); + return request(`/product-api/admins/category/tree?${stringify(params)}`, { + method: 'GET', + }); } export async function productCategoryAdd(params) { - return request(`/product-api/admins/category/add?${stringify(params)}`, { - method: 'POST', - body: {}, - }); + return request(`/product-api/admins/category/add?${stringify(params)}`, { + method: 'POST', + body: {}, + }); } export async function productCategoryUpdate(params) { - return request(`/product-api/admins/category/update?${stringify(params)}`, { - method: 'POST', - body: {}, - }); + return request(`/product-api/admins/category/update?${stringify(params)}`, { + method: 'POST', + body: {}, + }); } export async function productCategoryUpdateStatus(params) { @@ -31,9 +31,9 @@ export async function productCategoryUpdateStatus(params) { } export async function productCategoryDelete(params) { - return request(`/product-api/admins/category/delete?${stringify(params)}`, { - method: 'POST', - }); + return request(`/product-api/admins/category/delete?${stringify(params)}`, { + method: 'POST', + }); } // product spu + sku @@ -85,6 +85,12 @@ export async function productSpuInfo(params) { // product attr + attr value +export async function productAttrPage(params) { + return request(`/product-api/admins/attr/page?${stringify(params)}`, { + method: 'GET', + }); +} + export async function productAttrTree(params) { return request(`/product-api/admins/attr/tree?${stringify(params)}`, { method: 'GET', @@ -98,30 +104,30 @@ export async function productAttrValueAdd(params) { }); } - // product brand 2019-05-31 +// product brand 2019-05-31 export async function productBrandAdd(params) { - return request(`/product-api/admins/brand/add?${stringify(params)}`, { - method: 'POST', - body: {}, - }); + return request(`/product-api/admins/brand/add?${stringify(params)}`, { + method: 'POST', + body: {}, + }); } export async function productBrandUpdate(params) { - return request(`/product-api/admins/brand/update?${stringify(params)}`, { - method: 'POST', - body: {}, - }); + return request(`/product-api/admins/brand/update?${stringify(params)}`, { + method: 'POST', + body: {}, + }); } export async function productBrandGet(params) { return request(`/product-api/admins/brand/get?${stringify(params)}`, { - method: 'GET' + method: 'GET', }); } export async function productBrandPage(params) { return request(`/product-api/admins/brand/page?${stringify(params)}`, { - method: 'GET' + method: 'GET', }); } diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java index a48375409..7ccdfb8ce 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductAttrServiceImpl.java @@ -72,7 +72,7 @@ public class ProductAttrServiceImpl implements ProductAttrService { public ProductAttrPageBO getProductAttrPage(ProductAttrPageDTO productAttrPageDTO) { ProductAttrPageBO productAttrPageBO = new ProductAttrPageBO(); // 查询分页数据 - int offset = productAttrPageDTO.getPageNo() * productAttrPageDTO.getPageSize(); + int offset = (productAttrPageDTO.getPageNo()-1) * productAttrPageDTO.getPageSize(); productAttrPageBO.setAttrs(ProductAttrConvert.INSTANCE.convert(productAttrMapper.selectListByNameLike(productAttrPageDTO.getName(), offset, productAttrPageDTO.getPageSize()))); // 查询分页总数 diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index 36754ec2c..9a72166f7 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -91,7 +91,7 @@ public class AdminController { } // =========== 管理员管理 API =========== - + //TODO 目前需要增加搜索所有子部门的用户 @GetMapping("/page") @RequiresPermissions("system.admin.page") @ApiOperation(value = "管理员分页") diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java index 132f520dc..1a74a8572 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java @@ -49,7 +49,7 @@ public class DeptmentController { public CommonResult> treeAll(){ List list = deptmentService.getAllDeptments(); List voList = DeptmentConvert.INSTANCE.convert(list); - Map nodeMap = calaNodeMap(voList); + Map nodeMap = calcNodeMap(voList); // 获得到所有的根节点 List rootNodes = nodeMap.values().stream() .filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT)) @@ -64,7 +64,7 @@ public class DeptmentController { PageResult voPageResult = DeptmentConvert.INSTANCE.convert(pageResult); List list = deptmentService.getAllDeptments(); List voList = DeptmentConvert.INSTANCE.convert(list); - Map nodeMap = calaNodeMap(voList); + Map nodeMap = calcNodeMap(voList); voPageResult.getList().forEach(d->{ d.setChildren(nodeMap.get(d.getId()).getChildren()); }); @@ -97,7 +97,7 @@ public class DeptmentController { )); } - private Map calaNodeMap(List voList){ + private Map calcNodeMap(List voList){ Map nodeMap = voList.stream().collect(Collectors.toMap(e->e.getId(), e->e)); nodeMap.values().stream()