import React, { Component } from 'react'; import { Link } from 'react-router-dom'; import './index.less'; import Page from '@src/containers/Page'; import { formatDate, formatMonth, getMap, formatPercent } from '@src/services/Tools'; import Ratio from '../../../components/Ratio'; import UserAction from '../../../components/UserAction'; import UserPagination from '../../../components/UserPagination'; import { ExperienceScore, ExperienceDay, PrepareStatus, ExperiencePercent } from '../../../../Constant'; import { Main } from '../../../stores/main'; import { My } from '../../../stores/my'; import { Course } from '../../../stores/course'; const PrepareStatusMap = getMap(PrepareStatus, 'value', 'label'); const ExperiencePercentMap = getMap(ExperiencePercent, 'value', 'label'); const colorList = ['#2754E0', '#3F86EA', '#41A6F3', '#9BD4FF']; export default class extends Page { initState() { const prepareStatusSelect = PrepareStatus.map(row => { return { title: row.label, key: row.value, }; }); prepareStatusSelect.unshift({ title: '全部', key: '', }); const experienceDaySelect = ExperienceDay.map(row => { return { title: row.label, key: row.value, }; }); experienceDaySelect.unshift({ title: '全部', key: '', }); const experienceScoreSelect = ExperienceScore.map(row => { return { title: row.label, key: row.value, }; }); experienceScoreSelect.unshift({ title: '全部', key: '', }); const experiencePercentSelect = ExperiencePercent.map(row => { return { title: row.label, key: row.value, }; }); experiencePercentSelect.unshift({ title: '全部', key: '', }); return { prepareStatusSelect, experienceDaySelect, experienceScoreSelect, experiencePercentSelect, }; } init() { Main.getExperience() .then(result => { const totalScoreNumber = result.score.reduce((x, y) => x + y, 0); const totalPercentNumber = result.percent.reduce((x, y) => x + y, 0); const scoreList = ExperienceScore.map((row, index) => { const percent = formatPercent(result.score[index] || 0, totalScoreNumber); return { color: colorList[index], label: `${row.label} ${percent} ${result.score[index] || 0}人`, value: percent, }; }); const percentList = ExperiencePercent.map((row, index) => { const percent = formatPercent(result.percent[index] || 0, totalPercentNumber); return { color: colorList[index], label: `${row.label} ${percent} ${result.percent[index] || 0}人`, value: percent, }; }); this.setState({ data: result, scoreList, percentList }); }); } initData() { const data = Object.assign(this.state, this.state.search); if (data.order) { data.sortMap = { [data.order]: data.direction }; } data.filterMap = this.state.search; this.setState(data); Course.listExperience(Object.assign({}, this.state.search)) .then(result => { this.setState({ list: result.list, total: result.total }); }); } onFilter(value) { this.search(value, false); this.initData(); } onChangePage(page) { this.search({ page }, false); this.initData(); } renderView() { return (
千行课堂 > 学员表现
{this.renderDetail()}
); } renderDetail() { const { filterMap, list, data = {}, scoreList, percentList, total, page } = this.state; const { prepareStatusSelect, experienceDaySelect, experienceScoreSelect, experiencePercentSelect } = this.state; return [
学员人数
{data.number || 0}
考分分布
出分周期
{data.period || 0}天
提分比例
this.onFilter(value)} /> {list.map(item => { return
; })} {total > 0 && list.length > 0 && ( this.onChangePage(p)} /> )}
, ]; } } class Article extends Component { constructor(props) { super(props); this.state = {}; } onCollect() { const { data } = this.props; 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 }); }); } } render() { const { data } = this.props; const { collect } = this.state; let collectStatus = false; if (collect !== undefined) { collectStatus = collect; } else { collectStatus = data.collect; } return (
linkTo(`/course/experience/detail/${data.id}`)}>
{data.title}
{data.updateTime && formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')} 阅读 {data.viewNumber} { e.stopPropagation(); this.onCollect(); }}> {collectStatus ? '收藏' : '取消收藏'}
{data.user ? data.user.nickname : data.nickname} {PrepareStatusMap[data.prepareStatus]} 备考:{!!data.experienceDay && formatMonth(data.experienceDay, false)} {data.experienceScore}分 /提分 {ExperiencePercentMap[data.experiencePercent]}
{data.description}
); } }