index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. 有效期: {useStartTime && formatDate(useStartTime, 'YYYY-MM-DD')}至{useEndTime && 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 { checked } = this.state;
  145. const { data, onOpen, contract } = this.props;
  146. const { teacher, endTime, courseModule } = data;
  147. switch (courseModule) {
  148. case 'video':
  149. return <div className="body">
  150. <div className="text">
  151. <span>
  152. 请于{endTime && formatDate(endTime, 'YYYY-MM-DD')}前开通课程
  153. </span>
  154. </div>
  155. <div className="btn">
  156. <Button size="lager" radius onClick={() => onOpen && onOpen()}>
  157. 开通作业
  158. </Button>
  159. </div>
  160. </div>;
  161. case 'online':
  162. return <div className="body">
  163. <div className="text">
  164. <Checkbox checked={checked} onChange={() => {
  165. this.setState({ checked: !checked });
  166. }} />
  167. <span>
  168. 我已阅读并同意<a href={`/contract/${contract.key}`} target="_blank">{contract.title}</a>
  169. </span>
  170. </div>
  171. <div className="btn">
  172. <Button size="lager" disabled={!checked} radius onClick={() => checked && onOpen && onOpen()}>
  173. 开通作业
  174. </Button>
  175. </div>
  176. </div>;
  177. case 'vs':
  178. return <div className="body">
  179. <div className="t-1">请尽快与老师预约上课时间</div>
  180. <div className="t-2">请于 {endTime && formatDate(endTime, 'YYYY-MM-DD')} 前开通课程</div>
  181. <div className="qr-code">
  182. {teacher && <Assets name="qrcode" src={teacher.qr} />}
  183. </div>
  184. </div>;
  185. default:
  186. return <div />;
  187. }
  188. }
  189. getIngBody() {
  190. const { data, list = [], previewAction, onPreview } = this.props;
  191. const { useStartTime, useEndTime } = data;
  192. return (
  193. <div className="body">
  194. {list.length > 0 && <div className="title">近期待完成</div>}
  195. {list.length === 0 ? (
  196. <div className="text">
  197. <div className="t-1">好棒!</div>
  198. <div className="t-2">近期的作业都完成啦</div>
  199. </div>
  200. ) : (<div className="list">
  201. {list.map(item => {
  202. return (
  203. <div className="item">
  204. <div className="top">
  205. <div className="title">{item.title}</div>
  206. </div>
  207. <div className="detail">
  208. <Progress size="small" progress={item.progress} />
  209. <div className="action">
  210. {item.progress === 0 && (
  211. <IconButton
  212. type="start"
  213. tip="Start"
  214. onClick={() => previewAction && previewAction('start', item)}
  215. />
  216. )}
  217. {item.progress > 0 && (
  218. <IconButton
  219. type="continue"
  220. onClick={() => previewAction && previewAction('continue', item)}
  221. tip="Continue"
  222. />
  223. )}
  224. {item.progress > 0 && (
  225. <IconButton
  226. type="restart"
  227. onClick={() => previewAction && previewAction('restart', item)}
  228. tip="Restart"
  229. />
  230. )}
  231. </div>
  232. </div>
  233. </div>
  234. );
  235. })}
  236. </div>
  237. )}
  238. <div className="bottom">
  239. 有效期: {useStartTime && formatDate(useStartTime, 'YYYY-MM-DD')}至{useEndTime && formatDate(useEndTime, 'YYYY-MM-DD')} <a onClick={() => onPreview && onPreview()}>全部作业></a>
  240. </div>
  241. </div>
  242. );
  243. }
  244. getBody() {
  245. const { status } = this.props;
  246. if (status === 'end') return this.getEndBody();
  247. if (status === 'stop') return this.getStopBody();
  248. if (status === 'open') return this.getOpenBody();
  249. if (status === 'ing') return this.getIngBody();
  250. return <div />;
  251. }
  252. render() {
  253. const { style, title, tag, status } = this.props;
  254. return (
  255. <Module style={style} className={`card1 ${status}`}>
  256. <div className="header">
  257. {tag && <div className="tag">{tag}</div>}
  258. {title}
  259. </div>
  260. {this.getBody()}
  261. </Module>
  262. );
  263. }
  264. }