page.js 4.6 KB

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