添加 orderList 订单页面

pull/1/head
sin 2019-03-28 00:43:50 +08:00
parent c23eb737f0
commit e2a19a1d9d
3 changed files with 192 additions and 138 deletions

View File

@ -5,17 +5,32 @@ export default {
namespace: 'orderList', namespace: 'orderList',
state: { state: {
list: [], list: {
pagination: {
current: 0,
pageSize: 10,
total: 0,
},
dataSource: [],
},
}, },
effects: { effects: {
*queryPage({ payload }, { call, put }) { *queryPage({ payload }, { call, put }) {
const response = yield call(orderPage, payload); const response = yield call(orderPage, payload);
message.info('查询成功!'); message.info('查询成功!', response);
const { total, orders } = response.data;
yield put({ yield put({
type: 'queryPageSuccess', type: 'queryPageSuccess',
payload: { payload: {
list: response.data, list: {
dataSource: orders,
pagination: {
total,
current: payload.pageNo,
pageSize: payload.pageSize,
},
},
}, },
}); });
}, },
@ -34,9 +49,10 @@ export default {
reducers: { reducers: {
queryPageSuccess(state, { payload }) { queryPageSuccess(state, { payload }) {
const { list } = payload;
return { return {
...state, ...state,
...payload, list,
}; };
}, },
}, },

View File

@ -1,128 +1,113 @@
import React, { PureComponent } from 'react'; import React, { Fragment, PureComponent } from 'react';
import moment from 'moment'; import moment from 'moment';
import { connect } from 'dva'; import { connect } from 'dva';
import { import { Button, Card, Col, Divider, Form, Input, Row, Table, DatePicker } from 'antd';
Button,
Card,
Col,
Dropdown,
Form,
Icon,
Input,
List,
Menu,
Modal,
Row,
Select,
} from 'antd';
import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import DictionaryText from '@/components/Dictionary/DictionaryText'; import DictionaryText from '@/components/Dictionary/DictionaryText';
import DictionarySelect from '@/components/Dictionary/DictionarySelect';
import dictionary from '@/utils/dictionary'; import dictionary from '@/utils/dictionary';
import styles from './OrderList.less'; import styles from './OrderList.less';
const { RangePicker } = DatePicker;
const FormItem = Form.Item; const FormItem = Form.Item;
const SelectOption = Select.Option;
const OrderList = props => { const OrderList = props => {
const { list, loading } = props; const { list, dispatch, loading, handleModalVisible } = props;
const paginationProps = { // 翻页
showSizeChanger: true, const onPageChange = page => {
showQuickJumper: true, const { searchParams } = props;
pageSize: 5,
total: 50,
};
const deleteItem = id => {
const { dispatch } = props;
dispatch({ dispatch({
type: 'list/submit', type: 'adminList/query',
payload: { id }, payload: {
pageNo: page.current,
pageSize: page.pageSize,
...searchParams,
},
}); });
}; };
const handleEditor = currentItem => { const columns = [
const { handleEditorClick } = props; {
if (handleEditorClick) { title: '订单id',
handleEditorClick(currentItem); dataIndex: 'id',
} },
{
title: '用户',
dataIndex: 'userId',
},
{
title: '订单号',
dataIndex: 'orderNo',
},
{
title: '金额',
dataIndex: 'price',
render(val) {
return <span>{val} </span>;
},
},
{
title: '状态',
dataIndex: 'status',
render(val) {
return <DictionaryText dicKey={dictionary.ORDER_STATUS} dicValue={val} />;
},
},
{
title: '付款时间',
dataIndex: 'paymentTime',
render: val => (!val ? '' : <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>),
},
{
title: '发货时间',
dataIndex: 'deliveryTime',
render: val => (!val ? '' : <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>),
},
{
title: '收货时间',
dataIndex: 'receiverTime',
render: val => (!val ? '' : <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>),
},
{
title: '成交时间',
dataIndex: 'closingTime',
render: val => (!val ? '' : <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>),
},
{
title: '创建时间',
dataIndex: 'createTime',
render: val => (!val ? '' : <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>),
},
{
title: '操作',
width: 100,
render: (text, record) => {
return (
<Fragment>
<a onClick={() => handleModalVisible(true, 'update', record)}>编辑</a>
<Divider type="vertical" />
</Fragment>
);
},
},
];
const tableScroll = {
x: 1400,
}; };
const handleMoreMenu = (key, currentItem) => {
if (key === 'edit') {
handleEditor(currentItem);
} else if (key === 'delete') {
Modal.confirm({
title: '删除任务',
content: '确定删除该任务吗?',
okText: '确认',
cancelText: '取消',
onOk: () => deleteItem(currentItem.id),
});
}
};
const ListContent = ({ data }) => (
<div className={styles.listContent}>
<div className={styles.listContentItem}>
<span>金额: {data.price / 100} </span>
<p>编号: {data.orderNo}</p>
</div>
<div className={styles.listContentItem}>
<span>
付款时间: {data.paymentTime ? moment(data.paymentTime).format('YYYY-MM-DD HH:mm') : ''}
</span>
<p>创建时间{moment(data.createTime).format('YYYY-MM-DD HH:mm')}</p>
</div>
<div className={styles.listContentItem}>
<span>
订单状态: <DictionaryText dicKey={dictionary.ORDER_STATUS} dicValue={data.status} />
</span>
</div>
</div>
);
const MoreBtn = () => (
<Dropdown
overlay={
<Menu onClick={({ key }) => handleMoreMenu(key, props.current)}>
<Menu.Item key="edit">编辑</Menu.Item>
<Menu.Item key="delete">删除</Menu.Item>
</Menu>
}
>
<a>
更多 <Icon type="down" />
</a>
</Dropdown>
);
return ( return (
<List <Table
size="large"
rowKey="id" rowKey="id"
columns={columns}
dataSource={list.dataSource}
loading={loading} loading={loading}
pagination={paginationProps} pagination={list.pagination}
dataSource={list} onChange={onPageChange}
renderItem={item => ( scroll={tableScroll}
<List.Item
actions={[
<a
onClick={e => {
e.preventDefault();
handleEditor(item);
}}
>
编辑
</a>,
<MoreBtn current={item} />,
]}
>
<ListContent data={item} />
</List.Item>
)}
/> />
); );
}; };
@ -131,30 +116,80 @@ const OrderList = props => {
const SearchForm = props => { const SearchForm = props => {
const { const {
form: { getFieldDecorator }, form: { getFieldDecorator },
form,
handleSearch,
} = props; } = props;
const handleFormReset = () => {}; const handleFormReset = () => {};
const handleSearch = () => {}; const onSubmit = e => {
e.preventDefault();
form.validateFields((err, fields) => {
const buildTime = (fieldValue, key) => {
const res = {};
if (fieldValue) {
const keySuffix = key.substring(0, 1).toUpperCase() + key.substring(1);
// res[`start${keySuffix}`] = fieldValue[0].valueOf();
res[`start${keySuffix}`] = fieldValue[0].format('YYYY-MM-DD HH:mm:ss');
// res[`end${keySuffix}`] = fieldValue[1].valueOf();
res[`end${keySuffix}`] = fieldValue[1].format('YYYY-MM-DD HH:mm:ss');
}
return res;
};
const timeFields = ['createTime', 'closingTime'];
const buildSearchParams = fields2 => {
let res = {};
Object.keys(fields).map(objectKey => {
const fieldValue = fields2[objectKey];
if (timeFields.indexOf(objectKey) !== -1) {
// 处理时间
res = {
...res,
...buildTime(fieldValue, objectKey),
};
} else if (fieldValue !== undefined) {
res[objectKey] = fieldValue;
}
return true;
});
return res;
};
const searchParams = buildSearchParams(fields);
if (handleSearch) {
handleSearch(searchParams);
}
});
};
return ( return (
<Form onSubmit={handleSearch} layout="inline"> <Form onSubmit={onSubmit} layout="inline">
<Row gutter={{ md: 8, lg: 24, xl: 48 }}> <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
<Col md={8} sm={24}> <Col md={8} sm={24}>
<FormItem label="规则名称"> <FormItem label="订单id">
{getFieldDecorator('name')(<Input placeholder="请输入" />)} {getFieldDecorator('id')(<Input placeholder="请输入订单id" />)}
</FormItem> </FormItem>
</Col> </Col>
<Col md={8} sm={24}> <Col md={8} sm={24}>
<FormItem label="使用状态"> <FormItem label="订单号">
{getFieldDecorator('status')( {getFieldDecorator('orderNo')(<Input placeholder="请输入订单号" />)}
<Select placeholder="请选择" style={{ width: '100%' }}>
<SelectOption value="0">关闭</SelectOption>
<SelectOption value="1">运行中</SelectOption>
</Select>
)}
</FormItem> </FormItem>
</Col> </Col>
<Col md={8} sm={24}>
<FormItem label="状态">
{getFieldDecorator('status', {})(<DictionarySelect dicKey={dictionary.ORDER_STATUS} />)}
</FormItem>
</Col>
</Row>
<Row gutter={{ md: 8, lg: 24, xl: 48 }}>
<Col md={8} sm={24}>
<FormItem label="创建时间">{getFieldDecorator('createTime')(<RangePicker />)}</FormItem>
</Col>
<Col md={8} sm={24}>
<FormItem label="成交时间">{getFieldDecorator('closingTime')(<RangePicker />)}</FormItem>
</Col>
<Col md={8} sm={24}> <Col md={8} sm={24}>
<span className={styles.submitButtons}> <span className={styles.submitButtons}>
<Button type="primary" htmlType="submit"> <Button type="primary" htmlType="submit">
@ -171,43 +206,46 @@ const SearchForm = props => {
}; };
@connect(({ orderList, loading }) => ({ @connect(({ orderList, loading }) => ({
list: orderList.list,
orderList, orderList,
list: orderList.list,
loading: loading.models.orderList, loading: loading.models.orderList,
})) }))
@Form.create() @Form.create()
class BasicList extends PureComponent { class BasicList extends PureComponent {
state = {
current: {},
};
componentDidMount() { componentDidMount() {
const {
list: { pagination },
} = this.props;
this.queryList({
pageNo: pagination.current,
pageSize: pagination.pageSize,
});
}
queryList = params => {
const { dispatch } = this.props; const { dispatch } = this.props;
dispatch({ dispatch({
type: 'orderList/queryPage', type: 'orderList/queryPage',
payload: { payload: {
pageNo: 0, ...params,
pageSize: 10,
}, },
}); });
} };
handleEditorClick = () => { handleEditorClick = () => {
console.info('edit'); console.info('edit');
}; };
handleSubmit = e => { handleSearch = fields => {
e.preventDefault(); const {
const { dispatch, form } = this.props; list: { pagination },
const { current } = this.state; } = this.props;
const id = current ? current.id : '';
form.validateFields((err, fieldsValue) => { this.queryList({
if (err) return; ...fields,
dispatch({ pageNo: pagination.current,
type: 'list/submit', pageSize: pagination.pageSize,
payload: { id, ...fieldsValue },
});
}); });
}; };
@ -223,7 +261,7 @@ class BasicList extends PureComponent {
bodyStyle={{ padding: '0 32px 40px 32px' }} bodyStyle={{ padding: '0 32px 40px 32px' }}
> >
<div className={styles.tableListForm}> <div className={styles.tableListForm}>
<SearchForm {...this.props} /> <SearchForm {...this.props} handleSearch={this.handleSearch} />
</div> </div>
<OrderList {...this.props} handleEditorClick={this.handleEditorClick} /> <OrderList {...this.props} handleEditorClick={this.handleEditorClick} />
</Card> </Card>

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 KiB