index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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.report.id && (
  61. <IconButton
  62. type="start"
  63. tip="Start"
  64. onClick={() => previewAction && previewAction('start', item)}
  65. />
  66. )}
  67. {item.report.id && (
  68. <IconButton
  69. type="continue"
  70. onClick={() => previewAction && previewAction('continue', item)}
  71. tip="Continue"
  72. />
  73. )}
  74. {item.report.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. </div>
  89. );
  90. }
  91. getBody() {
  92. const { process = {} } = this.props;
  93. if (!process.payed && !process.startTime) return this.getBuyBody();
  94. if (process.payed) return this.getOpenBody();
  95. if (process.startTime) return this.getIngBody();
  96. return <div />;
  97. }
  98. render() {
  99. const { style, data = {}, process = {} } = this.props;
  100. return (
  101. <Module
  102. style={style}
  103. className={`card ${!process.payed && !process.startTime ? 'buy' : ''} ${process.payed ? 'open' : ''} ${process.startTime ? 'ing' : ''}`}
  104. >
  105. <div className="header">
  106. {`${data.titleZh} ${data.titleEn}`}
  107. {!process.payed && !process.startTime && <span className="sub-title">未购买</span>}
  108. {(process.payed || process.startTime) && <span className="sub-title">已购买</span>}
  109. </div>
  110. {this.getBody()}
  111. </Module>
  112. );
  113. }
  114. }
  115. export class Card1 extends Component {
  116. constructor(props) {
  117. super(props);
  118. this.state = {};
  119. }
  120. getEndBody() {
  121. const { data, onPreview } = this.props;
  122. const { useStartTime, useEndTime } = data;
  123. return (
  124. <div className="body">
  125. <div className="text">
  126. <div className="t-1">课程已经结束啦</div>
  127. </div>
  128. <div className="bottom">
  129. 有效期: {useStartTime && formatDate(useStartTime, 'YYYY-MM-DD')}至{useEndTime && formatDate(useEndTime, 'YYYY-MM-DD')} <a onClick={() => onPreview && onPreview()}>全部作业></a>
  130. </div>
  131. </div>
  132. );
  133. }
  134. getStopBody() {
  135. return (
  136. <div className="body">
  137. <div className="text">
  138. <div className="t-1">停课中</div>
  139. <div className="t-2">您可至「我的-课程」恢复学习</div>
  140. </div>
  141. </div>
  142. );
  143. }
  144. getOpenBody() {
  145. const { checked } = this.state;
  146. const { data, onOpen, contract } = this.props;
  147. const { teacher, endTime, course = {} } = data;
  148. switch (course.courseModule) {
  149. case 'video':
  150. return <div className="body">
  151. <div className="text-end">
  152. <div className="t-1">可至「个人中心-课程」开通</div>
  153. </div>
  154. </div>;
  155. case 'online':
  156. return <div className="body">
  157. <div className="text">
  158. <Checkbox checked={checked} onChange={() => {
  159. this.setState({ checked: !checked });
  160. }} />
  161. <span>
  162. 我已阅读并同意<a href={`/contract/${contract.key}`} target="_blank">{contract.title}</a>
  163. </span>
  164. </div>
  165. <div className="btn">
  166. <Button size="lager" disabled={!checked} radius onClick={() => checked && onOpen && onOpen()}>
  167. 开通作业
  168. </Button>
  169. </div>
  170. </div>;
  171. case 'vs':
  172. return <div className="body">
  173. <div className="t-1">请尽快与老师预约上课时间</div>
  174. <div className="t-2">请于 {endTime && formatDate(endTime, 'YYYY-MM-DD')} 前开通课程</div>
  175. <div className="qr-code">
  176. {teacher && <Assets name="qrcode" src={teacher.qr} />}
  177. </div>
  178. </div>;
  179. default:
  180. return <div />;
  181. }
  182. }
  183. getIngBody() {
  184. const { data, list = [], previewAction, onPreview } = this.props;
  185. const { useStartTime, useEndTime } = data;
  186. return (
  187. <div className="body">
  188. {list.length > 0 && <div className="title">近期待完成</div>}
  189. {list.length === 0 ? (
  190. <div className="text">
  191. <Assets name="good" className="good-icon" />
  192. <div className="t-1">好棒!</div>
  193. <div className="t-2">近期的作业都完成啦</div>
  194. </div>
  195. ) : (<div className="list">
  196. {list.map(item => {
  197. return (
  198. <div className="item">
  199. <div className="top">
  200. <div className="title">{item.title}</div>
  201. </div>
  202. <div className="detail">
  203. <Progress size="small" progress={item.progress} />
  204. <div className="action">
  205. {item.progress === 0 && (
  206. <IconButton
  207. type="start"
  208. tip="Start"
  209. onClick={() => previewAction && previewAction('start', item)}
  210. />
  211. )}
  212. {item.progress > 0 && (
  213. <IconButton
  214. type="continue"
  215. onClick={() => previewAction && previewAction('continue', item)}
  216. tip="Continue"
  217. />
  218. )}
  219. {item.progress > 0 && (
  220. <IconButton
  221. type="restart"
  222. onClick={() => previewAction && previewAction('restart', item)}
  223. tip="Restart"
  224. />
  225. )}
  226. </div>
  227. </div>
  228. </div>
  229. );
  230. })}
  231. </div>)}
  232. <div className="bottom">
  233. 有效期: {useStartTime && formatDate(useStartTime, 'YYYY-MM-DD')}至{useEndTime && formatDate(useEndTime, 'YYYY-MM-DD')} <a onClick={() => onPreview && onPreview()}>全部作业></a>
  234. </div>
  235. </div>
  236. );
  237. }
  238. getBody() {
  239. const { status } = this.props;
  240. if (status === 'end') return this.getEndBody();
  241. if (status === 'stop') return this.getStopBody();
  242. if (status === 'open') return this.getOpenBody();
  243. if (status === 'ing') return this.getIngBody();
  244. return <div />;
  245. }
  246. render() {
  247. const { style, title, tag, status } = this.props;
  248. return (
  249. <Module style={style} className={`card1 ${status}`}>
  250. <div className="header">
  251. {tag && <div className="tag">{tag}</div>}
  252. {title}
  253. </div>
  254. {this.getBody()}
  255. </Module>
  256. );
  257. }
  258. }