import React from 'react';
import { Link } from 'react-router-dom';
import { Form, Input, Button, Row, Col, InputNumber, Upload, Card, Icon, Tabs, Spin } from 'antd';
import './index.less';
import Editor from '@src/components/Editor';
import Page from '@src/containers/Page';
import Block from '@src/components/Block';
// import FileUpload from '@src/components/FileUpload';
import { formatFormError } from '@src/services/Tools';
import { asyncSMessage } from '@src/services/AsyncTools';
import { CourseVsType } from '../../../../Constant';
import { Course } from '../../../stores/course';
import { System } from '../../../stores/system';
export default class extends Page {
init() {
this.state.tab = CourseVsType[0].value;
}
initData() {
this.changeCourse(this.state.tab);
}
changeCourse(key) {
this.setState({ tab: key, loading: true });
Course.list({ courseModule: 'vs' })
.then(result => {
const { form } = this.props;
const list = result.list.filter(row => row.vsType === key);
let row = {};
if (list.length > 0) {
([row] = list);
Course.get({ id: row.id }).then(r => {
form.setFieldsValue(r);
this.setState({ data: r, loading: false });
this.refreshTeacher(row.id);
});
} else {
form.resetFields();
this.setState({ data: { expireDays: 7 }, loading: false, teacher: false });
}
});
}
refreshTeacher(id) {
Course.listTeacher({ courseId: id }).then(result => {
this.setState({ teachers: result.list, total: result.total, teacher: true });
});
}
changeTeacher(field, index, value) {
const { teachers } = this.state;
teachers[index] = teachers[index] || {};
teachers[index][field] = value;
this.setState({ teachers });
}
addLength(key, data) {
this.state[key] = this.state[key] || [];
this.state[key].push(data);
this.setState({ [key]: this.state[key] });
}
deleteLength(key, start) {
this.state[key] = this.state[key] || [];
this.state[key].splice(start, 1);
this.setState({ [key]: this.state[key] });
}
submit() {
const { form } = this.props;
form.validateFields((err) => {
if (!err) {
const data = form.getFieldsValue();
data.vsType = this.state.tab;
data.parentStructId = 0;
data.structId = 0;
data.extend = '';
data.courseModule = 'vs';
let handler;
if (data.id) {
handler = Course.edit(data);
} else {
handler = Course.add(data);
}
handler.then(() => {
asyncSMessage('保存成功');
if (!data.id) {
this.setState({ teacher: true, teachers: [] });
}
}).catch((e) => {
if (e.result) form.setFields(formatFormError(data, e.result));
});
}
});
}
renderVs() {
const { getFieldDecorator, getFieldValue, setFieldsValue } = this.props.form;
const cover = getFieldValue('cover');
return 课程介绍
授课老师