import React from 'react'; import './index.less'; import Page from '@src/containers/Page'; import { formatDate, getMap } from '@src/services/Tools'; import UserAction from '../../../components/UserAction'; import UserPagination from '../../../components/UserPagination'; import Tabs from '../../../components/Tabs'; import { OpenText } from '../../../components/Open'; import { Button } from '../../../components/Button'; import { Course } from '../../../stores/course'; import { My } from '../../../stores/my'; export default class extends Page { constructor(props) { props.size = 10; super(props); } initState() { return { filterMap: {}, list: [], tab: 'special', answerSelect: [{ title: '全部', key: '' }, { title: '已回答', key: '1' }, { title: '未回答', key: '0' }], }; } init() { const { id } = this.params; Course.get(id).then(result => { const courseNoSelect = result.courseNos.map(row => { return { title: row.title, key: `${row.id}`, }; }); courseNoSelect.unshift({ title: '全部课时', key: '', }); const courseNoMap = getMap(result.courseNos, 'id'); const timelineSelect = [{ title: '全部区间', value: '' }]; const max = Math.max(result.courseNos.map(row => row.time)); let start = 0; let end = start + 5; while (start < max) { timelineSelect.push({ title: `${start}:00~${end}:00`, key: `${start}`, }); start += 5; end = Math.min(start + 5, max); } this.setState({ course: result, courseNoMap, courseNoSelect, timelineSelect }); }); } 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 'special': this.refreshSpecial(); break; case 'my': this.refreshMy(); break; default: break; } } refreshSpecial() { const { id } = this.params; this.setState({ orderSelect: [ { title: '无', key: '' }, { title: '时间轴', key: 'position' }, { title: '更新时间', key: 'updateTime' }, { title: '查看次数', key: 'viewNumber' }, ], }); // paixu Course.listAsk(Object.assign({ courseId: id }, this.state.search)).then(result => { // 只显示单个提问 if (this.state.search.askId) { const askId = Number(this.state.search.askId); result.list = result.list.filter(row => row.id === askId); } this.setState({ list: result.list, total: result.total }); }); } refreshMy() { const { id } = this.params; this.setState({ orderSelect: [ { title: '无', key: '' }, { title: '时间轴', key: 'position' }, { title: '更新时间', key: 'updateTime' }, ], }); My.listCourseAsk(Object.assign({ courseId: id }, this.state.search)).then(result => { this.setState({ list: result.list, total: result.total }); }); } onTabChange(tab) { const data = { tab }; this.refreshQuery(data); } onFilter(value) { this.search(value, false); this.initData(); } onSearch(value) { this.search({ keyword: value }, false); this.initData(); } onAction() { } delAsk(id) { My.delCourseAsk(id).then(() => { this.refresh(); }); } viewAsk(id) { Course.askView(id); } renderView() { const { course = {}, courseNoMap = {} } = this.state; const { tab, courseNoSelect, answerSelect, timelineSelect, orderSelect, filterMap = {}, list = [] } = this.state; const { total, page } = this.state; const selectActionList = [ { key: 'courseNoId', placeholder: '全部课时', select: courseNoSelect, }, ]; selectActionList.push({ key: 'order', placeholder: '排序', select: orderSelect, }); if (filterMap.order === 'position') { selectActionList.push({ key: 'position', placeholder: '时间区间', select: timelineSelect, }); } if (tab === 'my') { selectActionList.push({ key: 'answerStatus', placeholder: '状态', select: answerSelect, }); } return (