page.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import FilterLayout from '@src/layouts/FilterLayout';
  7. // import ActionLayout from '@src/layouts/ActionLayout';
  8. import TableLayout from '@src/layouts/TableLayout';
  9. import { getMap, formatTreeData, formatDate, bindSearch } from '@src/services/Tools';
  10. import { asyncSMessage } from '@src/services/AsyncTools';
  11. import { CourseModule, CourseStatus } from '../../../../Constant';
  12. import { Course } from '../../../stores/course';
  13. import { Exercise } from '../../../stores/exercise';
  14. import { User } from '../../../stores/user';
  15. const CourseModuleMap = getMap(CourseModule, 'value', 'label');
  16. const CourseStatusMap = getMap(CourseStatus, 'value', 'label');
  17. export default class extends Page {
  18. constructor(props) {
  19. super(props);
  20. this.exerciseMap = {};
  21. this.filterForm = [{
  22. key: 'courseModule',
  23. type: 'select',
  24. name: '类型',
  25. allowClear: true,
  26. select: CourseModule,
  27. }, {
  28. key: 'structId',
  29. type: 'tree',
  30. allowClear: true,
  31. name: '学科',
  32. select: [],
  33. placeholder: '请选择',
  34. number: true,
  35. }, {
  36. key: 'courseId',
  37. type: 'select',
  38. name: '课程名称',
  39. allowClear: true,
  40. select: [],
  41. number: true,
  42. }, {
  43. key: 'userId',
  44. type: 'select',
  45. name: '学生',
  46. allowClear: true,
  47. select: [],
  48. number: true,
  49. }, {
  50. key: 'teacher',
  51. type: 'input',
  52. name: '老师',
  53. }];
  54. this.columns = [{
  55. title: '学生id',
  56. dataIndex: 'userId',
  57. render: (text, record) => {
  58. return `${text}/${record.user ? record.user.nickname : ''}`;
  59. },
  60. }, {
  61. title: '课程类型',
  62. dataIndex: 'course.courseModule',
  63. render: (text) => {
  64. return CourseModuleMap[text] || text;
  65. },
  66. }, {
  67. title: '课程名称',
  68. dataIndex: 'course.title',
  69. }, {
  70. title: '授课老师',
  71. dataIndex: 'teacher',
  72. render: (text, record) => {
  73. return text || record.course.teacher;
  74. },
  75. }, {
  76. title: '有效期',
  77. dataIndex: 'time',
  78. render: (text, record) => {
  79. return record.isUsed ? `${formatDate(record.useStartTime, 'YYYY-MM-DD')}~${formatDate(record.useEndTime, 'YYYY-MM-DD')}` : '';
  80. },
  81. }, {
  82. title: '上次学习时间',
  83. dataIndex: 'lastTime',
  84. render: (text) => {
  85. return text ? `${formatDate(text, 'YYYY-MM-DD HH:mm:ss')}` : '';
  86. },
  87. }, {
  88. title: '状态',
  89. dataIndex: 'status',
  90. render: (text, record) => {
  91. let status = 0;
  92. if (record.isUsed) {
  93. const end = new Date(record.useEndTime);
  94. status = 1;
  95. if (new Date().getTime() > end.getTime()) {
  96. status = 2;
  97. }
  98. }
  99. return CourseStatusMap[status] || status;
  100. },
  101. }, {
  102. title: '操作',
  103. dataIndex: 'handler',
  104. render: (text, record) => {
  105. return <div className="table-button">
  106. {<Link to={`/course/study/detail/${record.id}`}>查看</Link>}
  107. {record.isUsed > 0 && !record.isStop && (
  108. <a onClick={() => {
  109. this.stopAction(record.id);
  110. }}>停用</a>
  111. )}
  112. </div>;
  113. },
  114. }];
  115. Exercise.courseStruct().then((result) => {
  116. const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
  117. this.filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
  118. this.exerciseMap = getMap(result.map(row => {
  119. row.title = `${row.titleZh}`;
  120. row.value = row.id;
  121. return row;
  122. }), 'id', 'title');
  123. this.setState({ exercise: result });
  124. });
  125. bindSearch(this.filterForm, 'userId', this, (search) => {
  126. return User.list(search);
  127. }, (row) => {
  128. return {
  129. title: `${row.nickname}(${row.mobile})`,
  130. value: row.id,
  131. };
  132. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  133. bindSearch(this.filterForm, 'courseId', this, (search) => {
  134. return Course.list(search);
  135. }, (row) => {
  136. return {
  137. title: row.title,
  138. value: row.id,
  139. };
  140. }, this.state.search.courseId ? Number(this.state.search.courseId) : null, null);
  141. }
  142. init() {
  143. Course.list().then((result) => {
  144. this.filterForm[2].select = result.list.map(row => {
  145. row.value = row.id;
  146. return row;
  147. });
  148. });
  149. }
  150. initData() {
  151. Course.listStudy(this.state.search).then(result => {
  152. this.setTableData(result.list, result.total);
  153. });
  154. }
  155. stopAction(id) {
  156. return Course.editStudy({ id, isStop: 1 }).then(() => {
  157. asyncSMessage('停用成功!');
  158. this.refresh();
  159. });
  160. }
  161. renderView() {
  162. const { exercise } = this.state;
  163. return <Block flex>
  164. {exercise && <FilterLayout
  165. show
  166. itemList={this.filterForm}
  167. data={this.state.search}
  168. onChange={data => {
  169. data.page = 1;
  170. this.search(data);
  171. }} />}
  172. <TableLayout
  173. columns={this.tableSort(this.columns)}
  174. list={this.state.list}
  175. pagination={this.state.page}
  176. loading={this.props.core.loading}
  177. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  178. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  179. selectedKeys={this.state.selectedKeys}
  180. />
  181. </Block>;
  182. }
  183. }