import React from 'react';
import { Link } from 'react-router-dom';
import { Icon } from 'antd';
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.key = row.questionNoId;
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,
key: `${row.key}|${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, false);
this.initData();
}
onSearch(value) {
this.search({ 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 ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }, false);
}
onChangePage(page) {
this.search({ page }, false);
this.initData();
}
onAll(checked) {
const { selectList, contentSelectList } = this.state;
const { list = [] } = this.state;
if (checked) {
list.forEach(item => {
if (selectList.indexOf(item.key) < 0) {
selectList.push(item.key);
}
AskTarget.forEach((r) => {
if (!item[`${r.value}Content`]) return;
if (contentSelectList.indexOf(`${item.key}|${r.value}`) < 0) {
contentSelectList.push(`${item.key}|${r.value}`);
}
});
});
} else {
list.forEach(item => {
const index = selectList.indexOf(item.key);
if (index >= 0) {
selectList.splice(index, 1);
}
AskTarget.forEach((r) => {
if (!item[`${r.value}Content`]) return;
const i = contentSelectList.indexOf(`${item.key}|${r.value}`);
if (i >= 0) {
contentSelectList.splice(i, 1);
}
});
});
}
this.setState({ selectList, contentSelectList, allChecked: checked });
}
onSelect(selectList, key, checked) {
const { contentSelectList, list = [] } = this.state;
if (checked) {
const [item] = list.filter(row => row.key === key);
if (item) {
// 选中下面所有
AskTarget.forEach((r) => {
if (!item[`${r.value}Content`]) return;
if (contentSelectList.indexOf(`${item.key}|${r.value}`) < 0) {
contentSelectList.push(`${item.key}|${r.value}`);
}
});
}
} else {
const [item] = list.filter(row => row.key === key);
if (item) {
// 取消下面所有
AskTarget.forEach((r) => {
if (!item[`${r.value}Content`]) return;
const index = contentSelectList.indexOf(`${item.key}|${r.value}`);
if (index >= 0) {
contentSelectList.splice(index, 1);
}
});
}
}
this.setState({ selectList, contentSelectList, allCheckbox: false });
}
onSelectContent(contentSelectList, key, checked) {
const { selectList, list = [] } = this.state;
if (checked) {
const [questionNoIdStr] = key.split('|');
const questionNoId = Number(questionNoIdStr);
const [item] = list.filter(row => row.key === questionNoId);
if (item) {
// 选中上级
if (selectList.indexOf(item.key) < 0) {
selectList.push(item.key);
}
}
}
this.setState({ selectList, contentSelectList });
}
onAction(key) {
const { info } = this.props.user;
const { selectList, contentSelectList } = this.state;
const questionNoMap = {};
let questionNoIds;
switch (key) {
case 'help':
this.setState({ showTips: true });
return;
case 'clear':
if (selectList.length === 0 && contentSelectList === 0) {
this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1题,请重新选择' } });
return;
}
contentSelectList.forEach(row => {
const [questionNoIdStr, target] = row.split('|');
const questionNoId = Number(questionNoIdStr);
if (!questionNoMap[questionNoId]) {
questionNoMap[questionNoId] = { fields: 0 };
}
questionNoMap[questionNoId][target] = '';
questionNoMap[questionNoId].fields += 1;
});
questionNoIds = Object.keys(questionNoMap).filter(row => questionNoMap[row].fields < AskTarget.length);
if (questionNoIds.length > 0) {
Promise.all(questionNoIds.map(row => {
return My.updateQuestionNote(row, questionNoMap);
}))
.then(() => {
const clearList = Object.keys(questionNoMap).filter(row => questionNoMap[row].fields === AskTarget.length);
if (clearList.length > 0) {
this.clearNote(clearList);
} else {
this.refresh();
}
});
}
// this.setState({ showClearConfirm: true, clearInfo: { questionNoIds: selectList } });
break;
case 'export':
if (!info.vip) {
this.setState({ showVip: true });
return;
}
if (selectList.length < 1) {
this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于1题,请重新选择' } });
return;
}
if (selectList.length > 100) {
this.setState({ showWarn: true, warn: { title: '导出', content: '不可多余100题,请重新选择' } });
return;
}
contentSelectList.forEach(row => {
const [questionNoIdStr, target] = row.split('|');
const questionNoId = Number(questionNoIdStr);
if (!questionNoMap[questionNoId]) {
questionNoMap[questionNoId] = { fields: 0 };
}
questionNoMap[questionNoId][target] = '';
questionNoMap[questionNoId].fields += 1;
});
questionNoIds = Object.keys(questionNoMap);
this.setState({ showExportConfirm: true, exportInfo: { questionNoIds, questionNoMap } });
break;
default:
}
}
clearNote(list) {
My.clearQuestionNote(list)
.then(() => {
this.refresh();
})
.catch(e => {
this.setState({ showWarn: true, warn: { title: '移除', content: e.message }, showClearConfirm: false });
});
}
export() {
const { exportInfo } = this.state;
this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false });
My.exportNoteQuestion(exportInfo)
.then((result) => {
openLink(`/export/${result}`);
this.setState({ showExportWait: false });
})
.catch(e => {
this.setState({ showWarn: true, warn: { title: '导出', content: e.message }, showExportWait: 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)}
onSearch={value => this.onSearch(value)}
/>
this.onSort(value)}
onAll={checked => this.onAll(checked)}
onAction={key => this.onAction(key)}
/>
{list.map((item, index) => {
return (
this.onSelect(l, key, checked)}
header={false}
/>
this.onSelectContent(l, key, checked)}
header={index === 0}
/>
);
})}
{total > 0 && list.length > 0 && (
this.onChangePage(p)} />
)}
{this.renderModal()}
);
}
renderModal() {
const { showTips, showWarn, warn = {}, showClearConfirm, clearInfo = {}, showVip, showExamination, showReal, showExportWait, showExportConfirm, exportInfo = {} } = this.state;
const { info } = this.props.user;
return [
this.setState({ showTips: false })}>
组卷功能
操作数量:10-50;
注意事项:可跨题型、不可跨学科。
导出功能
操作数量:1-100;
注意事项:“综合推理IR”暂时无法导出。
*您可点击
查阅以上信息。
,
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 })}
/>,
];
}
}