合并代码
This commit is contained in:
@@ -50,6 +50,7 @@ export default {
|
||||
'menu.product.product-spu-add': '商品添加',
|
||||
'menu.product.product-spu-update': '商品编辑',
|
||||
'menu.product.product-category-list': '商品分类',
|
||||
'menu.product.product-brand-list': '商品品牌',
|
||||
// 订单
|
||||
'menu.order': '订单管理',
|
||||
'menu.order.order-list': '订单管理',
|
||||
|
||||
130
admin-web/src/models/product/productBrandList.js
Normal file
130
admin-web/src/models/product/productBrandList.js
Normal file
@@ -0,0 +1,130 @@
|
||||
import { message } from 'antd';
|
||||
import { productBrandPage} from '../../services/product';
|
||||
import {routerRedux} from "dva/router";
|
||||
import PaginationHelper from '../../../helpers/PaginationHelper';
|
||||
|
||||
const SEARCH_PARAMS_DEFAULT = {
|
||||
name: '',
|
||||
status: 1,
|
||||
cid: undefined,
|
||||
};
|
||||
|
||||
export default {
|
||||
namespace: 'productBrandList',
|
||||
|
||||
state: {
|
||||
// 分页列表相关
|
||||
list: [],
|
||||
listLoading: false,
|
||||
pagination: PaginationHelper.defaultPaginationConfig,
|
||||
searchParams: SEARCH_PARAMS_DEFAULT,
|
||||
|
||||
// 添加 or 修改表单相关
|
||||
// modalVisible: false,
|
||||
// modalType: undefined, // 'add' or 'update' 表单
|
||||
formVals: {}, // 当前表单值
|
||||
// modalLoading: false,
|
||||
|
||||
|
||||
sortModalVisible: false, // 修改排序弹窗
|
||||
sortModalLoading: false, // 修改排序的加载
|
||||
},
|
||||
|
||||
effects: {
|
||||
// *updateStatus({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
// const response = yield call(productCategoryUpdateStatus, body);
|
||||
// if (callback) {
|
||||
// callback(response);
|
||||
// }
|
||||
// yield put({
|
||||
// type: 'tree',
|
||||
// payload: {},
|
||||
// });
|
||||
// },
|
||||
// *delete({ payload }, { call, put }) {
|
||||
// const response = yield call(productCategoryDelete, payload);
|
||||
// message.info('删除成功!');
|
||||
// yield put({
|
||||
// type: 'tree',
|
||||
// payload: {},
|
||||
// });
|
||||
// },
|
||||
*redirectToAdd({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
yield put(routerRedux.replace('/product/product-spu-add'));
|
||||
},
|
||||
*redirectToUpdate({ payload }, { call, put }) {
|
||||
// const { callback, body } = payload;
|
||||
yield put(routerRedux.replace('/product/product-spu-update?id=' + payload));
|
||||
},
|
||||
*page({ payload }, { call, put }) {
|
||||
// const { queryParams } = payload;
|
||||
// const response = yield call(productSpuPage, payload);
|
||||
// message.info('查询成功!');
|
||||
// yield put({
|
||||
// type: 'treeSuccess',
|
||||
// payload: {
|
||||
// list: response.data,
|
||||
// },
|
||||
// });
|
||||
|
||||
// 显示加载中
|
||||
yield put({
|
||||
type: 'changeListLoading',
|
||||
payload: true,
|
||||
});
|
||||
|
||||
// 请求
|
||||
const response = yield call(productBrandPage, payload);
|
||||
// 响应
|
||||
yield put({
|
||||
type: 'add',
|
||||
payload: {
|
||||
list: response.data.brands,
|
||||
pagination: PaginationHelper.formatPagination(response.data, payload),
|
||||
searchParams: {
|
||||
name: payload.name,
|
||||
status: payload.status,
|
||||
cid: payload.cid,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 隐藏加载中
|
||||
yield put({
|
||||
type: 'changeListLoading',
|
||||
payload: false,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
reducers: {
|
||||
treeSuccess(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
...payload,
|
||||
};
|
||||
},
|
||||
// 修改加载中的状态
|
||||
changeSortModalLoading(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
sortModalLoading: payload,
|
||||
};
|
||||
},
|
||||
changeListLoading(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
listLoading: payload,
|
||||
};
|
||||
},
|
||||
// 设置所有属性
|
||||
add(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
...payload,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
357
admin-web/src/pages/Product/ProductBrandList.js
Normal file
357
admin-web/src/pages/Product/ProductBrandList.js
Normal file
@@ -0,0 +1,357 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import React, { PureComponent, Fragment } from 'react';
|
||||
import { connect } from 'dva';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Row,
|
||||
Col,
|
||||
Button,
|
||||
Modal,
|
||||
message,
|
||||
Table,
|
||||
Divider,
|
||||
Tree,
|
||||
Tabs,
|
||||
TreeSelect,
|
||||
Spin,
|
||||
InputNumber
|
||||
} from 'antd';
|
||||
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
|
||||
|
||||
import styles from './ProductSpuList.less';
|
||||
import PaginationHelper from "../../../helpers/PaginationHelper";
|
||||
import PicturesWall from "../../components/Image/PicturesWall";
|
||||
|
||||
const FormItem = Form.Item;
|
||||
|
||||
const status = ['未知', '开启', '禁用'];
|
||||
// 列表
|
||||
function List({ dataSource, loading, pagination, searchParams, dispatch,
|
||||
categoryTree,handleModalVisible}) {
|
||||
|
||||
|
||||
function onPageChange(page) { // 翻页
|
||||
dispatch({
|
||||
type: 'productBrandList/page',
|
||||
payload: {
|
||||
pageNo: page.current,
|
||||
pageSize: page.pageSize,
|
||||
...searchParams
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '品牌名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '品牌描述',
|
||||
dataIndex: 'description'
|
||||
},
|
||||
{
|
||||
title: '品牌图片',
|
||||
dataIndex: 'picUrl',
|
||||
render(val) {return <img width={120} src={val} />;},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render(val) {return <span>{status[val]}</span>;},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
render: val => <span>{moment(val).format('YYYY-MM-DD')}</span>,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 200,
|
||||
render: (text, record) => {
|
||||
const statusText = record.status === 1 ? '禁用' : '开启';
|
||||
return (
|
||||
<Fragment>
|
||||
<a onClick={() => handleModalVisible(true, 'update', record)}>编辑</a>
|
||||
<Divider type="vertical"/>
|
||||
<a className={styles.tableDelete} onClick={() => handleStatus(record)}>{statusText}</a>
|
||||
<Divider type="vertical"/>
|
||||
<a className={styles.tableDelete} onClick={() => handleDelete(record)}>删除</a>
|
||||
</Fragment>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={dataSource}
|
||||
rowKey="id"
|
||||
pagination={pagination}
|
||||
onChange={onPageChange}
|
||||
loading={loading} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 新建 form 表单
|
||||
const AddOrUpdateForm = Form.create()(props => {
|
||||
const { dispatch, loading, modalVisible, form, handleModalVisible, modalType, categoryTree, formVals } = props;
|
||||
let picturesWall = null;
|
||||
|
||||
const okHandle = () => {
|
||||
form.validateFields((err, fields) => {
|
||||
if (err) return;
|
||||
if (modalType === 'add') {
|
||||
dispatch({
|
||||
type: 'productBrandList/add',
|
||||
payload: {
|
||||
body: {
|
||||
...fields,
|
||||
picUrl: picturesWall ? picturesWall.getUrl() : undefined,
|
||||
},
|
||||
callback: () => {
|
||||
// 清空表单
|
||||
form.resetFields();
|
||||
// 提示
|
||||
message.success('新建成功');
|
||||
// 关闭弹窗
|
||||
handleModalVisible();
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: 'productCategoryList/update',
|
||||
payload: {
|
||||
body: {
|
||||
...formVals,
|
||||
...fields,
|
||||
picUrl: picturesWall ? picturesWall.getUrl() : undefined,
|
||||
},
|
||||
callback: () => {
|
||||
// 清空表单
|
||||
form.resetFields();
|
||||
// 提示
|
||||
message.success('编辑成功');
|
||||
// 关闭弹窗
|
||||
handleModalVisible();
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const title = modalType === 'add' ? '新建品牌' : '编辑品牌';
|
||||
const okText = modalType === 'add' ? '新建' : '编辑';
|
||||
return (
|
||||
<Modal
|
||||
destroyOnClose
|
||||
title={title}
|
||||
visible={modalVisible}
|
||||
onOk={okHandle}
|
||||
okText={okText}
|
||||
onCancel={() => handleModalVisible()}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="品牌名称">
|
||||
{form.getFieldDecorator('name', {
|
||||
rules: [{ required: true, message: '请输入品牌名称!', min: 2 }],
|
||||
initialValue: formVals.name,
|
||||
})(<Input placeholder="请输入" />)}
|
||||
</FormItem>
|
||||
|
||||
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="描述">
|
||||
{form.getFieldDecorator('description', {
|
||||
rules: [{ required: true, message: '请输入描述!' }],
|
||||
initialValue: formVals.description,
|
||||
})(<Input.TextArea placeholder="请输入" />)}
|
||||
</FormItem>
|
||||
</Spin>
|
||||
</Modal>
|
||||
);
|
||||
});
|
||||
|
||||
// 搜索表单
|
||||
const SearchForm = Form.create()(props => {
|
||||
const {
|
||||
form,
|
||||
form: { getFieldDecorator },
|
||||
dispatch,
|
||||
searchParams,
|
||||
categoryTree,
|
||||
} = props;
|
||||
|
||||
function search() {
|
||||
dispatch({
|
||||
type: 'productBrandList/page',
|
||||
payload: {
|
||||
...PaginationHelper.defaultPayload,
|
||||
...searchParams,
|
||||
...form.getFieldsValue(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 提交搜索
|
||||
function handleSubmit(e) {
|
||||
// 阻止默认事件
|
||||
e.preventDefault();
|
||||
// 提交搜索
|
||||
search();
|
||||
}
|
||||
|
||||
// 重置搜索
|
||||
function handleReset() {
|
||||
// 重置表单
|
||||
form.resetFields();
|
||||
// 执行搜索
|
||||
search();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} layout="inline">
|
||||
<Row gutter={{ md: 8, lg: 24, xl: 48 }}>
|
||||
|
||||
<Col md={8} sm={24}>
|
||||
<FormItem label="品牌名称">
|
||||
{getFieldDecorator('name')(<Input placeholder="请输入" />)}
|
||||
</FormItem>
|
||||
</Col>
|
||||
|
||||
<Col md={8} sm={24}>
|
||||
<FormItem label="品牌描述">
|
||||
{getFieldDecorator('description')(<Input placeholder="请输入" />)}
|
||||
</FormItem>
|
||||
</Col>
|
||||
|
||||
<Col md={8} sm={24}>
|
||||
<span className={styles.submitButtons}>
|
||||
<Button type="primary" htmlType="submit">
|
||||
查询
|
||||
</Button>
|
||||
<Button style={{ marginLeft: 8 }} onClick={handleReset}>
|
||||
重置
|
||||
</Button>
|
||||
</span>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// productSpuList
|
||||
@connect(({ productBrandList}) => ({
|
||||
...productBrandList
|
||||
}))
|
||||
|
||||
@Form.create()
|
||||
class ProductBrandList extends PureComponent {
|
||||
state = {
|
||||
modalVisible: false,
|
||||
modalType: 'add', //add update
|
||||
initValues: {},
|
||||
roleAssignVisible: false,
|
||||
roleAssignRecord: {},
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
const { dispatch } = this.props;
|
||||
// 查询初始数据
|
||||
dispatch({
|
||||
type: 'productBrandList/page',
|
||||
payload: {
|
||||
...PaginationHelper.defaultPayload,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
handleModalVisible = (modalVisible, modalType, record) => {
|
||||
const { dispatch } = this.props;
|
||||
dispatch({
|
||||
type: 'productBrandList/add',
|
||||
payload: {
|
||||
modalVisible,
|
||||
modalType,
|
||||
formVals: record || {}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
render() {
|
||||
const { dispatch,
|
||||
list, listLoading, searchParams, pagination,
|
||||
categoryTree, modalType,formVals,
|
||||
modalVisible,modalLoading} = this.props;
|
||||
|
||||
// 列表属性
|
||||
const listProps = {
|
||||
dataSource: list,
|
||||
pagination,
|
||||
searchParams,
|
||||
dispatch,
|
||||
categoryTree,
|
||||
loading: listLoading,
|
||||
handleModalVisible: this.handleModalVisible, // Function
|
||||
};
|
||||
|
||||
// 搜索表单属性
|
||||
const searchFormProps = {
|
||||
dispatch,
|
||||
categoryTree,
|
||||
searchParams,
|
||||
};
|
||||
|
||||
// 添加 or 编辑表单属性
|
||||
const addOrUpdateFormProps = {
|
||||
modalVisible,
|
||||
modalType,
|
||||
formVals,
|
||||
dispatch,
|
||||
loading: modalLoading,
|
||||
categoryTree: list,
|
||||
handleModalVisible: this.handleModalVisible, // Function
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<PageHeaderWrapper>
|
||||
<Card bordered={false}>
|
||||
<div className={styles.tableList}>
|
||||
<div className={styles.tableListOperator}>
|
||||
<Button icon="plus" type="primary" onClick={() => this.handleModalVisible(true, 'add', {})} >
|
||||
新建品牌
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<SearchForm {...searchFormProps} />
|
||||
<List {...listProps} />
|
||||
</Card>
|
||||
|
||||
<AddOrUpdateForm {...addOrUpdateFormProps} />
|
||||
</PageHeaderWrapper>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ProductBrandList;
|
||||
@@ -92,8 +92,36 @@ export async function productAttrTree(params) {
|
||||
}
|
||||
|
||||
export async function productAttrValueAdd(params) {
|
||||
return request(`/product-api/admins//attr_value/add?${stringify(params)}`, {
|
||||
return request(`/product-api/admins/attr_value/add?${stringify(params)}`, {
|
||||
method: 'POST',
|
||||
body: {},
|
||||
});
|
||||
}
|
||||
|
||||
// product brand 2019-05-31
|
||||
|
||||
export async function productBrandAdd(params) {
|
||||
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: {},
|
||||
});
|
||||
}
|
||||
|
||||
export async function productBrandGet(params) {
|
||||
return request(`/product-api/admins/brand/get?${stringify(params)}`, {
|
||||
method: 'GET'
|
||||
});
|
||||
}
|
||||
|
||||
export async function productBrandPage(params) {
|
||||
return request(`/product-api/admins/brand/page?${stringify(params)}`, {
|
||||
method: 'GET'
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user