|
@@ -0,0 +1,220 @@
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
+import PropTypes from 'prop-types';
|
|
|
+import moment from 'moment';
|
|
|
+import classnames from 'classnames';
|
|
|
+import queryString from 'query-string';
|
|
|
+import { Modal, DatePicker, Table, Menu, Icon, Badge } from 'antd';
|
|
|
+import AnimTableBody from '../../components/Animation/AnimTableBody';
|
|
|
+import DropOption from '../../components/DropOption';
|
|
|
+import styles from './table.less';
|
|
|
+import { orderStatuses, Codes } from '../../utils/config';
|
|
|
+
|
|
|
+const { RangePicker } = DatePicker;
|
|
|
+const confirm = Modal.confirm;
|
|
|
+
|
|
|
+export default class TableList extends PureComponent {
|
|
|
+ static propTypes = {
|
|
|
+ location: PropTypes.object,
|
|
|
+ onChange: PropTypes.func.isRequired,
|
|
|
+ onDeleteItem: PropTypes.func.isRequired,
|
|
|
+ onEditItem: PropTypes.func.isRequired,
|
|
|
+ };
|
|
|
+
|
|
|
+ state = {
|
|
|
+ filtered: false, //是否处于过滤状态
|
|
|
+ timeBegin: null, //起始时间 - 默认当前时间戳
|
|
|
+ timeEnd: null, //结束时间 - 默认时间戳
|
|
|
+ }
|
|
|
+
|
|
|
+ componentWillReceiveProps(nextProps) {
|
|
|
+ // 如果父组件传进的属性中包含timeBegin和timeEnd并进行合法性校验,通过则更新state
|
|
|
+ const { timeBegin, timeEnd } = nextProps;
|
|
|
+ const nextTimeBegin = Number(timeBegin);
|
|
|
+ const nextTimeEnd = Number(timeEnd);
|
|
|
+ if (nextTimeBegin && nextTimeEnd && moment(nextTimeBegin).isValid() && moment(nextTimeEnd).isValid()) {
|
|
|
+ this.setState({
|
|
|
+ timeBegin: moment(nextTimeBegin),
|
|
|
+ timeEnd: moment(nextTimeEnd),
|
|
|
+ filtered: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择了筛选的时间段,点击确定后触发
|
|
|
+ handleRangePickerOnOk = (value) => {
|
|
|
+ const timeBegin = value[0];
|
|
|
+ const timeEnd = value[1];
|
|
|
+ this.setState({ timeBegin, timeEnd, filtered: true });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 点击清除选中的时间段
|
|
|
+ handleRangePickerOnChange = (value) => {
|
|
|
+ if (value && !value.length) {
|
|
|
+ this.setState({
|
|
|
+ filtered: false,
|
|
|
+ timeBegin: null,
|
|
|
+ timeEnd: null,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setState({
|
|
|
+ filtered: true,
|
|
|
+ timeBegin: value[0],
|
|
|
+ timeEnd: value[1],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 点击空白区域,隐藏RangePicker,会触发一次查询
|
|
|
+ handleRangePickerFilter = (visible) => {
|
|
|
+ if (!visible) {
|
|
|
+ const { pagination, onChange } = this.props;
|
|
|
+ // 这里构造成数组类型是为了和table自带的过滤参数类型一致
|
|
|
+ const data = { timeBegin: [], timeEnd: [] };
|
|
|
+ if (this.state.timeBegin && this.state.timeEnd) {
|
|
|
+ data.timeBegin = [this.state.timeBegin.format('X')];
|
|
|
+ data.timeEnd = [this.state.timeEnd.format('X')];
|
|
|
+ }
|
|
|
+ onChange(pagination, data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ handleMenuClick = (record, e) => {
|
|
|
+ const { onDeleteItem, onViewItem, onEditItem, onRecoverItem } = this.props;
|
|
|
+ if (e.key === '1') {
|
|
|
+ onViewItem(record);
|
|
|
+ } else if (e.key === '2') {
|
|
|
+ console.log('enter into edit page...');
|
|
|
+ }else if (e.key === '3') {
|
|
|
+ confirm({
|
|
|
+ title: '你确定要作废该订单?',
|
|
|
+ onOk () {
|
|
|
+ console.log('deleting...');
|
|
|
+ // onDeleteItem(record.id)
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else if (e.key === '4') {
|
|
|
+ confirm({
|
|
|
+ title: '你确定要恢复该订单?',
|
|
|
+ onOk () {
|
|
|
+ console.log('recovering...');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据订单状态确定下拉菜单的选项
|
|
|
+ renderOperationDropMenu = (record) => {
|
|
|
+ switch (Number(record.status)) {
|
|
|
+ case Codes.CODE_PAID:
|
|
|
+ return [{key: '1', name: '查看'}];
|
|
|
+ break;
|
|
|
+ case Codes.CODE_UNPAID:
|
|
|
+ return [{key: '1', name: '查看'}, {key: '2', name: '修改'}, {key: '3', name: '作废'}];
|
|
|
+ break;
|
|
|
+ case Codes.CODE_CANCEL:
|
|
|
+ return [{key: '1', name: '查看'}, {key: '4', name: '恢复'}];
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { curStatus, onDeleteItem, onRecoverItem, onEditItem, location, pagination, ...tableProps } = this.props;
|
|
|
+ const { timeBegin, timeEnd, filtered } = this.state;
|
|
|
+
|
|
|
+ const columns = [{
|
|
|
+ title: '订单编号',
|
|
|
+ dataIndex: 'code',
|
|
|
+ key: 'code',
|
|
|
+ },{
|
|
|
+ title: '终端编号',
|
|
|
+ dataIndex: 'userCode',
|
|
|
+ key: 'userCode',
|
|
|
+ },{
|
|
|
+ title: '校区',
|
|
|
+ dataIndex: 'campusName',
|
|
|
+ key: 'campusName',
|
|
|
+ render: (text, record) => (
|
|
|
+ <span>{`${record.provinceCode}-${record.cityName}-${record.zoneName}`}</span>
|
|
|
+ ),
|
|
|
+ },{
|
|
|
+ title: '领教定价',
|
|
|
+ dataIndex: 'lingjiaoPrice',
|
|
|
+ key: 'lingjiaoPrice',
|
|
|
+ },{
|
|
|
+ title: '渠道定价',
|
|
|
+ dataIndex: 'merchantPrice',
|
|
|
+ key: 'merchantPrice',
|
|
|
+ },{
|
|
|
+ title: '实际售价',
|
|
|
+ dataIndex: 'finalPrice',
|
|
|
+ key: 'finalPrice',
|
|
|
+ },{
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ key: 'status',
|
|
|
+ render: (text, record) => {
|
|
|
+ const statusMap = {[Codes.CODE_PAID]: 'success', [Codes.CODE_UNPAID]: 'processing', [Codes.CODE_CANCEL]: 'error'};
|
|
|
+ return (<Badge status={statusMap[record.status]} text={orderStatuses[record.status]} />);
|
|
|
+ },
|
|
|
+ filters: Object.keys(orderStatuses).map(key => ({ text: orderStatuses[key], value: key })),
|
|
|
+ filterMultiple: false,
|
|
|
+ filteredValue: [curStatus],
|
|
|
+ },{
|
|
|
+ title: '下单时间',
|
|
|
+ dataIndex: 'gmtCreated',
|
|
|
+ key: 'gmtCreated',
|
|
|
+ render: (text, record) => (
|
|
|
+ <div>{moment(text).format('YYYY-MM-DD HH:mm:ss')}</div>
|
|
|
+ ),
|
|
|
+ filterIcon: <Icon type="clock-circle-o" style={{ color: filtered ? '#108ee9' : '#aaa' }} />,
|
|
|
+ filterDropdown: (
|
|
|
+ <div className="custom-filter-dropdown">
|
|
|
+ <RangePicker
|
|
|
+ value={filtered ? [timeBegin, timeEnd] : []}
|
|
|
+ showTime={{ format: 'HH:mm:ss' }}
|
|
|
+ format="YYYY-MM-DD HH:mm:ss"
|
|
|
+ placeholder={["起始时间", "截止时间"]}
|
|
|
+ onChange={this.handleRangePickerOnChange}
|
|
|
+ onOk={this.handleRangePickerOnOk}
|
|
|
+ getCalendarContainer={() => document.querySelector('.custom-filter-dropdown')}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ ),
|
|
|
+ onFilterDropdownVisibleChange: this.handleRangePickerFilter,
|
|
|
+ },{
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'operation',
|
|
|
+ key: 'operation',
|
|
|
+ render: (text, record) => (
|
|
|
+ <DropOption onMenuClick={e => this.handleMenuClick(record, e)} menuOptions={this.renderOperationDropMenu(record)} />
|
|
|
+ ),
|
|
|
+ }];
|
|
|
+
|
|
|
+ // 数据table列表表头的筛选按钮点击重置后status值为空,此时删除该参数
|
|
|
+ columns.map(item => {
|
|
|
+ item.dataIndex === 'status' && !curStatus ? delete item.filteredValue : null;
|
|
|
+ });
|
|
|
+
|
|
|
+ tableProps.pagination = !!pagination && { ...pagination, showSizeChanger: true, showQuickJumper: true, showTotal: total => `共 ${total} 条`};
|
|
|
+ const getBodyWrapperProps = {
|
|
|
+ page: location.query.page,
|
|
|
+ current: tableProps.pagination.current,
|
|
|
+ };
|
|
|
+ const getBodyWrapper = (body) => (<AnimTableBody {...getBodyWrapperProps} body={body} />);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Table
|
|
|
+ simple
|
|
|
+ bordered
|
|
|
+ { ...tableProps }
|
|
|
+ columns={columns}
|
|
|
+ className={classnames({ [styles.table]: true, [styles.motion]: true })}
|
|
|
+ rowKey={record => record.id}
|
|
|
+ scroll={{ x: 1300 }}
|
|
|
+ getBodyWrapper={getBodyWrapper}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|