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 基本信息
宣传信息
资料文件