import React from 'react'; import './index.less'; import { Tooltip, Popover, Checkbox } from 'antd'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import { timeRange, formatPercent, formatSeconds, formatDate, getMap } from '@src/services/Tools'; import UserLayout from '../../../layouts/User'; import UserAction from '../../../components/UserAction'; import UserTable from '../../../components/UserTable'; import IconButton from '../../../components/IconButton'; import menu, { refreshQuestionType, refreshStruct } from '../index'; import Tabs from '../../../components/Tabs'; import { TimeRange, QuestionType } from '../../../../Constant'; import { My } from '../../../stores/my'; import { Main } from '../../../stores/main'; import { Question } from '../../../stores/question'; const QuestionnTypeMap = getMap(QuestionType, 'value', 'label'); export default class extends Page { constructor(props) { props.size = 10; super(props); this.columns = [ { key: 'title', title: '练习册名称', fixSort: true }, { key: 'create_time', title: '做题时间', fixSort: true, render: (text, row, index) => { return (
2019-12-12 {row.children && ( {row.children.map((child, i) => { return ( {row.children.length - i} 2019-12-12 13:13:13 3/20 this.onChangeShowHistory(index, i, e.target.checked)} /> ); })} } > )}
13:13:13
); }, }, { key: 'correct', title: '正确率', sort: true }, { key: 'time', title: '平均耗时', sort: true }, { key: 'progress', title: '完成度' }, { key: 'report', title: '报告', render() { return ; }, }, ]; Main.getExaminationNumber().then(nums => { this.nums = nums; this.setState({ load: false }); }); } initState() { return { tab: 'exercise', timerange: 'today', filterMap: {}, sortMap: {}, list: [], // { children: [{}, {}], title: 'channgnanjue' }, {}, {}, {} selectList: [], allChecked: false, }; } init() { this.exerciseColumns = [ { key: 'title', title: '练习册名称', fixSort: true, // render: (text, record) => { // const { reports } = record; // return reports.map((report, index) => { // return
{index === 0 && text}
; // }); // }, }, { key: 'latest_time', title: '做题时间', fixSort: true, render: (text, record, index, childIndex) => { const { reports, show } = record; const report = childIndex === -1 ? reports[0] : record; const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss'); return
{time.split(' ')[0]} {childIndex === -1 && reports && reports.length > 1 && ( {reports.map((child, ii) => { if (ii === 0) return null; return {reports.length - ii} {formatDate(child.updateTime, 'YYYY-MM-DD HH:mm:ss')} {child.userNumber}/{child.questionNumber} = 0} onChange={e => this.onChangeShowHistory(index, ii, e.target.checked)} /> ; })} } > )}
{time.split(' ')[1]}
; }, }, { key: 'correct', title: '正确率', sort: true, render: (text, record, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; const user = formatPercent(report.userCorrect, report.userNumber); const all = formatPercent(record.stat.totalCorrect, record.stat.totalNumber); return
{user}% all ? 'up' : 'down'} />
全站{all}%
; }, }, { key: 'time', title: '平均耗时', sort: true, render: (text, record, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; const user = report.userTime / report.userNumber; const all = record.stat.totalTime / record.stat.totalNumber; return
{formatSeconds(user)} all ? 'up' : 'down'} />
全站{formatSeconds(all)}
; }, }, { key: 'progress', title: '完成度', render: (text, record, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; return (
{formatPercent(report.userNumber, report.questionNumber, false)}
); }, }, { key: 'report', title: '报告', render: (text, record, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; return (
{ Question.reportLink({ report }); }} />
); }, }, ]; this.examinationColumns = [ { key: 'title', title: '模考名称', fixSort: true }, { key: 'latest_time', title: '做题时间', fixSort: true, render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss'); return (
{time.split(' ')[0]}
{time.split(' ')[1]}
); }, }, { key: 'overall', title: 'Overall', render: (text, record) => { const [report] = record.reports; if (!report) return null; if (!report.qxCat) { return (
仅CAT模考
提供分数
); } return (
{report.score.totalScore}
{record.qxCat === 1 ? Math.round(record.origin.totalScore / record.origin.totalTimes) : Math.round(record.origin.secondTotalScore / record.origin.secondTotalTimes)}
); }, }, { key: 'verbal', title: 'Verbal', render: (text, record) => { const [report] = record.reports; if (!report) return null; if (!report.qxCat) { return (
{formatPercent(report.setting.number.verbal, this.nums.verbal.number, false)}
); } return (
{report.score.verbalScore}
{record.qxCat === 1 ? Math.round(record.origin.verbalScore / record.origin.totalTimes) : Math.round(record.origin.secondVerbalScore / record.origin.secondTotalTimes)}
); }, }, { key: 'quant', title: 'Quant', render: (text, record) => { const [report] = record.reports; if (!report) return null; if (!report.qxCat) { return (
{formatPercent(report.setting.number.quant, this.nums.quant.number, false)}
); } return (
{report.score.quantScore}
{record.qxCat === 1 ? Math.round(record.origin.quantScore / record.origin.totalTimes) : Math.round(record.origin.secondQuantScore / record.origin.secondTotalTimes)}
); }, }, { key: 'ir', title: 'IR', render: (text, record) => { const [report] = record.reports; if (!report) return null; if (!report.qxCat) { return
{formatPercent(report.setting.number.ir, this.nums.ir.number, false)}
; } return (
{report.score.irScore}
{record.qxCat === 1 ? Math.round(record.origin.irScore / record.origin.totalTimes) : Math.round(record.origin.secondIrScore / record.origin.secondTotalTimes)}
); }, }, { key: 'report', title: '报告', render: (text, record) => { const [report] = record.reports; return ( { Question.reportLink({ report }); }} /> ); }, }, ]; this.originColumns = [ { key: 'title', title: '名称', fixSort: true, render: (text) => { return
{text}
; }, }, { key: 'latest_time', title: '做题时间', fixSort: true, render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss'); return (
{time.split(' ')[0]}
{time.split(' ')[1]}
); }, }, { key: 'questionType', title: '题型', render: (text, record) => { return record.questionTypes.map(row =>

{QuestionnTypeMap[row]}

); }, }, { key: 'progress', title: '完成度', render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; return (
{formatPercent(report.userNumber, report.questionNumber, false)}
{report.userNumber}/{report.questionNumber}
); }, }, { key: 'correct', title: '正确率', sort: true, render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; return (
{formatPercent(report.userCorrect, report.userNumber, false)}
); }, }, { key: 'time', title: '平均耗时', sort: true, render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; return (
{formatSeconds(report.userTime / report.userNumber)}
); }, }, { key: 'report', title: '报告', render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; return (
{ Question.reportLink({ report }); }} />
); }, }, ]; } initData() { const data = Object.assign(this.state, this.state.search); data.filterMap = this.state.search; if (data.order) { data.sortMap = { [data.order]: data.direction }; } else { data.sortMap = { latest_time: 'desc' }; } if (data.timerange) { data.filterMap.timerange = data.timerange; } const [startTime, endTime] = timeRange(data.timerange); switch (data.tab) { case 'error': case 'collect': My.listReport( Object.assign({ origin: data.tab, startTime, endTime }, this.state.search, { order: Object.keys(data.sortMap) .map(key => { return `${key} ${data.sortMap[key]}`; }) .join(','), }), ).then(result => { result.list = result.list.map(row => { row.questionTypes = row.questionTypes || []; row.reports = row.reports || []; row.stat = row.stat || {}; return row; }); this.setState({ list: result.list, total: result.total, page: data.page, columns: this.originColumns }); }); break; case 'exercise': case 'examination': default: refreshQuestionType(this, data.subject, data.questionType, { all: true, needSentence: true, allSubject: true, }).then(({ questionTypes }) => { return refreshStruct(this, questionTypes, data.tab, data.one, data.two, { all: true, needPreview: true, needTextbook: false, }).then(({ structIds, courseModules }) => { My.listReport( Object.assign( { module: data.tab, questionTypes, structIds, courseModules, startTime, endTime }, this.state.search, { order: Object.keys(data.sortMap) .map(key => { return `${key} ${data.sortMap[key]}`; }) .join(','), }, ), ).then(result => { result.list = result.list.map(row => { row.questionTypes = row.questionTypes || []; row.reports = row.reports || []; row.stat = row.stat || {}; row.reports.forEach(r => { r.stat = row.stat; }); row.children = []; row.show = []; return row; }); this.setState({ list: result.list, total: result.total, page: data.page, columns: data.tab === 'exercise' ? this.exerciseColumns : this.examinationColumns, }); }); }); }); } } onChangeShowHistory(index, childIndex, checked) { const { list } = this.state; const item = list[index]; const { reports } = item; const { children } = item; const show = children.map(row => row.id); const childId = reports[childIndex].id; // 第一个不允许切换 if (checked) { if (show.indexOf(childId) >= 0) return; children.push(reports[childIndex]); } else { const k = show.indexOf(childId); if (k < 0) return; children.splice(k, 1); } list[index].children = children; list[index].show = children.map(row => row.id); this.setState({ list }); } onTabChange(tab) { const data = { tab }; this.refreshQuery(data); } onFilter(value) { this.search(value, false); this.initData(); } onSearch(value) { this.search({ keyword: value }, false); this.initData(); } onSort(value) { const keys = Object.keys(value); // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null }); const { sortMap } = this.state; const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0; this.search({ order: keys.length && value[keys[index]] ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }, false); this.initData(); } onChangePage(page) { this.search({ page }, false); this.initData(); } renderView() { const { config } = this.props; return ; } renderTable() { const { tab, questionSubjectSelect, questionSubjectMap = {}, oneSelect, twoSelectMap = {}, filterMap = {}, sortMap = {}, list = [], } = this.state; const { page, total, columns } = this.state; const selectList = []; if (tab === 'exercise') { selectList.push({ children: [ { key: 'subject', placeholder: '学科', select: questionSubjectSelect, }, { placeholder: '题型', key: 'questionType', be: 'subject', selectMap: questionSubjectMap, }, ], }); } if (tab === 'exercise' || tab === 'examination') { selectList.push({ label: '范围', children: [ { key: 'one', placeholder: '全部', select: oneSelect, }, { key: 'two', be: 'one', placeholder: '全部', selectMap: twoSelectMap, }, ], }); } selectList.push({ right: true, key: 'timerange', select: TimeRange, }); return (
this.onTabChange(key)} /> this.onFilter(value)} onChange={key => this.onChangeTab(key)} onSearch={value => this.onSearch(value)} /> this.onSelect(l)} onSort={v => this.onSort(v)} onChange={p => this.onChangePage(p)} />
); } }