import React from 'react'; import './index.less'; import { Form, Row, Col } from 'antd'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import { getMap, formatDate, formatMoney } from '@src/services/Tools'; import { RecordBuySource, ServiceKey, ServiceParamMap } from '../../../../Constant'; import { User } from '../../../stores/user'; const RecordBuySourceMap = getMap(RecordBuySource, 'value', 'label'); const ServiceKeyMap = getMap(ServiceKey, 'value', 'label'); const ServiceParamRelation = getMap(Object.keys(ServiceParamMap).map(key => { return { map: getMap(ServiceParamMap[key], 'value', 'label'), key }; }), 'key', 'map'); export default class extends Page { initData() { const { id } = this.params; let handler; if (id) { handler = User.getOrder({ id }); } else { handler = Promise.resolve({}); } handler .then(result => { const courseMap = getMap(result.courses, 'id'); const dataMap = getMap(result.datas, 'id'); const packageMap = getMap(result.packages, 'id'); this.setState({ courseMap, dataMap, packageMap, data: result }); }); } renderProduct() { const { data = {}, courseMap, dataMap, packageMap } = this.state; const { checkouts = [] } = data; return

包含商品

{(checkouts || []).map(row => { // 赠送过滤 if ((row.source || '').indexOf('gift') >= 0) return null; let title = ''; switch (row.productType) { case 'course': ({ title } = (courseMap[row.productId] || {})); break; case 'data': ({ title } = (dataMap[row.productId] || {})); break; case 'package': ({ title } = (packageMap[row.productId] || {})); break; case 'service': title = `服务:${ServiceKeyMap[row.service]}${row.param ? (ServiceParamRelation[row.service] || {})[row.param] || '' : ''}`; break; default: break; } return {title}{row.number > 1 ? `X ${row.number}` : ''} {`${formatMoney(row.money)}${row.money !== row.originMoney ? `(${formatMoney(row.originMoney)})` : ''}`} ; })}
; } renderMoney() { const { data = {} } = this.state; return

订单金额

{formatMoney(data.originMoney)} {(data.promote || []).map(info => { return -{formatMoney(info.originMoney - info.money)} {info.message} ; })} {formatMoney(data.money)}
; } renderGift() { const { data = {} } = this.state; return

赠送服务

{(data.gift || []).map(row => { return {row.message} ; })}
; } renderTime() { const { data = {} } = this.state; return

订单时间

{data.createTime ? formatDate(data.createTime, 'YYYY-MM-DD HH:mm:ss') : ''} {data.payTime ? formatDate(data.payTime, 'YYYY-MM-DD HH:mm:ss') : ''} {RecordBuySourceMap[data.payMethod] || ''} {data.transactionNo}
; } renderView() { return
{this.renderProduct()} {this.renderMoney()} {this.renderGift()} {this.renderTime()}
; } }