import React, { Component } from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import queryString from 'query-string';
import { Card, Form, Modal, Steps, Button, Table, Input, Icon } from 'antd';
import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
import FooterToolbar from '../../../components/FooterToolbar';
import { Codes, productType } from '../../../utils/config';
import { provCodeToName } from '../../../utils/city';
@connect(state => ({ orderDetail: state.orderDetail }))
@Form.create()
export default class SubOrderProfile extends Component {
/**
* 返回订单列表
*/
handlePageCancel = () => {
const { filters, dispatch } = this.props;
dispatch(routerRedux.push({
pathname: '/trade/order',
search: queryString.stringify(filters),
}));
}
/**
* 显示发货弹框
*/
showSendModal = () => {
this.props.dispatch({
type: 'orderDetail/showDeliveryModal',
});
}
/**
* 隐藏发货弹框
*/
hideSendModal = () => {
this.props.dispatch({
type: 'orderDetail/hideDeliveryModal',
});
this.props.form.resetFields();
}
/**
* 点击确认发货
*/
confirmSend = () => {
const { dispatch, form, orderDetail } = this.props;
const { validateFields, getFieldsValue } = form;
const { currentItem, filters } = orderDetail;
const { id } = currentItem;
validateFields((errors) => {
if (!errors) {
const { trackNo } = getFieldsValue();
dispatch({
type: 'orderDetail/orderSend',
payload: { id, trackNo },
callback: () => dispatch(routerRedux.push({
pathname: `/trade/order/sub/profile/${id}`,
search: queryString.stringify(filters),
})),
});
}
});
}
/**
* 点击确认收货
*/
confirmReceipt = () => {
Modal.confirm({
title: '是否确认收货?',
okText: '确定',
cancelText: '取消',
onOk: () => {
const { dispatch, orderDetail } = this.props;
const { currentItem, filters } = orderDetail;
const { id } = currentItem;
dispatch({
type: 'orderDetail/orderReceive',
payload: { id },
callback: () => dispatch(routerRedux.push({
pathname: `/trade/order/sub/profile/${id}`,
search: queryString.stringify(filters),
})),
});
},
});
}
/**
* 根据订单状态来生成操作按钮
*/
renderFooter = (status) => {
switch (status) {
// 待发货订单
case Codes.CODE_FORSEND:
return (
);
// 待收货订单
case Codes.CODE_SENT:
return (
);
// 已完成订单
case Codes.CODE_COMPLETE:
return (
);
// 已取消订单
case Codes.CODE_CANCEL:
return (
);
default:
return (
);
}
}
render() {
const { orderDetail, form } = this.props;
const { getFieldDecorator } = form;
const { currentItem, deliveryModalShow } = orderDetail;
const {
userCode,
provinceCode,
cityName,
zoneName,
classroomName,
orderStatus,
merchantName,
// originPrice,
// finalPrice,
// adjustPrice,
name,
type,
mobile,
address,
note,
trackNo,
goods,
} = currentItem;
// simply table columns
const simplyTableColumns = [{
title: 'field',
dataIndex: 'field',
key: 1,
width: '20%',
}, {
title: 'value',
dataIndex: 'value',
key: 2,
width: '80%',
}];
// 收货人信息 - table data
const consumerInfoTableData = [{
field: '购买终端编号',
value: userCode,
key: 1,
}, {
field: '购买终端名称',
value: `${classroomName}`,
key: 2,
}, {
field: '终端所属校区',
value: `${provCodeToName(provinceCode)}-${cityName}-${zoneName}`,
key: 3,
}, {
field: '终端所属渠道',
value: merchantName,
key: 4,
}, {
field: '收货人姓名',
value: name,
key: 5,
}, {
field: '收货人电话',
value: mobile,
key: 6,
}, {
field: '收货地址',
value: address,
key: 7,
}];
// 物流信息 - table datas
const deliveryTableData = [{
field: '物流单号',
value: trackNo,
key: 1,
}];
// 商品清单
const goodsTableColumns = [{
title: '商品编号',
dataIndex: 'code',
key: 1,
width: '25%',
}, {
title: '商品名称',
dataIndex: 'name',
key: 2,
width: '25%',
}, {
title: '商品类型',
dataIndex: 'type',
render: text => productType[text],
key: 3,
width: '15%',
}, {
title: '商品售价(元)',
dataIndex: 'merchantPrice',
key: 4,
width: '25%',
}, {
title: '商品数量',
dataIndex: 'quantity',
key: 5,
width: '10%',
}];
// 结算信息 - table data
/*
const strs = [];
(goods || []).forEach(item => strs.push(`${item.merchantPrice}(元) * ${item.quantity}`));
const accountTableDatas = [{
field: '商品总价',
value: `${strs.join(' + ')} = ${originPrice}(元)`,
key: 1,
}, {
field: '支付金额',
value:
{`总价:${originPrice}(元) - 商品优惠:${adjustPrice}(元) = 订单总金额:`}
{`${finalPrice}(元)`}
,
key: 2,
}];
*/
const entityStepMap = {
[Codes.CODE_UNPAID]: 0,
[Codes.CODE_PAID]: 1,
[Codes.CODE_FORSEND]: 1,
[Codes.CODE_SENT]: 2,
[Codes.CODE_RECEIVED]: 3,
[Codes.CODE_CANCEL]: 4,
[Codes.CODE_COMPLETE]: 4,
};
const virtualStepMap = {
[Codes.CODE_UNPAID]: 0,
[Codes.CODE_PAID]: 1,
[Codes.CODE_FORSEND]: 1,
[Codes.CODE_SENT]: 1,
[Codes.CODE_RECEIVED]: 1,
[Codes.CODE_CANCEL]: 4,
[Codes.CODE_COMPLETE]: 4,
};
const formItemLayout = {
labelCol: { span: 7 },
wrapperCol: { span: 15 },
};
return (
{type === Codes.CODE_ENTITY ?
(
} />
} />
} />
} />
} />
)
:
(
} />
} />
} />
)
}