index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd-mobile';
  4. import Assets from '@src/components/Assets';
  5. import { getMap, formatDate } from '@src/services/Tools';
  6. import { CrowdList, ServiceParamMap } from '../../../Constant';
  7. import Tag from '../Tag';
  8. import Money from '../Money';
  9. import Button from '../Button';
  10. const CrowdMap = getMap(CrowdList, 'value', 'label');
  11. const ServiceParamRelation = getMap(Object.keys(ServiceParamMap).map(key => {
  12. const list = (ServiceParamMap[key] || []).map((row, index) => {
  13. row.index = index;
  14. return row;
  15. });
  16. return { map: getMap(list, 'value'), key };
  17. }), 'key', 'map');
  18. export class Block extends Component {
  19. render() {
  20. const { className = '', children, onClick } = this.props;
  21. return <div className={`g-block ${className}`} onClick={() => onClick && onClick()}>{children}</div>;
  22. }
  23. }
  24. export class TopBlock extends Component {
  25. render() {
  26. const { className = '', theme = 'default', children, onClick } = this.props;
  27. return <div className={`g-top-block ${className} ${theme}`} onClick={() => onClick && onClick()}>{children}</div>;
  28. }
  29. }
  30. export class TagBlock extends Component {
  31. render() {
  32. const { className = '', theme = 'default', tag, children, onClick } = this.props;
  33. return (
  34. <div className={`g-tag-block ${className} ${theme}`} onClick={() => onClick && onClick()}>
  35. <div className="g-tag-block-tag">{tag}</div>
  36. {children}
  37. </div>
  38. );
  39. }
  40. }
  41. export class LinkBlock extends Component {
  42. render() {
  43. const { className = '', theme = 'default', title, sub, onClick } = this.props;
  44. return (
  45. <div className={`g-link-block ${className} ${theme}`} onClick={() => onClick && onClick()}>
  46. <div className="g-link-block-title">{title}</div>
  47. <div className="g-link-block-sub">{sub}</div>
  48. <div className="g-link-block-icon">
  49. <Icon type="right" size="xxs" color="#fff" />
  50. </div>
  51. </div>
  52. );
  53. }
  54. }
  55. export class CourseBlock extends Component {
  56. render() {
  57. const { data } = this.props;
  58. const comment = data.comments ? data.comments[0] : {};
  59. return (
  60. <Block className="course-block" onClick={() => {
  61. linkTo(`/product/course/detail/${data.id}`);
  62. }}>
  63. <div className="title">{data.title}</div>
  64. <div className="block-body">
  65. <Assets name="c_b" src={data.cover} />
  66. <div className="info">
  67. <div className="teacher">
  68. 授课老师<span>{data.teacher}</span>
  69. </div>
  70. <div className="desc">{comment.content}</div>
  71. <div className="division" />
  72. <div className="data">
  73. {CrowdMap[data.crowd] && <Tag size="small">适合{CrowdMap[data.crowd]}</Tag>}
  74. <div className="result">
  75. 优质回答<span>{data.askNumber}</span>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </Block>
  81. );
  82. }
  83. }
  84. export class CoursePackageBlock extends Component {
  85. render() {
  86. const { theme, data } = this.props;
  87. const comment = data.comments ? data.comments[0] : {};
  88. return (
  89. <TagBlock className="course-co-block" theme={theme} tag={data.tag} onClick={() => {
  90. linkTo(`/product/course/package/${data.id}`);
  91. }}>
  92. <div className="title">{data.title}</div>
  93. <div className="info">
  94. <div className="teacher">授课老师{(data.courses || []).map(row => {
  95. return <span>{row.teacher}</span>;
  96. })}
  97. </div>
  98. {CrowdMap[data.crowd] && <Tag size="small">适合{CrowdMap[data.crowd]}</Tag>}
  99. </div>
  100. <div className="desc">
  101. {comment.content}
  102. </div>
  103. </TagBlock>
  104. );
  105. }
  106. }
  107. export class DataBlock extends Component {
  108. render() {
  109. const { data } = this.props;
  110. const comment = data.comments ? data.comments[0] : {};
  111. return (
  112. <Block className="data-block" onClick={() => {
  113. linkTo(`/product/data/detail/${data.id}`);
  114. }}>
  115. <Assets name="d_b" src={data.cover} />
  116. <div className="info">
  117. <div className="title">{data.title}</div>
  118. <div className="desc">{comment.content}</div>
  119. <div className="division" />
  120. <div className="data">
  121. <div className="people">{data.saleNumber}人已购</div>
  122. <Money value={data.price} />
  123. </div>
  124. </div>
  125. </Block>
  126. );
  127. }
  128. }
  129. export class BuyBlock extends Component {
  130. render() {
  131. const { theme, data, onBuy, onOpen, onRead } = this.props;
  132. const now = new Date().getTime();
  133. let { title, price } = data;
  134. if (data.productType === 'course') {
  135. ({ title, price } = (data.course || {}));
  136. }
  137. if (data.productType === 'data') {
  138. ({ title, price } = (data.data || {}));
  139. }
  140. if (data.productType === 'service') {
  141. const p = ServiceParamRelation[data.service][data.param];
  142. const index = p ? p.index : 0;
  143. ({ title, price } = (data.serviceInfo || {}).package[index]);
  144. }
  145. const expire = data.useEndTime && new Date(data.useEndTime).getTime() < now.getTime();
  146. return (
  147. <TopBlock className="buy-block" theme={theme}>
  148. <div className="block-left">
  149. <div className="title">
  150. {expire && < Tag theme="border" radius size="small">
  151. 已到期
  152. </Tag>}
  153. {!expire && data.productType !== 'data' && data.isUsed && < Tag theme="border" radius size="small">
  154. 已开通
  155. </Tag>}
  156. {!expire && data.productType !== 'data' && !data.isUsed && < Tag theme="border" radius size="small">
  157. 未开通
  158. </Tag>}
  159. {title}
  160. </div>
  161. {((data.useEndTime || data.endTime) && data.productType === 'service') && <div className="date">有效期:{formatDate(data.useEndTime || data.endTime, 'YYYY-MM-DD')}</div>}
  162. {data.productType === 'data' && <div className="date">最新更新:{formatDate(data.data.latestTime, 'YYYY-MM-DD HH:mm:ss')}</div>}
  163. {data.productType === 'course' && !data.isUsed && <div className="date">有效期:{formatDate(data.endTime, 'YYYY-MM-DD')}</div>}
  164. {data.productType === 'course' && data.isUsed && <div className="date">课程学习时间:{formatDate(data.useStartTime, 'YYYY-MM-DD')}-{formatDate(data.useEndTime, 'YYYY-MM-DD')}</div>}
  165. {data.service !== 'textbook' && !data.isUsed && <div className="desc">请访问千行 GMAT 官网开通使用</div>}
  166. {data.service === 'textbook' && expire && <div className="desc">您可至PC端「我的工具」查看往期机经</div>}
  167. </div>
  168. <div className="block-right">
  169. <div className="btn">
  170. {data.service === 'textbook' && !data.isUsed && <Button radius onClick={() => onOpen && onOpen(data)}>开通</Button>}
  171. {expire && data.service !== 'vip' && <Button radius onClick={() => onBuy && onBuy(data)}>续费</Button>}
  172. {data.service === 'vip' && <Button radius onClick={() => onBuy && onBuy(data)}>续费</Button>}
  173. {data.productType === 'data' && data.data.resource && <Button radius onClick={() => onRead && onRead(data)}>阅读</Button>}
  174. {!expire && data.service === 'textbook' && <Button radius onClick={() => onRead && onRead(data)}>阅读</Button>}
  175. </div>
  176. {data.service === 'vip' && <div className="tip">¥{price}/{title}</div>}
  177. </div>
  178. </TopBlock >
  179. );
  180. }
  181. }