import React from 'react'; import { Link } from 'react-router-dom'; import moment from 'moment'; import { Form, Input, Button, Row, Col, InputNumber, Upload, DatePicker, Checkbox, 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 Select from '@src/components/Select'; 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, CourseVideoType } 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, title: file.name.split('.')[0] }); }).then(() => { this.refreshNo(); })} > ; }, }]; this.noColumns = [{ title: '课程序号', dataIndex: 'no', }, { title: '名称', dataIndex: 'title', render: (text, record) => { return { this.changeNo('title', record, v); }} />; }, }, { title: '时长', dataIndex: 'time', render: (text) => { return formatSeconds(text); }, }, { title: '视频地址', dataIndex: 'resource', render: (text) => { return 访问; }, }, { title: '试用视频', dataIndex: 'isTrail', render: (text, record) => { return
{ this.changeNo('isTrail', record, v.target.checked ? 1 : 0); }} /> {text > 0 && { this.changeNo('startTrail', record, v); }} />} {text > 0 && { this.changeNo('endTrail', record, v); }} />} {text > 0 && System.uploadVideo(file).then((result) => { return this.changeNo('trailResource', record, result.url); })} > }
; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { const { total } = this.state; return
{record.no > 1 && ( { this.changeNo('no', record, record.no - 1); }}>上移 )} {record.no <= total && ( { this.changeNo('no', record, 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 || 0}; }, }, { title: '状态', dataIndex: 'status', render: (text, record) => { let status = 0; const start = new Date(record.startTime); const end = new Date(record.endTime); if (new Date().getTime() > start.getTime()) { status = 1; if (new Date().getTime() > end.getTime()) { status = 2; } } return CourseStatusMap[status] || status; }, }]; Exercise.courseStruct().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; const { module } = this.state.search; let handler; if (id) { handler = Course.get({ id }); } else { handler = Promise.resolve({ structId: '', courseModule: module, expireDays: 180 }); } handler .then(result => { this.setState({ module: result.courseModule }); const { form } = this.props; result.structId = `${result.structId}`; form.setFieldsValue(result); if (id) { switch (result.courseModule) { case 'video': this.refreshNo(); break; case 'online': this.refreshTime(); 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, record, value) { Course.editNo({ id: record.id, [field]: value, courseId: record.courseId }).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(); }); } 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, getFieldValue, setFieldsValue } = this.props.form; const structIdConfig = { rules: [{ required: true, message: '请选择学科', }], }; if (data.structId) { structIdConfig.initialValue = data.structId; } const cover = getFieldValue('cover'); return
{getFieldDecorator('id')()} {exercise && data && {getFieldDecorator('structId', structIdConfig)( , )} } {getFieldDecorator('videoType', { rules: [ { required: true, message: '请选择' }, ], })( , )} {getFieldDecorator('expireDays', { rules: [ { required: true, message: '请输入有效期' }, ], })( , )} {getFieldDecorator('useExpireDays', { rules: [ { required: true, message: '请输入有效期' }, ], })( , )} {getFieldDecorator('teacher', { 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
}
, )}
; } 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; const structIdConfig = { rules: [{ required: true, message: '请选择学科', }], }; if (data.structId) { structIdConfig.initialValue = data.structId; } return
{getFieldDecorator('id')()} {exercise && {getFieldDecorator('structId', structIdConfig)( , )} } {getFieldDecorator('title', { rules: [ { required: true, message: '请输入课程名称' }, ], })( , )} {getFieldDecorator('askExtendDays', { 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 }); }} />
; } renderContent() { switch (this.state.module) { case 'online': return [this.renderOnline(), this.renderTime()]; case 'video': return [this.renderVideo(), this.renderNo(), this.renderInfoVideo(), this.renderSyllabus(), this.renderPromote()]; default: return
; } } renderView() { return
{this.renderContent()}
; } }