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 } from '../../../../Constant'; import { Exercise } from '../../../stores/exercise'; import { Course } from '../../../stores/course'; export default class extends Page { init() { this.exerciseMap = {}; Exercise.courseStruct().then((result) => { this.exerciseMap = getMap(result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; }), 'id', 'title'); this.setState({ exercise: result }); }); } initData() { const { id } = this.params; let handler; if (id) { handler = Course.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 }); 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); Course.editAsk(data).then(() => { asyncSMessage('保存成功'); }).catch((e) => { if (e.result) form.setFields(formatFormError(data, e.result)); }); } }); } ignore() { const { data } = this.state; Course.editAsk({ id: data.id, ignoreStatus: 1 }).then(() => { asyncSMessage('操作成功'); goBack(); }); } renderBase() { const { data } = this.state; const { course = {} } = data; return

提问信息

{this.exerciseMap[course.structId]} {course.title}
; } renderAsk() { const { getFieldDecorator, getFieldValue } = this.props.form; const { data, editContent } = this.state; const { user = {}, createTime, courseNo = {}, position, originContent, content } = data; return

提问信息

{user.nickname} {formatDate(createTime, 'YYYY-MM-DD HH:mm:ss')} {`P${courseNo.no}:${position}-${position + 5}min`} {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()}
; } }