page.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { formatDate, formatMonth, getMap } from '@src/services/Tools';
  5. import { Course } from '../../../stores/course';
  6. import { My } from '../../../stores/my';
  7. import { PrepareStatus, ExperiencePercent } from '../../../../Constant';
  8. const PrepareStatusMap = getMap(PrepareStatus, 'value', 'short');
  9. const ExperiencePercentMap = getMap(ExperiencePercent, 'value', 'label');
  10. export default class extends Page {
  11. initState() {
  12. return {
  13. data: {},
  14. };
  15. }
  16. initData() {
  17. const { id } = this.params;
  18. Course.getExperience(id)
  19. .then(result => {
  20. this.setState({ data: result });
  21. });
  22. Course.experienceView(id);
  23. }
  24. onCollect() {
  25. const { data } = this.state;
  26. const { collect } = this.state;
  27. let collectStatus = false;
  28. if (collect !== undefined) {
  29. collectStatus = collect;
  30. } else {
  31. collectStatus = data.collect;
  32. }
  33. if (!collectStatus) {
  34. My.addExperienceCollect(data.id)
  35. .then(() => {
  36. this.setState({ collect: true });
  37. });
  38. } else {
  39. My.delExperienceCollect(data.id)
  40. .then(() => {
  41. this.setState({ collect: false });
  42. });
  43. }
  44. }
  45. renderView() {
  46. const { data = {}, collect } = this.state;
  47. let collectStatus = false;
  48. if (collect !== undefined) {
  49. collectStatus = collect;
  50. } else {
  51. collectStatus = data.collect;
  52. }
  53. return (
  54. <div>
  55. <div className="center">
  56. <div className="content">
  57. <div className="t-1 t-s-28">{data.title} </div>
  58. <div className="t-6 m-b-2">
  59. <span className="m-r-2">{data.updateTime && formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')}</span>
  60. <span className="m-r-2 m-l-1">阅读 {data.viewNumber || 0}</span>
  61. <span className="m-l-1 c-p" onClick={() => this.onCollect()}>
  62. {!collectStatus ? '收藏' : '取消收藏'}
  63. </span>
  64. </div>
  65. <div className="t-1">
  66. <span className="m-r-2">{data.user ? data.user.nickname : data.nickname}</span>
  67. <span className="m-r-2 m-l-1">{PrepareStatusMap[data.prepareStatus]}</span>
  68. <span className="m-r-2 m-l-1">备考:{!!data.experienceDay && formatMonth(data.experienceDay, false)}</span>
  69. <span className="m-r-2 m-l-1">考试时间:{data.experienceTime && formatDate(data.experienceTime, 'YYYY-MM-DD HH:mm:ss')}</span>
  70. <span className="m-r-2 m-l-1">{data.experienceScore}分 /提分 {ExperiencePercentMap[data.experiencePercent]}</span>
  71. {data.link && <a className="m-l-1 t-4" href={data.link} target="_blank">更多信息</a>}
  72. </div>
  73. <div className="detail t-1" dangerouslySetInnerHTML={{ __html: data.content }} />
  74. </div>
  75. </div>
  76. </div>
  77. );
  78. }
  79. }