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

题目信息

{AskModuleMap[data.askModule]} {QuestionTypeMap[question.questionType]} {questionNo.title}
; } renderAsk() { const { getFieldDecorator, getFieldValue } = this.props.form; const { data, editContent } = this.state; const { user = {}, createTime, target, originContent, content } = data; return

提问信息

{user.nickname} {formatDate(createTime, 'YYYY-MM-DD HH:mm:ss')} {AskTargetMap[target]} {originContent} {!editContent && content} {getFieldDecorator('content', { })( editContent ? : , )} { data.content = getFieldValue('content'); this.setState({ editContent: value, data }); }} />
; } renderQuestionList() { return

该题目的展示中问题

{ this.orderQuestion(oldIndex, newIndex); }} renderItem={(item) => ( , ]}> 问题: 答复: )} />
; } renderAnswer() { const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('id')()} {getFieldDecorator('answer', { })( , )} {getFieldDecorator('showStatus', { valuePropName: 'checked', })( { if (value) { this.addOrder(); } else { this.removeOrder(); } }} checkedChildren='on' unCheckedChildren='off' />, )}
; } renderView() { return
{this.renderBase()} {this.renderAsk()} {this.renderQuestionList()} {this.renderAnswer()}
; } }