import React from 'react'; import { Form, Button, Row, Col, Icon, Input, InputNumber, Upload } from 'antd'; import './index.less'; import Editor from '@src/components/Editor'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import Radio from '@src/components/Radio'; import TreeSelect from '@src/components/TreeSelect'; // import EditTableCell from '@src/components/EditTableCell'; // import ActionLayout from '@src/layouts/ActionLayout'; // import TableLayout from '@src/layouts/TableLayout'; import { formatFormError, formatTreeData, getMap } from '@src/services/Tools'; import { asyncSMessage } from '@src/services/AsyncTools'; import { SwitchSelect, DataType } from '../../../../Constant'; // import { User } from '../../../stores/user'; import { Exercise } from '../../../stores/exercise'; import { Course } from '../../../stores/course'; import { System } from '../../../stores/system'; export default class extends Page { init() { this.exerciseMap = {}; Exercise.dataStruct().then((result) => { const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; }); const tree = formatTreeData(list, 'id', 'title', 'parentId'); this.exerciseMap = getMap(result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; }), 'id'); this.setState({ exercise: tree }); }); } initData() { const { id } = this.params; let handler; if (id) { handler = Course.getData({ id }); } else { handler = Promise.resolve({ structId: '' }); } handler .then(result => { const { setFieldsValue } = this.props.form; result.structId = `${result.structId || ' '}`; setFieldsValue(result); this.setState({ data: result }); }); } submit() { const { form } = this.props; form.validateFields((err, values) => { console.log(values); if (!err) { const data = form.getFieldsValue(); data.parentStructId = this.exerciseMap[data.structId] ? this.exerciseMap[data.structId].parentId : 0; data.isSentence = this.exerciseMap[data.structId] ? (this.exerciseMap[data.structId].extend === 'sentence' ? 1 : 0) : 0; let handler; if (data.id) { handler = Course.editData(data); } else { data.courseModule = module; handler = Course.addData(data); } handler.then(() => { asyncSMessage('保存成功'); }).catch((e) => { if (e.result) form.setFields(formatFormError(data, e.result)); }); } }); } renderBase() { const { exercise, data } = this.state; const { getFieldDecorator } = this.props.form; const structIdConfig = { rules: [{ required: true, message: '请选择学科', }], }; if (data.structId) { structIdConfig.initialValue = data.structId; } return

基本信息

{getFieldDecorator('id')()} {exercise && data && {getFieldDecorator('structId', structIdConfig)( , )} } {getFieldDecorator('dataType', { rules: [{ required: true, message: '请选择类型', }], })( , )} {getFieldDecorator('isNovice', { rules: [{ required: true, message: '请选择', }], })( , )} {getFieldDecorator('isOriginal', { rules: [{ required: true, message: '请选择', }], })( , )} {getFieldDecorator('title', { rules: [{ required: true, message: '请输入名称', }], })( , )} {getFieldDecorator('price', { rules: [{ required: true, message: '请输入价格', }], })( , )} {getFieldDecorator('pages', { rules: [{ required: true, message: '请输入页数', }], })( , )} {getFieldDecorator('link', { rules: [{ required: true, message: '请输入地址', }], })( , )}
; } renderInfo() { const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form; const cover = getFieldValue('cover'); return

宣传信息

{getFieldDecorator('cover', { rules: [ { required: true, message: '上传图片' }, ], })( System.uploadImage(file).then((result) => { setFieldsValue({ cover: result.url }); return Promise.reject(); })} > {cover ? avatar :
Upload
}
, )}
{getFieldDecorator('description', { rules: [{ required: true, message: '请输入摘要', }], })( , )} {/* {getFieldDecorator('trailStart')( parseInt(v, 10) || 1} />, )} {getFieldDecorator('trailEnd')( parseInt(v, 10) || 1} />, )} */}
; } renderFile() { const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form; const resource = getFieldValue('resource'); const trailResource = getFieldValue('trailResource'); return

资料文件

{resource && 访问} {getFieldDecorator('resource', { rules: [ { required: true, message: '上传文件' }, ], })( System.uploadImage(file).then((result) => { setFieldsValue({ resource: result.url }); return Promise.reject(); })} > , )} {trailResource && 访问} {getFieldDecorator('trailResource', { rules: [ { required: true, message: '上传文件' }, ], })( System.uploadImage(file).then((result) => { setFieldsValue({ trailResource: result.url }); return Promise.reject(); })} > , )}
; } renderContent() { const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('content', { })( , )}
; } renderAuthor() { const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('authorContent', { })( , )}
; } renderMethod() { const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('methodContent', { })( , )}
; } renderView() { return
{this.renderBase()} {this.renderInfo()} {this.renderFile()} {this.renderContent()} {this.renderAuthor()} {this.renderMethod()}
; } }