page.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 { AnswerStatus, SwitchSelect, MoneyRange } from '../../../../Constant';
  12. import { User } from '../../../stores/user';
  13. import { Exercise } from '../../../stores/exercise';
  14. import { Course } from '../../../stores/course';
  15. const AnswerStatusMap = getMap(AnswerStatus, '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: AnswerStatus,
  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. key: 'time',
  72. type: 'daterange',
  73. name: '提问时间',
  74. }];
  75. this.columns = [{
  76. title: '学科',
  77. dataIndex: 'course.structId',
  78. render: (text, record) => {
  79. return `${record.course.parentStructId ? `${this.exerciseMap[record.course.parentStructId]}-` : ''}${this.exerciseMap[record.course.structId]}`;
  80. },
  81. }, {
  82. title: '课程',
  83. dataIndex: 'course.title',
  84. }, {
  85. title: '课时',
  86. dataIndex: 'courseNo.no',
  87. }, {
  88. title: '位置',
  89. dataIndex: 'position',
  90. render: (text) => {
  91. return `${text}`;
  92. },
  93. }, {
  94. title: '提问者',
  95. dataIndex: 'user.nickname',
  96. }, {
  97. title: '消费金额',
  98. dataIndex: 'user.totalMoney',
  99. }, {
  100. title: '提问时间',
  101. dataIndex: 'createTime',
  102. render: (text) => {
  103. return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : '';
  104. },
  105. }, {
  106. title: '倒计时',
  107. sorter: true,
  108. dataIndex: 'expireTime',
  109. render: (text, record) => {
  110. const end = new Date(record.answerTime) || new Date();
  111. const cost = (end.getTime() - new Date(record.createTime).getTime()) / 1000;
  112. if (text) {
  113. if (record.askTime - cost > 0) return `${formatSeconds(text - cost)}/${formatSeconds(text)}`;
  114. return `0/${formatSeconds(text)}`;
  115. }
  116. return '-';
  117. },
  118. }, {
  119. title: '回答者',
  120. dataIndex: 'manager.username',
  121. }, {
  122. title: '回答时间',
  123. sorter: true,
  124. dataIndex: 'answerTime',
  125. render: (text) => {
  126. return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : '';
  127. },
  128. }, {
  129. title: '回答状态',
  130. dataIndex: 'answerStatus',
  131. render: (text) => {
  132. return AnswerStatusMap[text] || text;
  133. },
  134. }, {
  135. title: '展示状态',
  136. dataIndex: 'showStatus',
  137. render: (text) => {
  138. return SwitchSelectMap[text] || text;
  139. },
  140. }, {
  141. title: '操作',
  142. dataIndex: 'handler',
  143. render: (text, record) => {
  144. return <div className="table-button">
  145. {(
  146. <Link to={`/student/ask/course/detail/${record.id}`}>编辑</Link>
  147. )}
  148. </div>;
  149. },
  150. }];
  151. bindSearch(this.filterForm, 'userId', this, (search) => {
  152. return User.list(search);
  153. }, (row) => {
  154. return {
  155. title: `${row.nickname}(${row.mobile})`,
  156. value: row.id,
  157. };
  158. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  159. Exercise.courseStruct().then((result) => {
  160. const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
  161. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  162. this.exerciseMap = getMap(result.map(row => {
  163. row.title = `${row.titleZh}`;
  164. row.value = row.id;
  165. return row;
  166. }), 'id', 'title');
  167. this.setState({ exercise: result });
  168. });
  169. Course.list().then((result) => {
  170. this.filterForm[1].select = result.list.map(row => {
  171. row.value = row.id;
  172. return row;
  173. });
  174. });
  175. }
  176. initData() {
  177. const { search } = this.state;
  178. const data = Object.assign({ hasRecord: true }, search);
  179. if (data.time) {
  180. data.startTime = data.time[0] || '';
  181. data.endTime = data.time[1] || '';
  182. }
  183. Course.listAsk(data).then(result => {
  184. this.setTableData(result.list, result.total);
  185. });
  186. }
  187. ignoreAction() {
  188. const { selectedKeys } = this.state;
  189. asyncDelConfirm('忽略确认', '是否忽略选中提问?', () => {
  190. return Promise.all(selectedKeys.map(row => User.editAsk({ id: row, ignoreStatus: 1 }))).then(() => {
  191. asyncSMessage('操作成功!');
  192. this.refresh();
  193. });
  194. });
  195. }
  196. renderView() {
  197. const { exercise } = this.state;
  198. return <Block flex>
  199. {exercise && <FilterLayout
  200. show
  201. itemList={this.filterForm}
  202. data={this.state.search}
  203. onChange={data => {
  204. if (data.time.length > 0) {
  205. data.time = [data.time[0].format('YYYY-MM-DD 00:00:00'), data.time[1].format('YYYY-MM-DD 23:59:59')];
  206. }
  207. data.page = 1;
  208. this.search(data);
  209. }} />}
  210. {/* <ActionLayout
  211. itemList={this.actionList}
  212. selectedKeys={this.state.selectedKeys}
  213. onAction={key => this.onAction(key)}
  214. /> */}
  215. <TableLayout
  216. columns={this.tableSort(this.columns)}
  217. list={this.state.list}
  218. pagination={this.state.page}
  219. loading={this.props.core.loading}
  220. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  221. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  222. selectedKeys={this.state.selectedKeys}
  223. />
  224. </Block>;
  225. }
  226. }