import React from 'react'; import { Link } from 'react-router-dom'; import moment from 'moment'; import { Form, Input, Button, Row, Col, InputNumber, Upload, DatePicker, Card, Icon } from 'antd'; import './index.less'; import Editor from '@src/components/Editor'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import TreeSelect from '@src/components/TreeSelect'; import EditTableCell from '@src/components/EditTableCell'; import Radio from '@src/components/Radio'; import ActionLayout from '@src/layouts/ActionLayout'; import TableLayout from '@src/layouts/TableLayout'; // import FileUpload from '@src/components/FileUpload'; import { formatFormError, formatSeconds, formatTreeData, getMap } from '@src/services/Tools'; import { asyncSMessage } from '@src/services/AsyncTools'; import { CrowdList, CourseStatus } from '../../../../Constant'; import { Course } from '../../../stores/course'; import { System } from '../../../stores/system'; import { Exercise } from '../../../stores/exercise'; const CourseStatusMap = getMap(CourseStatus, 'value', 'label'); export default class extends Page { init() { this.exerciseMap = {}; this.actionList = [{ key: 'add', type: 'primary', name: '上传视频', render: (item) => { return System.uploadVideo(file).then((result) => { return Course.addNo({ courseId: this.params.id, resource: result.url, time: result.time }); }).then(() => { this.refreshNo(); })} > ; }, }]; this.noColumns = [{ title: '课程序号', dataIndex: 'no', }, { title: '名称', dataIndex: 'title', render: (text, record) => { return { this.changeNo('title', record.id, v); }} />; }, }, { title: '时长', dataIndex: 'time', render: (text) => { return formatSeconds(text); }, }, { title: '视频地址', dataIndex: 'resource', render: (text) => { return 访问; }, }, { title: '试用区间', dataIndex: 'originContent', render: (text, record) => { return { this.changeNo('originContent', record.id, v); }} />; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { const { total } = this.state; return
{record.no > 1 && ( { this.changeNo('no', record.id, record.no - 1); }}>上移 )} {record.no <= total && ( { this.changeNo('no', record.id, record.no + 1); }}>下移 )} {( { this.delNo(record.id); }}>删除 )}
; }, }]; this.timeColumns = [{ title: '时间段', dataIndex: 'time', render: (text, record) => { return { this.changeTime(record.id, { startTime: value[0], endTime: value[1] }); }} />; }, }, { title: '学员数量', dataIndex: 'studentNumber', render: (text, record) => { return {text}; }, }, { title: '状态', dataIndex: 'status', render: (text) => { return CourseStatusMap[text] || text; }, }]; Exercise.courseStruct().then((result) => { const list = result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }); const tree = formatTreeData(list, 'id', 'title', 'parentId'); this.exerciseMap = getMap(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }), 'id'); this.setState({ exercise: tree }); }); } initData() { const { id } = this.params; const { module } = this.state.search; let handler; if (id) { handler = Course.get({ id }); } else { handler = Promise.resolve({ structId: 0, courseModule: module }); } handler .then(result => { this.setState({ module: result.courseModule }); const { form } = this.props; result.structId = `${result.structId}`; // baseContent: null // courseContent: null // courseNoContent: null // crowdContent: null // messageContent: null // pointContent: null // processContent: null // promoteContent: null // serviceContent: null // syllabusContent: null // teacherContent: null // form.getFieldDecorator('id'); // form.getFieldDecorator('structId'); // form.getFieldDecorator('parentStructId'); // form.getFieldDecorator('courseModule'); // form.getFieldDecorator('title'); // form.getFieldDecorator('price'); // form.getFieldDecorator('crowd'); // form.getFieldDecorator('teacher'); // form.getFieldDecorator('wechatAvatar'); // form.getFieldDecorator('minNumber'); // form.getFieldDecorator('maxNumber'); form.setFieldsValue(result); if (id) { switch (result.courseModule) { case 'video': this.refreshNo(); break; case 'online': this.refreshTime(); break; case 'vs': this.refreshTeacher(); break; default: } } this.setState({ data: result }); }); } refreshNo() { const { id } = this.params; Course.allNo({ courseId: id }).then(result => { this.setState({ list: result, total: result.length, no: true }); }); } changeNo(field, id, value) { Course.editNo({ id, [field]: value }).then(() => { this.refreshNo(); }); } delNo(id) { Course.delNo({ id }).then(() => { this.refreshNo(); }); } refreshTime() { const { id } = this.params; Course.listTime({ courseId: id }).then(result => { result.list = result.list.map(row => { row.startTime = moment(row.startTime); row.endTime = moment(row.endTime); return row; }); this.setState({ list: result.list, total: result.total, time: true }); }); } changeTime(id, data) { data.id = id; Course.editTime(data).then(() => { this.refreshTime(); }); } refreshTeacher() { const { id } = this.params; 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; const { module } = this.state; form.validateFields((err) => { if (!err) { const data = form.getFieldsValue(); data.parentStructId = this.exerciseMap[data.structId] ? this.exerciseMap[data.structId].parentId : 0; data.extend = this.exerciseMap[data.structId] ? this.exerciseMap[data.structId].extend : ''; let handler; if (data.id) { handler = Course.edit(data); } else { data.courseModule = module; handler = Course.add(data); } handler.then((result) => { asyncSMessage('保存成功'); if (data.id) { linkTo(`/course/detail/${data.id}`); } else { linkTo(`/course/detail/${result.id}`); } }).catch((e) => { if (e.result) form.setFields(formatFormError(data, e.result)); }); } }); } renderVideo() { const { exercise, data } = this.state; const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('id')()} {exercise && data.structId && {getFieldDecorator('structId', { rules: [{ required: true, message: '请选择学科', }], initialValue: data.structId, })( , )} } {getFieldDecorator('crowd', { rules: [ { required: true, message: '请选择' }, ], })( , )} {getFieldDecorator('price', { rules: [ { required: true, message: '请输入价格' }, ], })( , )} {getFieldDecorator('title', { rules: [ { required: true, message: '请输入课程名称' }, ], })( , )} {getFieldDecorator('teacher', { rules: [ { required: true, message: '请输入教师' }, ], })( , )}
; } renderNo() { const { no } = this.state; if (!no) return null; return

上传正式视频

this.onAction(key)} /> this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} />
; } renderInfoVideo() { const { getFieldDecorator } = this.props.form; return

课程介绍

{getFieldDecorator('teacherContent', { })( , )} {getFieldDecorator('baseContent', { })( , )} {getFieldDecorator('courseContent', { })( , )} {getFieldDecorator('pointContent', { })( , )} {getFieldDecorator('crowdContent', { })( , )}
; } renderSyllabus() { const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('syllabusContent', { })( , )}
; } renderPromote() { const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('promoteContent', { })( , )}
; } renderOnline() { const { exercise, data } = this.state; const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('id')()} {exercise && data.structId && {getFieldDecorator('structId', { rules: [{ required: true, message: '请选择学科', }], initialValue: data.structId, })( , )} } {getFieldDecorator('title', { rules: [ { required: true, message: '请输入课程名称' }, ], })( , )}
; } renderTime() { const { time, timerange } = this.state; if (!time) return null; return

课时管理

this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> { this.setState({ timerange: value }); }} />
; } renderVs() { const { exercise, data } = this.state; const { getFieldDecorator } = this.props.form; return
{getFieldDecorator('id')()} {exercise && data.structId && {getFieldDecorator('structId', { rules: [{ required: true, message: '请选择学科', }], initialValue: data.structId, })( , )} } {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('expireDays', { rules: [ { required: true, message: '请输入有效期' }, ], })( , )}
; } 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', { rules: [ { required: true, message: '上传图片' }, ], })( System.uploadImage(file).then((result) => { setFieldsValue({ wechatAvatar: result.url }); return Promise.reject(); })} > {image ? avatar :
Upload
}
, )}
; } renderTeacher() { const { teachers, teacher } = 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('qr', index, result.url); return Promise.reject(); })} > {row.qr ? avatar :
Upload
}
; })} { this.addLength('teachers', { realname: '', wechat: '', qr: '' }); }}>
; } renderContent() { switch (this.state.module) { case 'online': return [this.renderOnline(), this.renderTime()]; case 'vs': return [this.renderVs(), this.renderInfoVs(), this.renderTeacher()]; case 'video': return [this.renderVideo(), this.renderNo(), this.renderInfoVideo(), this.renderSyllabus(), this.renderPromote()]; default: return
; } } renderView() { return
{this.renderContent()}
; } }