import React from 'react'; import { Link } from 'react-router-dom'; import './index.less'; import Page from '@src/containers/Page'; import { timeRange, getMap, formatDate } from '@src/services/Tools'; import UserLayout from '../../../layouts/User'; import UserTable from '../../../components/UserTable'; import UserAction from '../../../components/UserAction'; import UserPagination from '../../../components/UserPagination'; import { RealAuth } from '../../../components/OtherModal'; import Examination from '../../../components/Examination'; import VipRenew from '../../../components/VipRenew'; import Modal from '../../../components/Modal'; import menu, { refreshQuestionType, refreshStruct } from '../index'; import Tabs from '../../../components/Tabs'; import { TimeRange, QuestionType, AskTarget } from '../../../../Constant'; import { My } from '../../../stores/my'; import { OpenText } from '../../../components/Open'; const QuestionTypeMap = getMap(QuestionType, 'value', 'label'); const AskTargetMap = getMap(AskTarget, 'value', 'label'); const questionColumns = [ { key: 'questionType', width: 140, render(text, row) { return
{QuestionTypeMap[text]}
; }, }, { key: 'title', width: 100, render(text, row) { return
{text}
; }, }, { key: 'content', width: 540, render(text, row) { return
{text}
; }, }, ]; const contentColumns = [ { key: 'title', title: '笔记对象', width: 140, render(text) { return
{AskTargetMap[text]}
; }, }, { key: 'updateTime', title: '更新时间', width: 100, render(text) { return
{text.split(' ')[0]}
{text.split(' ')[1]}
; }, }, { key: 'content', title: '内容', width: 540, render(text) { return {text}; }, }, ]; export default class extends Page { constructor(props) { props.size = 10; super(props); } initState() { return { filterMap: {}, sortMap: {}, selectList: [], contentSelectList: [], allChecked: false, tab: 'exercise', timerange: 'today', }; } initData() { const data = Object.assign(this.state, this.state.search); data.filterMap = this.state.search; if (data.order) { data.sortMap = { [data.order]: data.direction }; } if (data.timerange) { data.filterMap.timerange = data.timerange; } const [startTime, endTime] = timeRange(data.timerange); refreshQuestionType(this, data.subject, data.questionType, { all: true, needSentence: false, allSubject: true, }).then(({ questionTypes }) => { return refreshStruct(this, data.tab, data.one, data.two, { all: true, needPreview: false, needTextbook: false, }).then(({ structIds, latest, year }) => { My.listQuestionNote( Object.assign( { module: data.tab, questionTypes, structIds, latest, year, 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.group = true; row.questionType = row.question.questionType; row.title = row.questionNo.title; row.content = row.question.description; row.list = []; AskTarget.forEach((r) => { if (!row[`${r.value}Content`]) return; row.list.push({ title: r.value, updateTime: formatDate(row[`${r.value}Time`], 'YYYY-MM-DD HH:mm:ss'), content: row[`${r.value}Content`], }); }); return row; }); this.setState({ list: result.list, total: result.total, page: data.page }); }); }); }); } onTabChange(tab) { const data = { tab }; this.refreshQuery(data); } onFilter(value) { this.search(value); } 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 ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }); } onChangePage(page) { this.search({ page }); } onAll(checked) { if (checked) { const { data = [] } = this.state; const list = []; data.forEach(item => { list.push(item.key); }); this.setState({ selectList: list, allChecked: true }); } else { this.setState({ selectList: [], allChecked: false }); } } onSelect(selectList) { this.setState({ selectList }); } onAction(key) { const { info } = this.props.user; const { selectList } = this.state; switch (key) { case 'help': this.setState({ showTips: true }); return; case 'clear': if (selectList.length === 0) { this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1题,请重新选择' } }); return; } // this.clearNote(); this.setState({ showClearConfirm: true, clearInfo: { questionNoIds: selectList } }); break; case 'export': if (!info.vip) { this.setState({ showVip: true }); return; } if (selectList.length < 0) { this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于10题,请重新选择' } }); return; } if (selectList.length > 100) { this.setState({ showWarn: true, warn: { title: '导出', content: '不可多余100题,请重新选择' } }); return; } this.setState({ showExportConfirm: true, exportInfo: { questionNoIds: selectList } }); break; default: } } clearNote() { const { clearInfo } = this.state; My.clearQuestionNote(clearInfo.questionNoIds) .then(() => { this.refresh(); }) .catch(e => { this.setState({ warn: { title: '移除', content: e.message }, showClearConfirm: false }); }); } renderView() { const { config } = this.props; return ; } renderTable() { const { tab, questionSubjectSelect, questionSubjectMap = {}, oneSelect, twoSelectMap = {}, filterMap = {}, sortMap = {}, list = [], } = this.state; const { selectList = [], contentSelectList = [], allChecked, page, total } = this.state; const { info } = this.props.user; return (
this.onTabChange(key)} /> this.onFilter(value)} /> this.onSort(value)} onAll={checked => this.onAll(checked)} onAction={key => this.onAction(key)} /> {list.map((item, index) => { return (
); })} {total > 0 && list.length > 0 && ( this.onChangePage(p)} /> )} {this.renderModal()}
); } renderModal() { const { showWarn, warn = {}, showClearConfirm, clearInfo = {}, showVip, showExamination, showReal, showExportWait, showExportConfirm, exportInfo = {} } = this.state; const { info } = this.props.user; return [ this.setState({ showWarn: false })}>
{warn.content}
, this.clearNote()} onCancel={() => this.setState({ showClearConfirm: false })}>
当前选中的 {clearInfo.questionNoIds ? clearInfo.questionNoIds.length : 0} 道题即将被移出笔记,移出后无法恢复,是否继续?
, this.export()} onCancel={() => this.setState({ showExportConfirm: false })}>
当前共选中 {exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0} 道题笔记,是否开始导出:
, this.setState({ showExportWait: 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={() => this.setState({ showVip: false })} />, ]; } }