index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Link } from 'react-router-dom';
  4. import { Checkbox } from 'antd';
  5. import Assets from '@src/components/Assets';
  6. import Module from '../Module';
  7. import Progress from '../Progress';
  8. import IconButton from '../IconButton';
  9. import Button from '../Button';
  10. export default class Card extends Component {
  11. getBuyBody() {
  12. const { data } = this.props;
  13. return (
  14. <div className="body">
  15. <div className="desc" dangerouslySetInnerHTML={{ __html: data.description }} />
  16. <div className="btn">
  17. <Button size="lager" radius>
  18. 立即购买
  19. </Button>
  20. </div>
  21. </div>
  22. );
  23. }
  24. getOpenBody() {
  25. return (
  26. <div className="body">
  27. <div className="title">请开通预习作业</div>
  28. <div className="text">
  29. <Checkbox />
  30. <span>
  31. 我已阅读并同意<Link to="">《千行 GMAT - Sentence Corretion 课程协议》</Link>
  32. </span>
  33. </div>
  34. <div className="btn">
  35. <Button size="lager" radius>
  36. 立即开通
  37. </Button>
  38. </div>
  39. </div>
  40. );
  41. }
  42. getIngBody() {
  43. const { process, previewAction } = this.props;
  44. return (
  45. <div className="body">
  46. <div className="title">近期待完成</div>
  47. {process.previews.length === 0 ? (
  48. <div className="text">
  49. <div>好棒!</div>
  50. <div>近期的作业都完成啦</div>
  51. </div>
  52. ) : (
  53. <div className="list">
  54. {process.previews.map(item => {
  55. return (
  56. <div className="item">
  57. <div className="top">
  58. <div className="date">{item.time}</div>
  59. <div className="action">
  60. {!item.repport.id && (
  61. <IconButton
  62. type="start"
  63. tip="Start"
  64. onClick={() => previewAction && previewAction('start', item)}
  65. />
  66. )}
  67. {item.repport.id && (
  68. <IconButton
  69. type="continue"
  70. onClick={() => previewAction && previewAction('continue', item)}
  71. tip="Continue"
  72. />
  73. )}
  74. {item.repport.id && (
  75. <IconButton
  76. type="restart"
  77. onClick={() => previewAction && previewAction('restart', item)}
  78. tip="Restart"
  79. />
  80. )}
  81. </div>
  82. </div>
  83. <Progress progress={item.report.id ? item.repport.userNumber / item.report.questionNumber : 0} />
  84. </div>
  85. );
  86. })}
  87. </div>
  88. )}
  89. </div>
  90. );
  91. }
  92. getBody() {
  93. const { process = {} } = this.props;
  94. if (!process.payed && !process.startTime) return this.getBuyBody();
  95. if (process.payed) return this.getOpenBody();
  96. if (process.startTime) return this.getIngBody();
  97. return <div />;
  98. }
  99. render() {
  100. const { style, data = {}, process = {} } = this.props;
  101. return (
  102. <Module
  103. style={style}
  104. className={`card ${!process.payed && !process.startTime ? 'buy' : ''} ${process.payed ? 'open' : ''} ${
  105. process.startTime ? 'ing' : ''
  106. }`}
  107. >
  108. <div className="header">
  109. {`${data.titleZh} ${data.titleEn}`}
  110. {!process.payed && !process.startTime && <span className="sub-title">未购买</span>}
  111. {(process.payed || process.startTime) && <span className="sub-title">已购买</span>}
  112. </div>
  113. {this.getBody()}
  114. </Module>
  115. );
  116. }
  117. }
  118. export class Card1 extends Component {
  119. getEndBody() {
  120. return (
  121. <div className="body">
  122. <div className="text">
  123. <div className="t-1">课程已经结束啦</div>
  124. </div>
  125. </div>
  126. );
  127. }
  128. getStopBody() {
  129. return (
  130. <div className="body">
  131. <div className="text">
  132. <div className="t-1">停课中</div>
  133. <div className="t-2">您可至「我的-课程」恢复学习</div>
  134. </div>
  135. </div>
  136. );
  137. }
  138. getOpenBody() {
  139. const { data } = this.props;
  140. const { qrCode } = data;
  141. return !qrCode ? (
  142. <div className="body">
  143. <div className="text">
  144. <Checkbox />
  145. <span>
  146. 我已阅读并同意<Link to="">《千行课程协议》</Link>
  147. </span>
  148. </div>
  149. <div className="btn">
  150. <Button size="lager" radius>
  151. 开通作业
  152. </Button>
  153. </div>
  154. </div>
  155. ) : (
  156. <div className="body">
  157. <div className="t-1">请尽快与老师预约上课时间</div>
  158. <div className="t-2">请于 2019-07-25 前开通课程</div>
  159. <div className="qr-code">
  160. <Assets name="qrcode" />
  161. </div>
  162. </div>
  163. );
  164. }
  165. getIngBody() {
  166. const { data, previewAction } = this.props;
  167. const { list = [] } = data;
  168. return (
  169. <div className="body">
  170. {list.length > 0 && <div className="title">近期待完成</div>}
  171. {list.length === 0 ? (
  172. <div className="text">
  173. <div className="t-1">好棒!</div>
  174. <div className="t-2">近期的作业都完成啦</div>
  175. </div>
  176. ) : (
  177. <div className="list">
  178. {list.map(item => {
  179. return (
  180. <div className="item">
  181. <div className="top">
  182. <div className="title">{item.title}</div>
  183. </div>
  184. <div className="detail">
  185. <Progress size="small" progress={item.progress} />
  186. <div className="action">
  187. {item.status === 'start' && (
  188. <IconButton
  189. type="start"
  190. tip="Start"
  191. onClick={() => previewAction && previewAction('start', item)}
  192. />
  193. )}
  194. {item.status === 'continue' && (
  195. <IconButton
  196. type="continue"
  197. onClick={() => previewAction && previewAction('continue', item)}
  198. tip="Continue"
  199. />
  200. )}
  201. {item.status === 'restart' && (
  202. <IconButton
  203. type="restart"
  204. onClick={() => previewAction && previewAction('restart', item)}
  205. tip="Restart"
  206. />
  207. )}
  208. </div>
  209. </div>
  210. </div>
  211. );
  212. })}
  213. </div>
  214. )}
  215. <div className="bottom">
  216. 有效期: 2019-08-20至2020-01-01 <Link to="">全部作业></Link>
  217. </div>
  218. </div>
  219. );
  220. }
  221. getBody() {
  222. const { data } = this.props;
  223. const { status } = data;
  224. if (status === 'end') return this.getEndBody();
  225. if (status === 'stop') return this.getStopBody();
  226. if (status === 'open') return this.getOpenBody();
  227. if (status === 'ing') return this.getIngBody();
  228. return <div />;
  229. }
  230. render() {
  231. const { style, data, title, tag } = this.props;
  232. const { status } = data;
  233. return (
  234. <Module style={style} className={`card1 ${status}`}>
  235. <div className="header">
  236. {tag && <div className="tag">{tag}</div>}
  237. {title}
  238. </div>
  239. {this.getBody()}
  240. </Module>
  241. );
  242. }
  243. }