import React from 'react';
import { Breadcrumb, Switch } from 'antd';
import './index.less';
import Page from '@src/containers/Page';
import { asyncConfirm, asyncSMessage } from '@src/services/AsyncTools';
import { formatPercent, formatSeconds, formatDate } from '@src/services/Tools';
import ListTable from '../../../components/ListTable';
import ProgressText from '../../../components/ProgressText';
import IconButton from '../../../components/IconButton';
import Button from '../../../components/Button';
import { DownloadModal } from '../../../components/OtherModal';
import { Question } from '../../../stores/question';
import { Textbook } from '../../../stores/textbook';
import Select from '../../../components/Select';
import { TextbookMinYear } from '../../../../Constant';
export default class extends Page {
initState() {
this.columns = [{
title: '练习册',
width: 250,
align: 'left',
render: (record) => {
let progress = 0;
if (record.report) {
progress = formatPercent(record.report.userNumber, record.report.questionNumber);
}
return (
);
},
}, {
title: '正确率',
width: 150,
align: 'left',
render: (record) => {
let correct = '--';
if (record.report) {
correct = formatPercent(record.report.userCorrect, record.report.userNumber, false);
}
return (
{correct}
全站{formatPercent(record.stat.totalCorrect, record.stat.totalNumber, false)}
);
},
}, {
title: '全站用时',
width: 150,
align: 'left',
render: (record) => {
let time = '--';
if (record.report) {
time = formatSeconds(record.report.userTime / record.report.userNumber);
}
return (
{time}
全站{formatSeconds(record.stat.totalTime / record.stat.totalNumber)}
);
},
}, {
title: '最近做题',
width: 150,
align: 'left',
render: (record) => {
const time = record.report ? record.report.updateTime : record.paper ? record.paper.latestTime : null;
return (
{time && formatDate(time, 'YYYY-MM-DD')}
{time && formatDate(time, 'HH:mm')}
);
},
}, {
title: '操作',
width: 180,
align: 'left',
render: (record) => {
return (
{!record.report && {
Question.startLink('exercise', record);
}} />}
{(record.report && !record.report.isFinish) && {
Question.continueLink('exercise', record);
}} />}
{(record.report) && {
this.restart(record);
}} />}
);
},
}, {
title: '报告',
width: 30,
align: 'right',
render: (record) => {
return (
{record.report && !!record.report.isFinish && {
Question.reportLink(record);
}} />}
);
},
}];
this.inited = false;
const year = [];
const nowYear = new Date().getFullYear();
for (let i = TextbookMinYear; i <= nowYear; i += 1) {
year.push({
title: i.toString(),
key: i.toString(),
});
}
return {
yearList: year,
};
}
initData() {
const { search } = this.state;
const info = {};
info.latest = search.latest ? Number(search.latest) : 0;
info.logic = search.logic ? search.logic : 'ds';
info.year = search.year ? search.year : new Date().getFullYear().toString();
const data = Object.assign(this.state, this.state.search);
data.info = info;
this.setState(data);
this.refreshData();
}
refreshData() {
Textbook.getInfo().then((result) => {
this.setState({ textbook: result });
});
this.refreshTextbook();
}
refreshTextbook() {
Textbook.listPaper(Object.assign({ year: new Date().getFullYear().toString() }, this.state.search, this.state.info))
.then((result) => {
this.setState({ list: result });
})
.catch(err => {
asyncSMessage(err.message, 'warn');
linkTo('/examination');
});
}
restart(item) {
asyncConfirm('提示', '你打算重做本套练习,过往做题记录可至「个人中心-报告」查看。', () => {
Question.restart(item.paper.id).then(() => {
this.refresh();
});
});
}
subscribe(value) {
Textbook.subscribe(value)
.then(() => {
this.refresh();
})
.catch(err => {
asyncSMessage(err.message, 'warn');
});
}
renderView() {
const { list, search, info = {}, textbook = {}, showDownload } = this.state;
const { finish } = search;
return (
模考
数学机经
{info.latest ? '最新' : '往期'}
{info.logic ? info.logic.toUpperCase() : ''}
{!!info.latest && !!textbook.latest &&
最近更新:{formatDate(textbook.latest.updateTime, 'YYYY-MM-DD')}
}
{!!info.latest && 邮箱订阅 {
this.subscribe(!textbook.subscribe);
}} />}
{!!info.latest && }
{!info.latest && }
filters={[
{
type: 'radio',
checked: finish,
list: [{ key: '0', title: '未完成' }, { key: '1', title: '已完成' }],
onChange: item => {
if (item.key === finish) {
this.search({ finish: null });
} else if (item.key === '0') {
this.search({ finish: 0 });
} else if (item.key === '1') {
this.search({ finish: 1 });
} else {
this.search({ finish: null });
}
},
},
]}
data={list}
columns={this.columns}
/>
this.setState({ showDownload: false })}
onCancel={() => this.setState({ showDownload: false })}
onClose={() => this.setState({ showDownload: false })}
/>
);
}
}