import React from 'react';
import { Link } from 'react-router-dom';
import './index.less';
import Page from '@src/containers/Page';
import Assets from '@src/components/Assets';
import { getMap, formatDate } from '@src/services/Tools';
import { CommentModal, FaqModal, TextbookFeedbackModal, FinishModal } from '../../../components/OtherModal';
import { CommentFalls, AnswerCarousel, Consultation, Contact } from '../../../components/Other';
import Modal from '../../../components/Modal';
import Footer from '../../../components/Footer';
import Button from '../../../components/Button';
import UserTable from '../../../components/UserTable';
import Tabs from '../../../components/Tabs';
import { TextbookItem } from '../../../components/Item';
import { TwoDate } from '../../../components/Date';
import { Main } from '../../../stores/main';
import { Textbook } from '../../../stores/textbook';
import { Order } from '../../../stores/order';
import { User } from '../../../stores/user';
import { TextbookFeedbackTarget, TextbookSubject } from '../../../../Constant';
const textbookHistoryColumns = [
{
title: '更新时间',
key: 'createTime',
width: 120,
render: (text) => {
return
{text.split(' ')[0]}
{text.split(' ')[1]}
;
},
},
{ title: '版本', key: 'version', width: 120 },
{ title: '更新内容', key: 'content', width: 330 },
];
export default class extends Page {
initState() {
return {
tab: 'baselibrary',
list: [],
enroll: {},
load: 0,
subject: TextbookSubject[0].value,
textbookSubject: TextbookSubject.map(row => {
return {
title: row.label,
key: row.value,
};
}),
};
}
init() {
this.enrollMap = {};
this.libraryMap = {};
Main.getBase()
.then(result => {
this.setState({ base: result });
});
Textbook.getInfo().then((result) => {
const { latest } = result;
result.day = parseInt((new Date().getTime() - new Date(result.latest.startDate).getTime()) / 86400000, 10);
result.expireDay =
result.expireTime && parseInt((new Date(result.expireTime).getTime() - new Date().getTime()) / 86400000, 10);
const list = [];
list.push({ subject: 'quant', number: latest.quantNumber, time: latest.quantTime, version: latest.quantVersion });
list.push({ subject: 'rc', number: latest.rcNumber, time: latest.rcTime, version: latest.rcVersion });
list.push({ subject: 'ir', number: latest.irNumber, time: latest.irTime, version: latest.irVersion });
this.setState({ data: result, list });
if (!result.hasService && result.unUseRecord) {
this.textbookHistory({ subject: this.state.subject, showUpdate: false });
}
});
}
initData() {
this.refreshFaqs(this.state.tab);
this.refreshComments();
const start = new Date();
start.setMinutes(0, 0, 0);
start.setHours(0);
start.setDate(1);
start.setMonth(start.getMonth() - 2);
const end = new Date();
end.setMinutes(0, 0, 0);
end.setHours(0);
end.setDate(1);
end.setMonth(end.getMonth() + 4);
const startDate = formatDate(start, 'YYYY-MM-DD');
const endDate = formatDate(end, 'YYYY-MM-DD');
this.refreshEnroll(startDate, endDate);
this.setState({ startDate, endDate });
const nowYear = new Date().getFullYear();
this.refreshYear(nowYear);
if (nowYear > start.getFullYear()) {
this.refreshYear(nowYear - 1);
}
}
refreshFaqs(tab) {
Main.listFaq({ page: 1, size: 1000, channel: `library-${tab}` })
.then((result => {
this.setState({ faqs: result.list });
}));
}
refreshComments() {
Main.listComment({ page: 1, size: 1000, channel: 'library' })
.then(result => {
this.setState({ comments: result.list });
});
}
refreshEnroll(startDate, endDate) {
const month = formatDate(new Date(), 'YYYY-MM');
Textbook.listEnroll(startDate, endDate)
.then(result => {
result.times = result.times.map(row => {
row.month = formatDate(row.month, 'YYYY-MM');
if (row.month === month) {
// 本月机经开通人数
this.setState({ useNumber: row.useNumber });
}
return row;
});
this.enrollMap = getMap(result.times, 'month');
if (result.date) {
const d = new Date(result.date);
result.dateF = formatDate(d, 'YYYY-MM-DD');
result.day = parseInt((d.getTime() - new Date().getTime()) / 86400000, 10);
}
this.setState({ enroll: result, load: this.state.load + 1 });
});
}
refreshYear(year) {
Textbook.listYear(year)
.then(result => {
result = result.map(row => {
row.day = formatDate(row.startDate, 'YYYY-MM-DD');
this.libraryMap[row.day] = row;
return row;
});
this.setState({ library: result, load: this.state.load + 1 });
});
}
textbookHistory({ page, size, subject, showUpdate = true }) {
this.setState({ subject });
Textbook.allHistory(subject).then(result => {
this.setState({
showUpdate,
updateList: result.map(row => {
row.version = row[`${subject}Version`];
row.content = row[`${subject}Content`];
row.createTime = formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss');
return row;
}),
// 不显示分页
updateTotal: 0,
maxHeight: 730,
updatePage: page,
updateData: { page, size, subject, columns: textbookHistoryColumns, type: 'textbook' },
});
});
}
enroll() {
const { date, enroll } = this.state;
if (enroll.date) return;
if (!date) {
this.setState({ showWarn: true, warn: { title: '报名', content: '请先选择报考日期' } });
return;
}
User.needLogin()
.then(() => {
Textbook.enroll(date.format('YYYY-MM-DD'))
.then(() => {
enroll.date = new Date(date);
enroll.dateF = date.format('YYYY-MM-DD');
enroll.day = parseInt((enroll.date.getTime() - new Date().getTime()) / 86400000, 10);
this.setState({ showWarn: true, warn: { title: '报名', content: `已报考${formatDate(date, 'YYYY-MM-DD')}` } });
this.setState({ enroll });
});
});
}
unEnroll() {
const { enroll } = this.state;
if (!enroll.date) return;
User.needLogin()
.then(() => {
Textbook.unEnroll()
.then(() => {
this.setState({ enroll: {} });
});
});
}
onTabChange(key) {
this.refreshFaqs(key);
this.setState({ tab: key });
}
open(recordId) {
User.needLogin()
.then(() => {
Order.useRecord(recordId)
.then(() => {
this.refresh();
});
});
}
buy() {
User.needLogin()
.then(() => {
return Order.speedPay({ productType: 'service', service: 'textbook' });
})
.then((order) => {
return User.needPay(order);
})
.then(() => {
this.refresh();
});
}
renderView() {
const { data = {}, base = {}, tab, faqs = [], comments = [], showFaq, faq = {}, showFinish, showComment, comment = {}, showUpdate, updateData = {}, updateList = [], updateTotal, maxHeight, showFeedback, feedback = {}, showWarn, warn = {} } = this.state;
return (
{this.renderDate()}
{!data.hasService && data.unUseRecord && this.renderLog()}
{!data.hasService && !data.unUseRecord && this.renderCompare()}
{data.hasService && this.renderList()}
this.onTabChange(key)}
/>
this.setState({ showWarn: false })}>
{warn.content}
this.setState({ showUpdate: false, updateList: [] })}
>
{
updateData.page = page;
if (updateData.type === 'data') {
this.dataHistory(updateData);
} else if (updateData.type === 'textbook') {
this.textbookHistory(updateData);
} else if (updateData.type === 'record') {
this.recordList(updateData);
}
}}
total={updateTotal}
maxHeight={maxHeight}
/>
this.setState({ showFeedback: false, feedback: {}, showFinish: true })}
onCancel={() => this.setState({ showFeedback: false, feedback: {} })}
onClose={() => this.setState({ showFeedback: false, feedback: {} })}
/>
this.setState({ showComment: false, comment: {}, showFinish: true })}
onCancel={() => this.setState({ showComment: false, comment: {} })}
onClose={() => this.setState({ showComment: false, comment: {} })}
/>
this.setState({ showFaq: false, faq: {} })} onConfirm={() => this.setState({ showFaq: false, faq: {}, showFinish: true })} />
this.setState({ showFinish: false })}
/>
);
}
renderDate() {
const { data, enroll = {}, useNumber, startDate, endDate, load } = this.state;
const { latest = {}, day } = data;
return (
今日
换库
考试日
{enroll.date &&
{enroll.day > 0 ? `距离考试还有${enroll.day}天` : `距离考试已过去${enroll.day * -1}天`}
}
{enroll.date && }
{!enroll.date && }
按年份查看 >
{
const d = date.format('YYYY-MM-DD');
if (enroll.date && d === enroll.dateF) {
return 'type-2';
}
if (this.libraryMap[d]) {
return 'type-1';
}
return null;
}}
extendInfo={date => {
const d = date.format('YYYY-MM');
return `${this.enrollMap[d] ? this.enrollMap[d].enrollNumber : 0}人`;
}}
onChange={(date) => this.setState({ date })}
/>
最近换库
{latest.startDate ? formatDate(latest.startDate, 'YYYY-MM-DD') : ''}
已换库 {day} 天
本月共{useNumber || 0}人使用机经
);
}
renderList() {
const { list } = this.state;
return (
{list.map(item => {
return linkTo(`/textbook/topic/list/${item.subject}`)}
onMenuClick={value => {
const { key } = value;
if (key === 'comment') {
this.setState({ showComment: true, comment: { channel: 'library' } });
} else if (key === 'update') {
this.textbookHistory({ page: 1, size: 100, subject: item.subject });
} else if (key === 'feedback') {
this.setState({ showFeedback: true, feedback: { textbookSubject: item.subject, target: TextbookFeedbackTarget[0].value, no: '' } });
}
}} />;
})}
);
}
renderLog() {
const { data, subject, updateList, textbookSubject } = this.state;
return (
更新日志
this.textbookHistory({ subject: key, showUpdate: false })}
/>
this.open(data.unUseRecord.id)} />
);
}
renderCompare() {
return (
让机经帮上忙,而不是帮倒忙!
千行机经 |
其他机经 |
整理内容+梳理逻辑结构 |
只关注内容 |
最新版本自动更新至邮箱 |
手动领取 |
重视考场一手信息,越准越好 |
越多越好 |
独家资源,严格把关 |
市面资源 |
一键反馈,随时沟通 |
无售后系统 |
下载至本地、在线浏览、在线做题,多种查阅方式 |
下载至本地 |
);
}
}