page.js 6.2 KB

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