index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import React, { Component } from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Assets from '@src/components/Assets';
  5. import { getMap, formatSeconds, formatDate } from '@src/services/Tools';
  6. import Button from '../Button';
  7. import More from '../More';
  8. import { Order } from '../../stores/order';
  9. import { User } from '../../stores/user';
  10. import { ServiceKey, ServiceParamMap, CrowdList } from '../../../Constant';
  11. const CrowdMap = getMap(CrowdList, 'value', 'label');
  12. export class SingleItem extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {};
  16. }
  17. buy() {
  18. const { data } = this.props;
  19. User.needLogin().then(() => {
  20. Order.speedPay({ productType: 'course', productId: data.id }).then(result => {
  21. User.needPay(result).then(() => {
  22. linkTo('/my/course');
  23. });
  24. });
  25. });
  26. }
  27. add() {
  28. const { data } = this.props;
  29. User.needLogin().then(() => {
  30. Order.addCheckout({ productType: 'course', productId: data.id })
  31. .then(() => {
  32. this.setState({ add: true });
  33. });
  34. });
  35. }
  36. render() {
  37. const { data = {}, noAction } = this.props;
  38. const { add } = this.state;
  39. return (
  40. <div className="single-item">
  41. <div className="img c-p" style={{ backgroundImage: `url(${data.cover})` }} onClick={() => linkTo(`/course/detail/${data.id}`)}>
  42. <div className="title">
  43. <div className="tag">{CrowdMap[data.crowd]}</div>
  44. <Link className='f-w-b' to={`/course/detail/${data.id}`} target="_blank">{data.title}</Link>
  45. </div>
  46. <div className="left">
  47. <span>课时数: {data.noNumber}</span>
  48. <span>{formatSeconds(data.time)}</span>
  49. </div>
  50. <div className="right">
  51. <span>{data.trailNumber || 0}次观看</span>
  52. </div>
  53. </div>
  54. <div className="name">
  55. <span>授课老师:{data.teacher}</span>
  56. <span>优质问答: {data.askNumber}</span>
  57. <span>有效期: {data.useExpireDays}天</span>
  58. </div>
  59. <div className="money">¥ {data.price}</div>
  60. {!noAction && (
  61. <div className="action">
  62. {!data.have && (
  63. <Button radius size="lager" onClick={() => this.buy()}>
  64. 立即购买
  65. </Button>
  66. )}
  67. {data.have && (
  68. <Button
  69. className="f-r"
  70. theme="default"
  71. radius
  72. size="lager"
  73. onClick={() => linkTo(`/course/detail/${data.id}`)}
  74. >
  75. 查看课程
  76. </Button>
  77. )}
  78. {!data.have && (
  79. <Button
  80. className="f-r"
  81. theme="default"
  82. disabled={data.add || add}
  83. radius
  84. size="lager"
  85. onClick={() => this.add()}
  86. >
  87. <Assets name={data.add || add ? 'add_disabled' : 'add'} />
  88. </Button>
  89. )}
  90. </div>
  91. )}
  92. {!noAction && data.have && <Assets className="buyed" width={75} height={75} name="Purchased" />}
  93. </div>
  94. );
  95. }
  96. }
  97. export class PackageItem extends Component {
  98. constructor(props) {
  99. super(props);
  100. this.state = {};
  101. }
  102. buy() {
  103. const { data } = this.props;
  104. User.needLogin().then(() => {
  105. Order.speedPay({ productType: 'course_package', productId: data.id }).then(result => {
  106. User.needPay(result).then(() => {
  107. linkTo('/my/course');
  108. });
  109. });
  110. });
  111. }
  112. add() {
  113. const { data } = this.props;
  114. User.needLogin().then(() => {
  115. Order.addCheckout({ productType: 'course_package', productId: data.id }).then(() => {
  116. this.setState({ add: true });
  117. });
  118. });
  119. }
  120. render() {
  121. const { data = {} } = this.props;
  122. const { add } = this.state;
  123. const originMoney = data.courses.reduce((a, y) => a + y.price, 0);
  124. const novice = data.courses.filter(row => row.crowd !== 'novice').length === 0;
  125. const teacherMap = {};
  126. data.courses.forEach(row => {
  127. teacherMap[row.teacher] = true;
  128. });
  129. const teachers = Object.keys(teacherMap);
  130. return (
  131. <div className="package-item">
  132. <div className="block m-b-1 c-p" onClick={() => linkTo(`/course/package/detail/${data.id}`)}>
  133. <div className="title t-1 m-b-5">
  134. <div hidden={!novice} className="tag">
  135. 新手
  136. </div>
  137. <Link className='t-1 f-w-b' to={`/course/package/detail/${data.id}`} target="_blank">{data.title}</Link>
  138. </div>
  139. <div className="t-1 t-s-12 m-b-5">授课老师 {teachers.join(' ')}</div>
  140. <div className="t-1 t-s-12 m-b-2">{data.description}</div>
  141. <div className="t-1 t-s-12">包含课程</div>
  142. <div className="p-t-5">
  143. {data.courses.map(course => {
  144. return (
  145. <div className="t m-b-1 t-4 m-r-5 t-s-12 d-i-b p-5">
  146. {course.title}({course.noNumber}课时)
  147. </div>
  148. );
  149. })}
  150. </div>
  151. <div className="t-1 t-s-12">配套服务</div>
  152. <div className="p-t-5">
  153. <div className="t m-b-1 t-4 m-r-5 t-s-12 d-i-b p-5">预习作业</div>
  154. <div className="t m-b-1 t-4 m-r-5 t-s-12 d-i-b p-5">课后答题</div>
  155. </div>
  156. <div className="t-1 t-s-12">赠送服务</div>
  157. <div className="p-t-5">
  158. {data.gift &&
  159. ServiceKey.map(row => {
  160. if (!data.gift[row.value]) return null;
  161. const list = ServiceParamMap[row.value];
  162. if (list) {
  163. const map = getMap(list, 'value', 'label');
  164. return (
  165. <div className="t m-b-1 t-4 m-r-5 t-s-12 d-i-b p-5">
  166. {row.label}×{map[data.gift[row.value]]}
  167. </div>
  168. );
  169. }
  170. return (
  171. <div className="t m-b-1 t-4 m-r-5 t-s-12 d-i-b p-5">
  172. {row.label}×{data.gift[row.value]}
  173. </div>
  174. );
  175. })}
  176. </div>
  177. </div>
  178. <div className="t-1 t-s-12">
  179. 原价: <span className="t-d-l-t">¥{originMoney}</span>
  180. </div>
  181. <div className="t-7 t-s-18 f-w-b m-b-1">套餐价: ¥{data.price}</div>
  182. <div className="action">
  183. <Button radius size="lager" onClick={() => this.buy()}>
  184. 立即购买
  185. </Button>
  186. <Button
  187. className="f-r"
  188. theme="default"
  189. radius
  190. size="lager"
  191. disabled={data.add || add}
  192. onClick={() => this.add()}
  193. >
  194. <Assets name={data.add || add ? 'add_disabled' : 'add'} />
  195. </Button>
  196. </div>
  197. </div>
  198. );
  199. }
  200. }
  201. export class DataItem extends Component {
  202. constructor(props) {
  203. super(props);
  204. this.state = {};
  205. }
  206. buy() {
  207. const { data } = this.props;
  208. User.needLogin().then(() => {
  209. Order.speedPay({ productType: 'data', productId: data.id }).then(result => {
  210. User.needPay(result).then(() => {
  211. linkTo('/my/tools?tab=data');
  212. });
  213. });
  214. });
  215. }
  216. add() {
  217. const { data } = this.props;
  218. User.needLogin().then(() => {
  219. Order.addCheckout({ productType: 'data', productId: data.id }).then(() => {
  220. this.setState({ add: true });
  221. });
  222. });
  223. }
  224. render() {
  225. const { data = {} } = this.props;
  226. const { add } = this.state;
  227. return (
  228. <div className="data-single-item">
  229. <Assets
  230. width={264}
  231. height={309}
  232. name=""
  233. className="c-p"
  234. src={data.cover}
  235. onClick={() => linkTo(`/course/data/detail/${data.id}`)}
  236. />
  237. <div className="m-b-1">
  238. <span className="t-7 t-s-24 f-w-b">¥{data.price}</span>
  239. <span className="f-r t-8 t-s-20">{data.saleNumber}人</span>
  240. </div>
  241. <div className="action">
  242. {!data.have && (
  243. <Button
  244. radius
  245. size="lager"
  246. onClick={() => {
  247. this.buy();
  248. }}
  249. >
  250. 立即购买
  251. </Button>
  252. )}
  253. {data.have && (
  254. <Button className="f-r" theme="default" radius size="lager" onClick={() => openLink(data.resource)}>
  255. 查看资料
  256. </Button>
  257. )}
  258. {!data.have && (
  259. <Button
  260. className="f-r"
  261. theme="default"
  262. disabled={data.add || add}
  263. radius
  264. size="lager"
  265. onClick={() => this.add()}
  266. >
  267. <Assets name={data.add || add ? 'add_disabled' : 'add'} />
  268. </Button>
  269. )}
  270. </div>
  271. {data.have && <Assets className="buyed" width={75} height={75} name="Purchased" />}
  272. </div>
  273. );
  274. }
  275. }
  276. export class TextbookItem extends Component {
  277. constructor(props) {
  278. super(props);
  279. this.state = {};
  280. }
  281. render() {
  282. const { data = {}, menu, onClick, onMenuClick } = this.props;
  283. return (
  284. <div className="textbook-item">
  285. <Assets name="sun_blue" className="m-b-5" onClick={() => onClick()} />
  286. <div className="t-6 t-s-14 m-b-5">
  287. 已更新至 <span className="t-4">{data.number}</span> 题
  288. </div>
  289. <div className="t-6 t-s-12 m-b-1">
  290. {data.time && formatDate(data.time, 'YYYY-MM-DD HH:mm:ss')}
  291. <div className="f-r">
  292. <More menu={menu} onClick={onMenuClick} />
  293. </div>
  294. </div>
  295. </div>
  296. );
  297. }
  298. }