123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- import React from 'react';
- import './index.less';
- import Page from '@src/containers/Page';
- import Block from '@src/components/Block';
- import FilterLayout from '@src/layouts/FilterLayout';
- import ActionLayout from '@src/layouts/ActionLayout';
- import TableLayout from '@src/layouts/TableLayout';
- import { formatDate, bindSearch, getMap } from '@src/services/Tools';
- import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
- import { CourseSource, CourseStatus, CourseVsType } from '../../../../Constant';
- import { Course } from '../../../stores/course';
- import { User } from '../../../stores/user';
- const CourseSourceMap = getMap(CourseSource, 'value', 'label');
- const CourseStatusMap = getMap(CourseStatus, 'value', 'label');
- const CourseVsTypeMap = getMap(CourseVsType, 'value', 'label');
- export default class extends Page {
- init() {
- this.onlineAction = [{
- key: 'info',
- name: '课程',
- render: () => {
- const { data } = this.state;
- return `${data.title}`;
- },
- }, {
- key: 'addOnlineStudent',
- name: '添加学员',
- }];
- this.onlineFilter = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'timeId',
- type: 'select',
- allowClear: true,
- select: [],
- number: true,
- name: '时间段',
- }, {
- key: 'userId',
- type: 'select',
- name: '学员',
- allowClear: true,
- select: [],
- number: true,
- placeholder: '请输入',
- }];
- this.onlineList = [{
- key: 'timeId',
- type: 'select',
- select: [],
- name: '时间段',
- }, {
- key: 'userIds',
- type: 'multiple',
- name: '学员',
- allowClear: true,
- select: [],
- number: true,
- placeholder: '请输入',
- }];
- this.onlineColumns = [{
- title: '时间段',
- dataIndex: 'time',
- render: (text) => {
- return `${formatDate(text.startTime, 'YYYY-MM-DD')}~${formatDate(text.endTime, 'YYYY-MM-DD')}`;
- },
- }, {
- title: '学员id',
- dataIndex: 'userId',
- }, {
- title: '学员名称',
- dataIndex: 'user.nickname',
- }, {
- title: '手机号',
- dataIndex: 'user.mobile',
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {<a onClick={() => {
- this.deleteOnlineStudent(record);
- }}>删除</a>}
- </div>;
- },
- }];
- this.vsAction = [{
- key: 'info',
- name: '课程',
- render: () => {
- const { data } = this.state;
- return `${data.title}(${CourseVsTypeMap[data.vsType]})`;
- },
- }, {
- key: 'addVsStudent',
- name: '添加学员',
- }];
- this.vsAddList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'userId',
- type: 'select',
- name: '学员',
- select: [],
- number: true,
- placeholder: '请输入',
- }, {
- key: 'teacherId',
- type: 'select',
- select: [],
- name: '老师',
- }, {
- key: 'number',
- type: 'number',
- name: '课时数',
- }, {
- key: 'cctalkName',
- type: 'input',
- name: 'CCTalk名',
- }];
- this.vsChangeList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'teacherId',
- type: 'select',
- required: true,
- select: [],
- name: '老师',
- }, {
- key: 'cctalkName',
- type: 'input',
- name: 'CCTalk名',
- }, {
- key: 'number',
- type: 'hidden',
- name: '课时数',
- }];
- this.vsColumns = [{
- title: '学员id',
- dataIndex: 'user.id',
- }, {
- title: '学员名称',
- dataIndex: 'user.nickname',
- render: (text, record) => {
- return `${text}(${record.user.mobile})`;
- },
- }, {
- title: '课时数',
- dataIndex: 'number',
- }, {
- title: '有效期',
- dataIndex: 'time',
- render: (text, record) => {
- return record.isUsed ? `${formatDate(record.useStartTime, 'YYYY-MM-DD')}~${formatDate(record.useEndTime, 'YYYY-MM-DD')}` : '';
- },
- }, {
- title: '添加方式',
- dataIndex: 'source',
- render: (text) => {
- return CourseSourceMap[text] || text;
- },
- }, {
- title: '授课老师',
- dataIndex: 'teacher.realname',
- }, {
- title: '状态',
- dataIndex: 'status',
- render: (text, record) => {
- let status = 0;
- if (record.isUsed) {
- const end = new Date(record.useEndTime);
- status = 1;
- if (new Date().getTime() > end.getTime()) {
- status = 2;
- }
- }
- return CourseStatusMap[status] || status;
- },
- }, {
- title: 'CCTalk用户名',
- dataIndex: 'cctalkName',
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {<a onClick={() => {
- this.changeVs(record);
- }}>修改</a>}
- </div>;
- },
- }];
- }
- initData() {
- const { id } = this.params;
- let handler;
- if (id) {
- handler = Course.get({ id });
- }
- handler
- .then(result => {
- this.setState({ module: result.courseModule });
- this.setState({ data: result });
- this.refresh();
- });
- }
- refresh() {
- const { id } = this.params;
- const { module } = this.state;
- switch (module) {
- case 'video':
- break;
- case 'online':
- bindSearch(this.onlineFilter, 'timeId', this, (search) => {
- return Course.listTime(Object.assign({ courseId: id }, search));
- }, (row) => {
- return {
- title: `${formatDate(row.startTime, 'YYYY-MM-DD')}~${formatDate(row.endTime, 'YYYY-MM-DD')}`,
- value: row.id,
- };
- }, this.state.search.timeId ? Number(this.state.search.timeId) : null, null);
- bindSearch(this.onlineFilter, 'userId', this, (search) => {
- return User.list(search);
- }, (row) => {
- return {
- title: `${row.nickname}(${row.mobile})`,
- value: row.id,
- };
- }, null, null);
- bindSearch(this.onlineList, 'timeId', this, (search) => {
- return Course.listTime(Object.assign({ courseId: id }, search));
- }, (row) => {
- return {
- title: `${formatDate(row.startTime, 'YYYY-MM-DD')}~${formatDate(row.endTime, 'YYYY-MM-DD')}`,
- value: row.id,
- };
- }, null, null);
- bindSearch(this.onlineList, 'userIds', this, (search) => {
- return User.list(search);
- }, (row) => {
- return {
- title: `${row.nickname}(${row.mobile})`,
- value: row.id,
- };
- }, null, null);
- this.refreshOnline();
- break;
- case 'vs':
- this.refreshVs();
- break;
- default:
- }
- }
- refreshOnline() {
- const { id } = this.params;
- Course.listStudentOnline(Object.assign({ courseId: id }, this.state.search)).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- refreshVs() {
- const { id } = this.params;
- Course.listStudentVs(Object.assign({ courseId: id }, this.state.search)).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- addOnlineStudentAction() {
- const { id } = this.params;
- asyncForm('添加', this.onlineList, {}, data => {
- return Promise.all(data.userIds.map(userId => Course.addStudentOnline({ courseId: id, timeId: data.timeId, userId }))).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- }).catch(err => {
- console.log(err);
- });
- }
- deleteOnlineStudent(row) {
- Course.delStudentOnline({ id: row.id }).then(() => {
- asyncSMessage('删除成功!');
- this.refresh();
- });
- }
- addVsStudentAction() {
- const { id } = this.params;
- const { data } = this.state;
- this.vsAddList[3].type = data.vsType === 'novice' ? 'hidden' : 'number';
- asyncForm('添加', this.vsAddList, {}, info => {
- if (data.vsType === 'novice') {
- // 写死:新手每次1课时
- info.number = 1;
- }
- // ([info.useStartTime, info.useEndTime] = info.time);
- return Course.addStudentVs(Object.assign({ courseId: id }, info)).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- }).then(component => {
- bindSearch(this.vsAddList, 'userId', component, (search) => {
- return User.list(search);
- }, (row) => {
- return {
- title: `${row.nickname}(${row.mobile})`,
- value: row.id,
- };
- }, null, null);
- bindSearch(this.vsAddList, 'teacherId', component, (search) => {
- return Course.listTeacher(Object.assign({ courseId: id }, search));
- }, (row) => {
- return {
- title: row.realname,
- value: row.id,
- };
- }, null, null);
- });
- }
- changeVs(record) {
- const { id } = this.params;
- asyncForm('修改', this.vsChangeList, record, info => {
- // ([info.useStartTime, info.useEndTime] = info.time);
- return Course.editStudentVs(Object.assign({ courseId: id }, info)).then(() => {
- asyncSMessage('编辑成功!');
- this.refresh();
- });
- }).then(component => {
- bindSearch(this.vsChangeList, 'teacherId', component, (search) => {
- return Course.listTeacher(Object.assign({ courseId: id }, search));
- }, (row) => {
- return {
- title: row.realname,
- value: row.id,
- };
- }, record.teacherId, null);
- });
- }
- renderOnline() {
- return <Block flex>
- {<FilterLayout
- show
- itemList={this.onlineFilter}
- data={this.state.search}
- onChange={data => {
- data.page = 1;
- this.search(data);
- }} />}
- <ActionLayout
- itemList={this.onlineAction}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- columns={this.onlineColumns}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
- onSelect={(keys, rows) => this.tableSelect(keys, rows)}
- selectedKeys={this.state.selectedKeys}
- />
- </Block>;
- }
- renderVs() {
- return <Block flex>
- {<ActionLayout
- itemList={this.vsAction}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />}
- <TableLayout
- columns={this.vsColumns}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
- onSelect={(keys, rows) => this.tableSelect(keys, rows)}
- selectedKeys={this.state.selectedKeys}
- />
- </Block>;
- }
- renderView() {
- switch (this.state.module) {
- case 'online':
- return [this.renderOnline()];
- case 'vs':
- return [this.renderVs()];
- case 'video':
- return [];
- default:
- return <div />;
- }
- }
- }
|