import React from 'react'; import './index.less'; import Page from '@src/containers/Page'; import { formatDate, formatMonth, getMap } from '@src/services/Tools'; import { Course } from '../../../stores/course'; import { My } from '../../../stores/my'; import { PrepareStatus, ExperiencePercent } from '../../../../Constant'; const PrepareStatusMap = getMap(PrepareStatus, 'value', 'short'); const ExperiencePercentMap = getMap(ExperiencePercent, 'value', 'label'); export default class extends Page { initState() { return { data: {}, }; } initData() { const { id } = this.params; Course.getExperience(id) .then(result => { this.setState({ data: result }); }); Course.experienceView(id); } onCollect() { const { data } = this.state; const { collect } = this.state; let collectStatus = false; if (collect !== undefined) { collectStatus = collect; } else { collectStatus = data.collect; } if (!collectStatus) { My.addExperienceCollect(data.id) .then(() => { this.setState({ collect: true }); }); } else { My.delExperienceCollect(data.id) .then(() => { this.setState({ collect: false }); }); } } renderView() { const { data = {}, collect } = this.state; let collectStatus = false; if (collect !== undefined) { collectStatus = collect; } else { collectStatus = data.collect; } return (
{data.title}
{data.updateTime && formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')} 阅读 {data.viewNumber || 0} this.onCollect()}> {!collectStatus ? '收藏' : '取消收藏'}
{data.user ? data.user.nickname : data.nickname} {PrepareStatusMap[data.prepareStatus]} 备考:{!!data.experienceDay && formatMonth(data.experienceDay, false)} 考试时间:{data.experienceTime && formatDate(data.experienceTime, 'YYYY-MM-DD HH:mm:ss')} {data.experienceScore}分 /提分 {ExperiencePercentMap[data.experiencePercent]} {data.link && 更多信息}
); } }