page.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import React from 'react';
  2. import './index.less';
  3. import { Form, Row, Col } from 'antd';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import { getMap, formatDate, formatMoney } from '@src/services/Tools';
  7. import { RecordBuySource, ServiceKey, ServiceParamMap } from '../../../../Constant';
  8. import { User } from '../../../stores/user';
  9. const RecordBuySourceMap = getMap(RecordBuySource, 'value', 'label');
  10. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  11. const ServiceParamRelation = getMap(Object.keys(ServiceParamMap).map(key => {
  12. return { map: getMap(ServiceParamMap[key], 'value', 'label'), key };
  13. }), 'key', 'map');
  14. export default class extends Page {
  15. initData() {
  16. const { id } = this.params;
  17. let handler;
  18. if (id) {
  19. handler = User.getOrder({ id });
  20. } else {
  21. handler = Promise.resolve({});
  22. }
  23. handler
  24. .then(result => {
  25. const courseMap = getMap(result.courses, 'id');
  26. const dataMap = getMap(result.datas, 'id');
  27. const packageMap = getMap(result.packages, 'id');
  28. this.setState({ courseMap, dataMap, packageMap, data: result });
  29. });
  30. }
  31. renderProduct() {
  32. const { data = {}, courseMap, dataMap, packageMap } = this.state;
  33. const { checkouts = [] } = data;
  34. return <Block>
  35. <h1>包含商品</h1>
  36. <Form>
  37. {(checkouts || []).map(row => {
  38. // 赠送过滤
  39. if ((row.source || '').indexOf('gift') >= 0) return null;
  40. let title = '';
  41. switch (row.productType) {
  42. case 'course':
  43. ({ title } = (courseMap[row.productId] || {}));
  44. break;
  45. case 'data':
  46. ({ title } = (dataMap[row.productId] || {}));
  47. break;
  48. case 'package':
  49. ({ title } = (packageMap[row.productId] || {}));
  50. break;
  51. case 'service':
  52. title = `服务:${ServiceKeyMap[row.service]}${row.param ? (ServiceParamRelation[row.service] || {})[row.param] || '' : ''}`;
  53. break;
  54. default:
  55. break;
  56. }
  57. return <Row>
  58. <Col span={10} offset={2}>
  59. {title}{row.number > 1 ? `X ${row.number}` : ''}
  60. </Col>
  61. <Col span={12}>
  62. {`${formatMoney(row.money)}${row.money !== row.originMoney ? `(${formatMoney(row.originMoney)})` : ''}`}
  63. </Col>
  64. </Row>;
  65. })}
  66. </Form>
  67. </Block>;
  68. }
  69. renderMoney() {
  70. const { data = {} } = this.state;
  71. return <Block>
  72. <h1>订单金额</h1>
  73. <Form>
  74. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='原价'>
  75. {formatMoney(data.originMoney)}
  76. </Form.Item>
  77. {(data.promote || []).map(info => {
  78. return <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='优惠金额'>
  79. <Row>
  80. <Col span={12} >
  81. -{formatMoney(info.originMoney - info.money)}
  82. </Col>
  83. <Col span={12}>
  84. {info.message}
  85. </Col>
  86. </Row>
  87. </Form.Item>;
  88. })}
  89. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='总支付'>
  90. {formatMoney(data.money)}
  91. </Form.Item>
  92. </Form>
  93. </Block>;
  94. }
  95. renderGift() {
  96. const { data = {} } = this.state;
  97. return <Block>
  98. <h1>赠送服务</h1>
  99. <Form>
  100. {(data.gift || []).map(row => {
  101. return <Form.Item >
  102. {row.message}
  103. </Form.Item>;
  104. })}
  105. </Form>
  106. </Block>;
  107. }
  108. renderTime() {
  109. const { data = {} } = this.state;
  110. return <Block>
  111. <h1>订单时间</h1>
  112. <Form>
  113. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='提交时间'>
  114. {data.createTime ? formatDate(data.createTime, 'YYYY-MM-DD HH:mm:ss') : ''}
  115. </Form.Item>
  116. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='支付时间'>
  117. {data.payTime ? formatDate(data.payTime, 'YYYY-MM-DD HH:mm:ss') : ''}
  118. </Form.Item>
  119. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='支付方式'>
  120. {RecordBuySourceMap[data.payMethod] || ''}
  121. </Form.Item>
  122. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='付款流水号'>
  123. {data.transactionNo}
  124. </Form.Item>
  125. </Form>
  126. </Block>;
  127. }
  128. renderView() {
  129. return <div>
  130. {this.renderProduct()}
  131. {this.renderMoney()}
  132. {this.renderGift()}
  133. {this.renderTime()}
  134. </div>;
  135. }
  136. }