import React from 'react';
import { Form, Button, Row, Col, List, Icon, Switch, Typography, Input } from 'antd';
import './index.less';
import Editor from '@src/components/Editor';
import Page from '@src/containers/Page';
import Block from '@src/components/Block';
import DragList from '@src/components/DragList';
// import FileUpload from '@src/components/FileUpload';
import { formatFormError, formatDate, getMap } from '@src/services/Tools';
import { asyncSMessage } from '@src/services/AsyncTools';
import { PcUrl, AskTarget, QuestionType, AskModule } from '../../../../Constant';
// import { User } from '../../../stores/user';
import { Question } from '../../../stores/question';
const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
const AskTargetMap = getMap(AskTarget, 'value', 'label');
const AskModuleMap = getMap(AskModule, 'value', 'label');
export default class extends Page {
init() {
// Exercise.allStruct().then(result => {
// result = result.filter(row => row.level === 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
// this.setState({ exercise: result });
// });
}
initData() {
const { id } = this.params;
let handler;
if (id) {
handler = Question.getAsk({ id });
} else {
handler = Promise.resolve({ others: [] });
}
handler
.then(result => {
result.ignoreStatus = result.answerStatus === 2;
const { getFieldDecorator, setFieldsValue } = this.props.form;
getFieldDecorator('id');
getFieldDecorator('answer');
getFieldDecorator('showStatus');
getFieldDecorator('content');
setFieldsValue({ id: result.id, content: result.content, answer: result.answer, showStatus: result.showStatus });
this.setState({ data: result });
});
}
orderQuestion(oldIndex, newIndex) {
const { data } = this.state;
const { others = [] } = data;
const tmp = others.splice(oldIndex, 1);
if (newIndex === others.length) {
others.push(tmp[0]);
} else {
others.splice(newIndex, 0, tmp[0]);
}
this.setState({ others });
}
addOrder() {
const { data } = this.state;
const { others } = data;
others.push(data);
this.setState({ data });
}
removeOrder() {
const { data } = this.state;
const { others } = data;
data.others = others.filter(row => row.id !== data.id);
this.setState({ data });
}
submit() {
const { form } = this.props;
form.validateFields((err) => {
if (!err) {
const data = form.getFieldsValue();
data.showStatus = data.showStatus ? 1 : 0;
data.other = this.state.data.others.map(row => row.id);
Question.editAsk(data).then(() => {
asyncSMessage('保存成功');
}).catch((e) => {
if (e.result) form.setFields(formatFormError(data, e.result));
});
}
});
}
ignore() {
const { data } = this.state;
Question.editAsk({ id: data.id, ignoreStatus: 1 }).then(() => {
asyncSMessage('操作成功');
goBack();
});
}
renderBase() {
const { data } = this.state;
const { question = {}, questionNo = {} } = data;
return 题目信息
提问信息
该题目的展示中问题