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
{getFieldDecorator('id')()} {getFieldDecorator('title', { rules: [ { required: true, message: '请输入课程名称' }, ], })( , )} {getFieldDecorator('price', { rules: [ { required: true, message: '请输入价格' }, ], })( , )} {getFieldDecorator('minNumber', { rules: [ { required: true, message: '请输入最小购买数量' }, ], })( , )} {getFieldDecorator('maxNumber', { rules: [ { required: true, message: '请输入最大购买数量' }, ], })( , )} {getFieldDecorator('expirePreDays', { rules: [ { required: true, message: '请输入有效期' }, ], })( , )} {getFieldDecorator('expireDays', { rules: [ { required: true, message: '请输入有效期' }, ], })( , )} {getFieldDecorator('comment', { rules: [ { required: true, message: '请输入描述' }, ], })( , )} {getFieldDecorator('cover', { rules: [ { required: true, message: '上传图片' }, ], })( System.uploadImage(file).then((result) => { setFieldsValue({ cover: result.url }); return Promise.reject(); })} > {cover ? avatar :
Upload
}
, )}
; } renderInfoVs() { const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form; const image = getFieldValue('wechatAvatar') || null; return

课程介绍

{getFieldDecorator('serviceContent', { })( , )} {getFieldDecorator('crowdContent', { })( , )} {getFieldDecorator('courseNoContent', { })( , )} {getFieldDecorator('processContent', { })( , )} {getFieldDecorator('messageContent', { })( , )} {getFieldDecorator('wechatAvatar')( System.uploadImage(file).then((result) => { setFieldsValue({ wechatAvatar: result.url }); return Promise.reject(); })} > {image ? avatar :
Upload
}
, )}
; } renderTeacher() { const { teachers, teacher, data } = this.state; if (!teacher) return null; return

授课老师

{teachers.map((row, index) => { return { this.changeTeacher('realname', index, e.target.value); }} /> { this.changeTeacher('wechat', index, e.target.value); }} /> System.uploadImage(file).then((result) => { this.changeTeacher('avatar', index, result.url); return Promise.reject(); })} > {row.avatar ? avatar :
Upload
}
System.uploadImage(file).then((result) => { this.changeTeacher('qr', index, result.url); return Promise.reject(); })} > {row.qr ? avatar :
Upload
}
{ this.changeTeacher('description', index, e.target.value); }} />
; })} { this.addLength('teachers', { realname: '', wechat: '', qr: '' }); }}>
; } renderContent() { return [this.renderVs(), this.renderInfoVs(), this.renderTeacher()]; } renderView() { const { tab, data } = this.state; return
0 && 查看学员} onChange={(value) => { this.changeCourse(value); }}> {CourseVsType.map((row) => { return ; })} {this.renderContent()}
; } }