page.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. let title = '';
  42. switch (row.productType) {
  43. case 'course':
  44. ({ title } = (courseMap[row.productId] || {}));
  45. break;
  46. case 'data':
  47. ({ title } = (dataMap[row.productId] || {}));
  48. break;
  49. case 'package':
  50. ({ title } = (packageMap[row.productId] || {}));
  51. break;
  52. case 'service':
  53. title = `服务:${ServiceKeyMap[row.service]}${row.param ? (ServiceParamRelation[row.service] || {})[row.param] || '' : ''}`;
  54. break;
  55. default:
  56. break;
  57. }
  58. return <Row>
  59. <Col span={10} offset={2}>
  60. {title}{row.number > 1 ? `X ${row.number}` : ''}
  61. </Col>
  62. <Col span={12}>
  63. {`${formatMoney(row.money)}${row.money !== row.originMoney ? `(${formatMoney(row.originMoney)})` : ''}`}
  64. </Col>
  65. </Row>;
  66. })}
  67. </Form>
  68. </Block>;
  69. }
  70. renderMoney() {
  71. const { data = {} } = this.state;
  72. return <Block>
  73. <h1>订单金额</h1>
  74. <Form>
  75. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='原价'>
  76. {formatMoney(data.originMoney)}
  77. </Form.Item>
  78. {Object.keys(data.promote || {}).map(key => {
  79. const info = data.promote[key];
  80. return <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='优惠金额'>
  81. <Row>
  82. <Col span={12} >
  83. -{formatMoney(info.originMoney - info.money)}
  84. </Col>
  85. <Col span={12}>
  86. {info.message || promoteInfoMap[`${key}-${info.key}`]}
  87. </Col>
  88. </Row>
  89. </Form.Item>;
  90. })}
  91. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='总支付'>
  92. {formatMoney(data.money)}
  93. </Form.Item>
  94. </Form>
  95. </Block>;
  96. }
  97. renderGift() {
  98. const { data = {} } = this.state;
  99. return <Block>
  100. <h1>赠送服务</h1>
  101. <Form>
  102. {(data.gift || []).map(row => {
  103. return <Form.Item >
  104. {row.message}
  105. </Form.Item>;
  106. })}
  107. </Form>
  108. </Block>;
  109. }
  110. renderTime() {
  111. const { data = {} } = this.state;
  112. return <Block>
  113. <h1>订单时间</h1>
  114. <Form>
  115. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='提交时间'>
  116. {data.createTime ? formatDate(data.createTime) : ''}
  117. </Form.Item>
  118. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='支付时间'>
  119. {data.payTime ? formatDate(data.payTime) : ''}
  120. </Form.Item>
  121. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='支付方式'>
  122. {RecordBuySourceMap[data.payMethod] || ''}
  123. </Form.Item>
  124. <Form.Item labelCol={{ span: 3 }} wrapperCol={{ span: 16 }} label='付款流水号'>
  125. {data.transactionNo}
  126. </Form.Item>
  127. </Form>
  128. </Block>;
  129. }
  130. renderView() {
  131. return <div>
  132. {this.renderProduct()}
  133. {this.renderMoney()}
  134. {this.renderGift()}
  135. {this.renderTime()}
  136. </div>;
  137. }
  138. }