1
0

page.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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, formatDate, formatTreeData, formatSeconds } from '@src/services/Tools';
  10. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  11. import { AskStatus, SwitchSelect } from '../../../../Constant';
  12. import { User } from '../../../stores/user';
  13. import { Exercise } from '../../../stores/exercise';
  14. import { Course } from '../../../stores/course';
  15. import user from '../../user';
  16. const AskStatusMap = getMap(AskStatus, 'value', 'label');
  17. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  18. export default class extends Page {
  19. init() {
  20. // this.actionList = [{
  21. // key: 'ignore',
  22. // type: 'danger',
  23. // name: '批量忽略',
  24. // needSelect: 1,
  25. // }];
  26. this.exerciseMap = {};
  27. this.filterForm = [{
  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. allowClear: true,
  39. name: '课程',
  40. select: [],
  41. placeholder: '请选择',
  42. number: true,
  43. }, {
  44. key: 'answerStatus',
  45. type: 'select',
  46. allowClear: true,
  47. name: '回答状态',
  48. select: AskStatus,
  49. number: true,
  50. }, {
  51. key: 'showStatus',
  52. type: 'select',
  53. allowClear: true,
  54. name: '展示状态',
  55. select: SwitchSelect,
  56. }];
  57. this.columns = [
  58. {
  59. title: '学科',
  60. dataIndex: 'course.structId',
  61. render: (text, record) => {
  62. return `${record.course.parentStructId ? `${this.exerciseMap[record.course.parentStructId]}-` : ''}${this.exerciseMap[record.course.structId]}`;
  63. },
  64. },
  65. {
  66. title: '课程',
  67. dataIndex: 'course.title',
  68. },
  69. {
  70. title: '位置',
  71. dataIndex: 'position',
  72. render: (text, record) => {
  73. return `P${record.courseNo.no}:${text}`;
  74. },
  75. },
  76. {
  77. title: '提问摘要',
  78. dataIndex: 'content',
  79. }, {
  80. title: '提问者',
  81. dataIndex: 'user.nickname',
  82. }, {
  83. title: '承诺时间',
  84. dataIndex: 'user.askTime',
  85. render: (text, record) => {
  86. const cost = (new Date().getTime() - new Date(record.createTime).getTime()) / 1000;
  87. return user.askTime ? formatSeconds(user.askTime - cost) : '-';
  88. },
  89. }, {
  90. title: '回答状态',
  91. dataIndex: 'answerStatus',
  92. render: (text) => {
  93. return AskStatusMap[text] || text;
  94. },
  95. }, {
  96. title: '回答者',
  97. dataIndex: 'manager.username',
  98. }, {
  99. title: '回答时间',
  100. dataIndex: 'answerTime',
  101. render: (text) => {
  102. return text ? formatDate(text) : '';
  103. },
  104. }, {
  105. title: '展示状态',
  106. dataIndex: 'showStatus',
  107. render: (text) => {
  108. return SwitchSelectMap[text] || text;
  109. },
  110. }, {
  111. title: '操作',
  112. dataIndex: 'handler',
  113. render: (text, record) => {
  114. return <div className="table-button">
  115. {(
  116. <Link to={`/course/ask/detail/${record.id}`}>编辑</Link>
  117. )}
  118. </div>;
  119. },
  120. },
  121. ];
  122. Exercise.courseStruct().then((result) => {
  123. const list = result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  124. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  125. console.log(this.filterForm[0].tree);
  126. this.exerciseMap = getMap(result.map(row => {
  127. row.title = `${row.titleZh}/${row.titleEn}`;
  128. row.value = row.id;
  129. return row;
  130. }), 'id', 'title');
  131. this.setState({ exercise: result });
  132. });
  133. }
  134. initData() {
  135. Course.listAsk(this.state.search).then(result => {
  136. this.setTableData(result.list, result.total);
  137. });
  138. }
  139. ignoreAction() {
  140. const { selectedKeys } = this.state;
  141. asyncDelConfirm('忽略确认', '是否忽略选中提问?', () => {
  142. return Promise.all(selectedKeys.map(row => User.editAsk({ id: row, answerStatus: 2 }))).then(() => {
  143. asyncSMessage('操作成功!');
  144. this.refresh();
  145. });
  146. });
  147. }
  148. renderView() {
  149. const { exercise } = this.state;
  150. return <Block flex>
  151. {exercise && <FilterLayout
  152. show
  153. itemList={this.filterForm}
  154. data={this.state.search}
  155. onChange={data => {
  156. this.search(data);
  157. }} />}
  158. {/* <ActionLayout
  159. itemList={this.actionList}
  160. selectedKeys={this.state.selectedKeys}
  161. onAction={key => this.onAction(key)}
  162. /> */}
  163. <TableLayout
  164. select
  165. columns={this.columns}
  166. list={this.state.list}
  167. pagination={this.state.page}
  168. loading={this.props.core.loading}
  169. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  170. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  171. selectedKeys={this.state.selectedKeys}
  172. />
  173. </Block>;
  174. }
  175. }