page.js 5.6 KB

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