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 Button from '../../../components/Button'; import UserTable from '../../../components/UserTable'; import UserAction from '../../../components/UserAction'; import UserPagination from '../../../components/UserPagination'; import Switch from '../../../components/Switch'; import menu, { refreshQuestionType, refreshStruct } from '../index'; import Tabs from '../../../components/Tabs'; import { TimeRange, AskTarget, QuestionType } from '../../../../Constant'; import { My } from '../../../stores/my'; import { OpenText } from '../../../components/Open'; const AskTargetMap = getMap(AskTarget, 'value', 'label'); const QuestionTypeMap = getMap(QuestionType, 'value', 'label'); const columns = [ { 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}
); }, }, ]; export default class extends Page { constructor(props) { props.size = 10; super(props); } initState() { return { filterMap: {}, sortMap: {}, list: [], selectList: [], 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, questionTypes, data.tab, data.one, data.two, { all: true, needPreview: false, needTextbook: true, }).then(({ structIds, latest, year }) => { My.listQuestionAsk( 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; 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, false); this.initData(); } onSearch(value) { this.search({ page: 1, keyword: value }, false); this.initData(); } 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 && value[keys[index]] ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }, false); this.initData(); } onChangePage(page) { this.search({ page }, false); this.initData(); } onAction() { } onSelect(selectList) { this.setState({ selectList }); } delAsk(id) { My.delQuestionAsk(id).then(() => { this.refresh(); }); } renderView() { const { config } = this.props; return ; } renderTable() { const { tab, questionSubjectSelect, questionSubjectMap = {}, oneSelect, twoSelectMap = {}, oneSelectPlaceholder, twoSelectPlaceholder, filterMap = {}, sortMap = {}, list = [], } = this.state; const { total, page } = this.state; return (
this.onTabChange(key)} /> this.onFilter(value)} onSearch={value => this.onSearch(value)} /> 只看已回答{' '} { filterMap.answerStatus = Number(filterMap.answerStatus) ? null : 1; this.onFilter(filterMap); }} />
} onSort={value => this.onSort(value)} /> {list.map(item => { return (
提问区域: {AskTargetMap[item.target]} {item.answerStatus === 0 && (
)}
提问
{formatDate(item.createTime, 'YYYY-MM-DD HH:mm:ss')}
{item.answerStatus > 0 && (
回答
{formatDate(item.answerTime, 'YYYY-MM-DD HH:mm:ss')}
)} {item.answerStatus > 0 && (
)}
); })} {total > 0 && list.length > 0 && ( this.onChangePage(p)} /> )}
); } }