page.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd';
  4. import Assets from '@src/components/Assets';
  5. import Page from '@src/containers/Page';
  6. import Modal from '../../../components/Modal';
  7. import UserTable from '../../../components/UserTable';
  8. import IconButton from '../../../components/IconButton';
  9. import { Order } from '../../../stores/order';
  10. import { User } from '../../../stores/user';
  11. import { formatDate, formatMoney } from '../../../../../src/services/Tools';
  12. // import { ServiceKey, ServiceParamMap, OrderInfoMap } from '../../../../Constant';
  13. export default class extends Page {
  14. initData() {
  15. const { id } = this.params;
  16. Order.getOrder(id)
  17. .then(result => {
  18. User.formatOrder(result);
  19. this.setState({ order: result, list: result.checkouts });
  20. });
  21. }
  22. renderView() {
  23. const { order = {}, list = [] } = this.state;
  24. return (
  25. <div style={{ paddingTop: 40 }}>
  26. <div className="content">
  27. <div className="t-1 m-b-2 f-w-b t-s-24">订单详情</div>
  28. </div>
  29. <div className="content">
  30. <div className="m-b-1 t-8 m-b-2">订单编号 {order.id}</div>
  31. </div>
  32. <div className="list content">
  33. {(list || []).map(item => {
  34. if (item.source === 'gift_course') return null;
  35. return <OrderItem data={item} />;
  36. })}
  37. </div>
  38. <div className="gift-list content">
  39. {(order.gift || []).map(item => {
  40. return <GiftItem data={item} />;
  41. })}
  42. </div>
  43. <div className="content block">
  44. <div className="t-1 t-s-18 f-w-b title">订单金额</div>
  45. <div className="t-2 t-s-12 item">
  46. <span>应付金额</span>
  47. <span>¥ {formatMoney(order.originMoney)}</span>
  48. </div>
  49. {order.originMoney - order.money > 0 && <div className="t-2 t-s-12 item">
  50. <span>优惠金额</span>
  51. <span>¥ {formatMoney(order.originMoney - order.money)}</span>
  52. </div>}
  53. <div className="t-2 t-s-12 item">
  54. <span>实付金额</span>
  55. <span>¥ {formatMoney(order.money)}</span>
  56. </div>
  57. </div>
  58. <div className="content block">
  59. <div className="t-1 t-s-18 f-w-b title">支付信息</div>
  60. <div className="t-2 t-s-12 item">
  61. <span>支付方式</span>
  62. <span>
  63. {order.payMethod ? <Assets name={order.payMethod === 'wechat' ? 'wechatpay' : order.payMethod} /> : '待确定'}
  64. {/* alipay wechatpay bank */}
  65. </span>
  66. </div>
  67. <div className="t-2 t-s-12 item">
  68. <span>付款时间</span>
  69. <span>{order.payTime ? formatDate(order.payTime, 'YYYY-MM-DD HH:mm:ss') : '待确定'}</span>
  70. </div>
  71. </div>
  72. </div>
  73. );
  74. }
  75. }
  76. class GiftItem extends Component {
  77. render() {
  78. const { data } = this.props;
  79. let message = '';
  80. if (data.money) {
  81. message = `实付金额满${data.money}元赠送`;
  82. } else if (data.from === 'vsNumber') {
  83. message = `1VS1课程满${data.number}节赠送`;
  84. }
  85. return (
  86. <div className="gift-item">
  87. <div className="d-i-b t-2 t-s-12 m-l-2">
  88. <Assets className="m-r-5" width={20} height={20} name="gift2" />
  89. {data.message}
  90. </div>
  91. <div style={{ marginRight: 80 }} className="d-i-b t-2 t-s-12 f-r">
  92. {message}
  93. </div>
  94. </div>
  95. );
  96. }
  97. }
  98. class OrderItem extends Component {
  99. constructor(props) {
  100. super(props);
  101. this.state = { open: false, showList: false };
  102. this.columns = [{
  103. key: 'label',
  104. title: '服务',
  105. }, {
  106. key: 'expireDays',
  107. title: '开通有效期',
  108. render: (text, checkout) => {
  109. return checkout.expireDays ? `${checkout.expireDays}天` : '付款后立即生效';
  110. },
  111. }, {
  112. key: 'useExpireDays',
  113. title: '使用有效期',
  114. render: (text, checkout) => {
  115. return checkout.useExpireDays ? `${checkout.useExpireDays}天` : '永久';
  116. },
  117. }];
  118. }
  119. render() {
  120. const { data = {} } = this.props;
  121. const { showList } = this.state;
  122. return (
  123. <div className="order-item">
  124. {this.renderInfo()}
  125. {(data.children || data.gift) && this.renderDetail()}
  126. <Modal
  127. show={showList}
  128. maskClosable
  129. close
  130. body={false}
  131. width={630}
  132. onClose={() => this.setState({ showList: false })}
  133. className="order-modal"
  134. >
  135. <UserTable
  136. size="small"
  137. theme="top"
  138. columns={this.columns}
  139. data={data.gift}
  140. />
  141. </Modal>
  142. </div>
  143. );
  144. }
  145. renderInfo() {
  146. const { data } = this.props;
  147. const checkout = data;
  148. return (
  149. <div className="order-item-info">
  150. <div style={{ width: 360 }} className="d-i-b t-1 t-s-16">
  151. {data.title}
  152. </div>
  153. <div style={{ width: 530 }} hidden={checkout.productType === 'data'} className="d-i-b t-8 t-s-12">
  154. {checkout.productType !== 'course_package' && <span className="m-r-2">开通有效期: {checkout.expireDays ? `${checkout.expireDays}天` : '付款后立即生效'}</span>}
  155. {checkout.productType !== 'course_package' && <span className="m-l-2">使用有效期: {checkout.useExpireDays ? `${checkout.useExpireDays}天` : '永久'}</span>}
  156. </div>
  157. <div style={{ width: 530 }} hidden={checkout.productType !== 'data'} className="d-i-b t-8 t-s-12">
  158. <IconButton
  159. type="download"
  160. onClick={() => {
  161. openLink(checkout.data.resource);
  162. }}
  163. />
  164. </div>
  165. <div style={{ width: 120 }} className="d-i-b t-s-12 p-r">
  166. {data.number > 0 && <span className="t-8 m-r-2">数量</span>}
  167. {data.number > 0 && <span className="t-1">{data.number}</span>}
  168. </div>
  169. <div className="d-i-b t-7 t-s-16"> ¥ {data.money}</div>
  170. </div>
  171. );
  172. }
  173. renderDetail() {
  174. const { data = {} } = this.props;
  175. const { children = [], gift } = data;
  176. const { open } = this.state;
  177. return (
  178. <div className="order-item-detail l-h-20">
  179. <div hidden={!children || children.length === 0} className="contain">
  180. <div style={{ width: 1010 }} className="d-i-b t-1 t-s-12">
  181. <span className="d-i-b f-w-b m-r-5">
  182. 包含
  183. <Icon
  184. hidden={!open}
  185. className="t-10 c-p"
  186. type="caret-up"
  187. onClick={() => this.setState({ open: !open })}
  188. />
  189. <Icon
  190. hidden={open}
  191. className="t-10 c-p"
  192. type="caret-down"
  193. onClick={() => this.setState({ open: !open })}
  194. />
  195. </span>
  196. <span hidden={open} style={{ width: 300 }} className="d-i-b nowrap">
  197. {(children || []).map(checkout => checkout.title).join(' + ')}
  198. </span>
  199. </div>
  200. <div className="d-i-b t-1 t-s-12 t-d-l-t"> ¥ {formatMoney(data.originMoney)}</div>
  201. </div>
  202. <div hidden={!open} className="contain-list m-b-5 l-h-16">
  203. {(children || []).map(checkout => {
  204. return <div>
  205. <div style={{ width: 360 }} className="d-i-b t-1 t-s-12">
  206. <span className="d-i-b m-r-5">{checkout.title}</span>
  207. </div>
  208. <div className="d-i-b t-8 t-s-12">
  209. <span className="m-r-2">开通有效期: {checkout.expireDays ? `${checkout.expireDays}天` : '付款后立即生效'}</span>
  210. <span className="m-l-2">使用有效期: {checkout.useExpireDays ? `${checkout.useExpireDays}天` : '永久'}</span>
  211. </div>
  212. </div>;
  213. })}
  214. </div>
  215. {gift && <div className="service">
  216. <div className="d-i-b t-1 t-s-12">
  217. <span className="d-i-b f-w-b m-r-5">赠送服务</span>
  218. <span className="d-i-b">
  219. {gift.map(row => {
  220. return `${row.label}x${row.param ? row.param.label : row.number}`;
  221. }).join(' ')}
  222. <Icon className="m-l-5 close" type="exclamation-circle" theme="filled" onClick={() => {
  223. this.setState({ showList: true });
  224. }} />
  225. </span>
  226. </div>
  227. </div>}
  228. </div>
  229. );
  230. }
  231. }