page.js 6.8 KB

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