index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 { formatDate } from '@src/services/Tools';
  7. import Module from '../Module';
  8. import Progress from '../Progress';
  9. import IconButton from '../IconButton';
  10. import Button from '../Button';
  11. export default class Card extends Component {
  12. getBuyBody() {
  13. const { data } = this.props;
  14. return (
  15. <div className="body">
  16. <div className="desc" dangerouslySetInnerHTML={{ __html: data.description }} />
  17. <div className="btn">
  18. <Button size="lager" radius>
  19. 立即购买
  20. </Button>
  21. </div>
  22. </div>
  23. );
  24. }
  25. getOpenBody() {
  26. return (
  27. <div className="body">
  28. <div className="title">请开通预习作业</div>
  29. <div className="text">
  30. <Checkbox />
  31. <span>
  32. 我已阅读并同意<Link to="">《千行 GMAT - Sentence Corretion 课程协议》</Link>
  33. </span>
  34. </div>
  35. <div className="btn">
  36. <Button size="lager" radius>
  37. 立即开通
  38. </Button>
  39. </div>
  40. </div>
  41. );
  42. }
  43. getIngBody() {
  44. const { process, previewAction } = this.props;
  45. return (
  46. <div className="body">
  47. <div className="title">近期待完成</div>
  48. {process.previews.length === 0 ? (
  49. <div className="text">
  50. <div>好棒!</div>
  51. <div>近期的作业都完成啦</div>
  52. </div>
  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. const { data, onPreview } = this.props;
  121. const { useStartTime, useEndTime } = data;
  122. return (
  123. <div className="body">
  124. <div className="text">
  125. <div className="t-1">课程已经结束啦</div>
  126. </div>
  127. <div className="bottom">
  128. 有效期: {formatDate(useStartTime, 'YYYY-MM-DD')}至{formatDate(useEndTime, 'YYYY-MM-DD')} <a onClick={() => onPreview && onPreview()}>全部作业></a>
  129. </div>
  130. </div>
  131. );
  132. }
  133. getStopBody() {
  134. return (
  135. <div className="body">
  136. <div className="text">
  137. <div className="t-1">停课中</div>
  138. <div className="t-2">您可至「我的-课程」恢复学习</div>
  139. </div>
  140. </div>
  141. );
  142. }
  143. getOpenBody() {
  144. const { data, onOpen } = this.props;
  145. const { teacher, endTime } = data;
  146. return !teacher ? (
  147. <div className="body">
  148. <div className="text">
  149. <Checkbox />
  150. <span>
  151. 我已阅读并同意<Link to="">《千行课程协议》</Link>
  152. </span>
  153. </div>
  154. <div className="btn">
  155. <Button size="lager" radius onClick={() => onOpen && onOpen()}>
  156. 开通作业
  157. </Button>
  158. </div>
  159. </div>
  160. ) : (<div className="body">
  161. <div className="t-1">请尽快与老师预约上课时间</div>
  162. <div className="t-2">请于 {formatDate(endTime, 'YYYY-MM-DD')} 前开通课程</div>
  163. <div className="qr-code">
  164. <Assets name="qrcode" src={teacher.qr} />
  165. </div>
  166. </div>
  167. );
  168. }
  169. getIngBody() {
  170. const { data, list = [], previewAction, onPreview } = this.props;
  171. const { useStartTime, useEndTime } = data;
  172. return (
  173. <div className="body">
  174. {list.length > 0 && <div className="title">近期待完成</div>}
  175. {list.length === 0 ? (
  176. <div className="text">
  177. <div className="t-1">好棒!</div>
  178. <div className="t-2">近期的作业都完成啦</div>
  179. </div>
  180. ) : (<div className="list">
  181. {list.map(item => {
  182. return (
  183. <div className="item">
  184. <div className="top">
  185. <div className="title">{item.title}</div>
  186. </div>
  187. <div className="detail">
  188. <Progress size="small" progress={item.progress} />
  189. <div className="action">
  190. {item.progress === 0 && (
  191. <IconButton
  192. type="start"
  193. tip="Start"
  194. onClick={() => previewAction && previewAction('start', item)}
  195. />
  196. )}
  197. {item.progress > 0 && (
  198. <IconButton
  199. type="continue"
  200. onClick={() => previewAction && previewAction('continue', item)}
  201. tip="Continue"
  202. />
  203. )}
  204. {item.progress > 0 && (
  205. <IconButton
  206. type="restart"
  207. onClick={() => previewAction && previewAction('restart', item)}
  208. tip="Restart"
  209. />
  210. )}
  211. </div>
  212. </div>
  213. </div>
  214. );
  215. })}
  216. </div>
  217. )}
  218. <div className="bottom">
  219. 有效期: {formatDate(useStartTime, 'YYYY-MM-DD')}至{formatDate(useEndTime, 'YYYY-MM-DD')} <a onClick={() => onPreview && onPreview()}>全部作业></a>
  220. </div>
  221. </div>
  222. );
  223. }
  224. getBody() {
  225. const { status } = this.props;
  226. if (status === 'end') return this.getEndBody();
  227. if (status === 'stop') return this.getStopBody();
  228. if (status === 'open') return this.getOpenBody();
  229. if (status === 'ing') return this.getIngBody();
  230. return <div />;
  231. }
  232. render() {
  233. const { style, title, tag, status } = this.props;
  234. return (
  235. <Module style={style} className={`card1 ${status}`}>
  236. <div className="header">
  237. {tag && <div className="tag">{tag}</div>}
  238. {title}
  239. </div>
  240. {this.getBody()}
  241. </Module>
  242. );
  243. }
  244. }