import React from 'react'; import './index.less'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import { asyncSMessage } from '@src/services/AsyncTools'; import { formatDate, getMap } from '@src/services/Tools'; import UserLayout from '../../../layouts/User'; import UserAction from '../../../components/UserAction'; import menu from '../index'; import Tabs from '../../../components/Tabs'; import More from '../../../components/More'; import Button from '../../../components/Button'; import Switch from '../../../components/Switch'; import TotalSort from '../../../components/TotalSort'; import { RealAuth, TextbookFeedbackModal, FinishModal, CommentModal, FeedbackErrorDataModal } from '../../../components/OtherModal'; import Examination from '../../../components/Examination'; import VipRenew from '../../../components/VipRenew'; import Modal from '../../../components/Modal'; import UserTable from '../../../components/UserTable'; import UserPagination from '../../../components/UserPagination'; import { My } from '../../../stores/my'; import { User } from '../../../stores/user'; import { Order } from '../../../stores/order'; import { Textbook } from '../../../stores/textbook'; import { DataType, ServiceKey, RecordSource, TextbookFeedbackTarget } from '../../../../Constant'; import { Main } from '../../../stores/main'; import { Question } from '../../../stores/question'; const ServiceKeyMap = getMap(ServiceKey, 'value', 'label'); const RecordSourceMap = getMap(RecordSource, 'value', 'label'); const dataHistoryColumns = [ { title: '更新时间', key: 'time', width: 120 }, { title: '位置', key: 'position', width: 120 }, { title: '原内容', key: 'originContent', width: 120 }, { title: '更改为', key: 'content', width: 120 }, { title: '更新至', key: 'version', width: 90 }, ]; 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 }, ]; const openColumns = [ { title: '商品名称', key: 'title', width: 240 }, { title: '获取方式', key: 'source', width: 240 }, { title: '开通期限', key: 'endTime', width: 240 }, { title: '操作', key: 'handler', width: 90 }, ]; export default class extends Page { constructor(props) { props.size = 10; super(props); } initState() { return { tab: 'data', sortMap: {}, filterMap: {}, feedbackError: { position: ['', '', ''] }, }; } 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); const { tab } = this.state; switch (tab) { case 'textbook': this.refreshTextbook(); break; case 'examination': this.refreshExamination(); break; case 'vip': this.refreshVip(); break; case 'cal': break; case 'data': default: this.refreshData(); break; } } refreshTextbook() { Main.getService('textbook').then(result => { this.setState({ service: 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 }); }); } textbookHistory({ page, size, subject }) { Textbook.allHistory(subject).then(result => { this.setState({ showUpdate: true, 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' }, }); }); } refreshExamination() { Main.getService('qx_cat').then(result => { this.setState({ service: result }); }); Question.getExaminationInfo(result => { result.expireDay = result.expireTime && parseInt((new Date().getTime() - new Date(result.expireTime).getTime()) / 86400000, 10); this.setState({ data: result }); }); } refreshVip() { Main.getService('vip').then(result => { this.setState({ service: result }); }); My.getVipInfo().then(result => { this.setState({ data: result }); }); } recordList({ page, size, service, isUse, isExpire }) { Order.listRecord({ page, size, productType: 'service', service, isUse, isExpire }).then(result => { this.setState({ showUpdate: true, updateList: result.list.map(row => { row.title = ServiceKeyMap[service]; row.source = RecordSourceMap[row.source]; row.handler = ( { this.open(row.id); }} > 立即开通 ); row.endTime = `${formatDate(row.endTime, 'YYYY-MM-DD')} 前`; return row; }), updateTotal: result.list.length, updatePage: page, updateData: { page, size, service, isUse, columns: isUse ? [] : openColumns, type: 'record' }, }); }); } refreshData() { const dataTypeSelect = DataType.map(row => { row.title = row.label; row.key = row.value; return row; }); dataTypeSelect.unshift({ title: '全部', key: '', }); this.setState({ dataTypeSelect }); Main.dataStruct().then(result => { const structs = result .filter(row => row.level === 1) .map(row => { row.title = `${row.titleZh}${row.titleEn}`; row.key = `${row.id}`; return row; }); structs.unshift({ title: '全部', key: '', }); this.setState({ structs, }); }); My.listData(Object.assign({}, this.state.search)).then(result => { // result = { // list: [ // { // title: '123123', // latestTime: '', // id: 1, // number: 10, // version: '1231', // }, // ], // }; this.setState({ list: result.list.map(row => { row.time = formatDate(row.time, 'YYYY-MM-DD HH:mm:ss'); return row; }), total: result.total, page: this.state.search.page, }); }); } dataHistory({ dataId, page, size }) { My.listDataHistory({ page, size: 10000, dataId }).then(result => { result.list = result.list.map(row => { row.time = formatDate(row.time, 'YYYY-MM-DD\nHH:mm:ss'); return row; }); this.setState({ showUpdate: true, // 不显示分页 updateTotal: 0, maxHeight: 730, updateList: result.list, updatePage: page, updateData: { page, size, dataId, columns: dataHistoryColumns, type: 'data' }, }); }); } onFilter(value) { this.search(value); } onSort(value) { const { sortMap } = this.state; const keys = Object.keys(value); 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 }); } onTabChange(tab) { const data = { tab }; this.refreshQuery(data); } subscribeDataEmail(value) { My.subscribeDataEmail(value) .then(() => { const { info } = this.props.user; info.dataEmailSubscribe = value; User.infoHandle(info); }) .catch(err => { asyncSMessage(err.message, 'warn'); }); } cancelSubscribe(dataId) { My.subscribeData(dataId, false) .then(() => { this.refresh(); }); } open(recordId) { Order.useRecord(recordId).then(() => { this.refresh(); }); } buyTextbook() { User.needLogin() .then(() => { return Order.speedPay({ productType: 'service', service: 'textbook' }); }) .then((order) => { return User.needPay(order); }) .then(() => { this.refresh(); }); } buyQxCat() { User.needLogin() .then(() => { return Order.speedPay({ productType: 'service', service: 'qx_cat' }); }) .then((order) => { return User.needPay(order); }) .then(() => { this.refresh(); }); } renderView() { const { config } = this.props; return ; } renderDetail() { const { tab, comment = {}, feedback = {}, feedbackError = {}, showComment, showFinish, showUpdate, showFeedback, showFeedbackError, updateList, updateTotal, maxHeight, updateData = {}, showExamination, showReal, showVip, } = this.state; const { info } = this.props.user; return (
this.onTabChange(key)} /> {this[`renderTab${tab}`]()} 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({ showComment: false, comment: {}, showFinish: true })} onCancel={() => this.setState({ showComment: false, comment: {} })} onClose={() => this.setState({ showComment: false, comment: {} })} /> this.setState({ showFeedbackError: false, feedbackError: {}, showFinish: true })} onCancel={() => this.setState({ showFeedbackError: false, feedbackError: {} })} onClose={() => this.setState({ showFeedbackError: false, feedbackError: {} })} /> this.setState({ showFeedback: false, feedback: {}, showFinish: true })} onCancel={() => this.setState({ showFeedback: false, feedback: {} })} onClose={() => this.setState({ showFeedback: false, feedback: {} })} /> this.setState({ showFinish: false })} /> this.setState({ showExamination: false })} onCancel={() => this.setState({ showExamination: false })} onClose={() => this.setState({ showExamination: false })} /> this.setState({ showReal: false })} /> this.setState({ showVip: false, showReal: true })} onPrepare={() => this.setState({ showVip: false, showExamination: true })} onClose={(result) => { if (result) { this.refresh(); } else { this.setState({ showVip: false }); } }} />
); } renderTabdata() { const { list = [], filterMap = {}, sortMap = {}, structs, dataTypeSelect, total, page } = this.state; const { info } = this.props.user; return (
this.onFilter(value)} onSort={value => this.onSort(value)} right={
邮箱订阅{' '} { this.subscribeDataEmail(!info.dataEmailSubscribe); }} />
} />
{list.map(item => { return (
{}
版本{item.version} {item.title}
最新更新: {formatDate(item.latestTime, 'YYYY-MM-DD HH:mm:ss')}
{ const { key } = value; if (key === 'comment') { this.setState({ showComment: true, comment: { channel: 'course_data', position: item.id } }); } else if (key === 'update') { this.dataHistory({ dataId: item.id, page: 1, size: 10 }); } else if (key === 'feedback') { this.setState({ showFeedbackError: true, feedbackError: { dataId: item.id, title: item.title, position: ['', '', ''] } }); } else if (key === 'remove') { this.cancelSubscribe(item.id); } }} />
); })}
{total > 0 && list.length > 0 && ( this.onChangePage(p)} /> )}
); } renderTabtextbook() { const { data = {}, list = [], service } = this.state; const { latest = {}, day } = data; return (
最新换库 {latest.startDate ? formatDate(latest.startDate, 'YYYY-MM-DD') : ''} 已换库{day}
} right={ !data.hasService && data.unUseRecord && (
{ this.recordList({ page: 1, size: 10, service: 'textbook', isUse: false, isExpire: false }); }} >待开通
) } /> {data.hasService && (
{list.map(item => { return (
linkTo(`/textbook/topic/list/${item.subject}`)} />
已更新至{item.num}
{item.date}
{ 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: { questionSubject: item.subject, target: TextbookFeedbackTarget[0].value } }); } }} />
); })}
)} {!data.hasService && !data.unUseRecord && (
还未购买本月机经
¥ {service && service.package && service.package[0].price}
)} {/* {data.hasService && (
使用中
距离到期还有 {data.expireDay} 天
)} */} {!data.hasService && data.unUseRecord && (
请于{formatDate(data.unUseRecord.endTime, 'YYYY-MM-DD')}前开通
)} ); } renderTabexamination() { const { data = {}, service } = this.state; return (
{ this.recordList({ page: 1, size: 10, service: 'qx_cat', isUse: false, isExpire: false }); }} > 待开通
) } /> {!data.hasService && !data.unUseRecord && !data.expireTime && (
未购买
¥ {service && service.package && service.package[0].price}
)} {!data.hasService && data.unUseRecord && (
请于{formatDate(data.unUseRecord.endTime, 'YYYY-MM-DD')}前开通
)} {data.hasService && (
使用中
距离到期还有 {data.expireDay} 天
)} {!data.hasService && !data.unUseRecord && data.expireTime && (
已过期
{formatDate(data.startTime, 'YYYY-MM-DD')} ~ {formatDate(data.expireTime, 'YYYY-MM-DD')}
¥ {service && service.package && service.package[0].price}
)} ); } renderTabvip() { const { data } = this.state; return (
{!data.hasService && !data.unUseRecord && !data.expireTime && (
未购买
)} {data.hasService && (
使用中
{formatDate(data.expireTime, 'YYYY-MM-DD')} 到期
)} {!data.hasService && !data.unUseRecord && data.expireTime && (
已过期
{formatDate(data.startTime, 'YYYY-MM-DD')} ~ {formatDate(data.expireTime, 'YYYY-MM-DD')}
)}
); } renderTabcal() { const { data = {} } = this.state; return (
{ data.value = value; this.setState({ data }); }} />
); } }