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: 'all', filterMap: {}, sortMap: {}, list: [], // { children: [{}, {}], title: 'channgnanjue' }, {}, {}, {} selectList: [], allChecked: false, defaultSortMap: { latest_time: 'desc' }, }; } init() { this.exerciseColumns = [ { key: 'title', title: '练习册名称', fixSort: true, render: (text, record) => { if (text) { if (QuestionnTypeMap[record.questionTypes[0]]) return `${QuestionnTypeMap[record.questionTypes[0]]}-${text}`; return `${text}`; } return ''; }, }, { key: 'latest_time', title: '做题时间', sort: 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 = Math.floor(report.userTime / report.userNumber); const all = Math.floor(record.stat.totalTime / record.stat.totalNumber); return
{formatSeconds(user)} all ? 'down' : 'up'} />
全站{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 }, true); }} />
); }, }, ]; this.examinationColumns = [ { key: 'title', title: '模考名称', fixSort: true }, { key: 'latest_time', title: '做题时间', sort: 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: 'overall', title: 'Overall', render: (text, record, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; if (!report) return null; if (!report.qxCat) { return (
仅CAT模考
提供分数
); } if (!report.score) return null; 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, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; if (!report) return null; if (!report.qxCat) { return (
{formatPercent(report.setting.real ? report.setting.real.verbal : report.setting.number.verbal, this.nums.verbal.number, false)}
); } if (!report.score) return null; 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, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; if (!report) return null; if (!report.qxCat) { return (
{formatPercent(report.setting.real ? report.setting.real.quant : report.setting.number.quant, false)}
); } if (!report.score) return null; 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, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; if (!report) return null; if (!report.qxCat) { return
{formatPercent(report.setting.real ? report.setting.real.ir : report.setting.number.ir, this.nums.ir.number, false)}
; } if (!report.score) return null; 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, index, childIndex) => { const { reports } = record; const report = childIndex === -1 ? reports[0] : record; return ( { Question.reportLink({ report }, true); }} /> ); }, }, ]; this.originColumns = [ { key: 'title', title: '名称', fixSort: true, render: (text) => { return
{text}
; }, }, { key: 'questionType', title: '题型', render: (text, record) => { return record.questionTypes.map(row =>

{QuestionnTypeMap[row]}

); }, }, { key: 'latest_time', title: '做题时间', sort: 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: '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: '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: 'report', title: '报告', render: (text, record) => { const { reports } = record; if (!reports) return null; const report = reports[0]; if (!report) return null; return (
{ Question.reportLink({ report }, true); }} />
); }, }, ]; } 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 if (data.order !== null && data.order !== '') { data.sortMap = Object.assign({}, this.state.defaultSortMap); } 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, onlyPreview: data.one === 'preview', }).then(({ questionTypes, selectSentence }) => { return refreshStruct(this, questionTypes, data.tab, data.one, data.two, { all: true, needPreview: true, needTextbook: false, selectSentence, }).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 => { if (key === 'title') return 'struct_three asc, struct_four asc, no asc'; 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({ page: 1, keyword: value }, false); this.initData(); } onSort(value) { const keys = Object.keys(value); const { sortMap, defaultSortMap } = this.state; const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0; let order = keys.length && value[keys[index]] ? keys[index] : null; let direction = keys.length ? value[keys[index]] : null; if (order == null) { const [prevOrder] = Object.keys(sortMap); console.log(defaultSortMap[prevOrder]); if (!defaultSortMap[prevOrder]) { [order] = Object.keys(defaultSortMap); direction = defaultSortMap[order]; } } this.search({ order, direction }, false); this.initData(); } onChangePage(page) { this.search({ page }, false); this.initData(); } renderView() { const { config } = this.props; return ; } renderTable() { const { tab, questionSubjectSelect, questionSubjectMap = {}, oneSelect, twoSelectMap = {}, oneSelectPlaceholder, twoSelectPlaceholder, 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: oneSelectPlaceholder, select: oneSelect, }, { key: 'two', be: 'one', placeholder: twoSelectPlaceholder, 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)} />
); } }