page.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: 'money',
  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. {
  79. title: '课程',
  80. dataIndex: 'course.title',
  81. },
  82. {
  83. title: '位置',
  84. dataIndex: 'position',
  85. render: (text, record) => {
  86. return `P${record.courseNo.no}:${text}`;
  87. },
  88. },
  89. {
  90. title: '提问摘要',
  91. dataIndex: 'content',
  92. }, {
  93. title: '提问者',
  94. dataIndex: 'user.nickname',
  95. }, {
  96. title: '承诺时间',
  97. dataIndex: 'askTime',
  98. render: (text, record) => {
  99. const end = new Date(record.answerTime) || new Date();
  100. const cost = (end.getTime() - new Date(record.createTime).getTime()) / 1000;
  101. if (text) {
  102. if (text - cost > 0) return `${formatSeconds(text - cost)}/${formatSeconds(text)}`;
  103. return `0/${formatSeconds(text)}`;
  104. }
  105. return '-';
  106. },
  107. }, {
  108. title: '回答状态',
  109. dataIndex: 'answerStatus',
  110. render: (text) => {
  111. return AskStatusMap[text] || text;
  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: 'showStatus',
  125. render: (text) => {
  126. return SwitchSelectMap[text] || text;
  127. },
  128. }, {
  129. title: '操作',
  130. dataIndex: 'handler',
  131. render: (text, record) => {
  132. return <div className="table-button">
  133. {(
  134. <Link to={`/course/ask/detail/${record.id}`}>编辑</Link>
  135. )}
  136. </div>;
  137. },
  138. }];
  139. bindSearch(this.filterForm, 'userId', this, (search) => {
  140. return User.list(search);
  141. }, (row) => {
  142. return {
  143. title: `${row.nickname}(${row.mobile})`,
  144. value: row.id,
  145. };
  146. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  147. Exercise.courseStruct().then((result) => {
  148. const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
  149. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  150. this.exerciseMap = getMap(result.map(row => {
  151. row.title = `${row.titleZh}`;
  152. row.value = row.id;
  153. return row;
  154. }), 'id', 'title');
  155. this.setState({ exercise: result });
  156. });
  157. Course.list().then((result) => {
  158. this.filterForm[1].select = result.list.map(row => {
  159. row.value = row.id;
  160. return row;
  161. });
  162. });
  163. }
  164. initData() {
  165. Course.listAsk(this.state.search).then(result => {
  166. this.setTableData(result.list, result.total);
  167. });
  168. }
  169. ignoreAction() {
  170. const { selectedKeys } = this.state;
  171. asyncDelConfirm('忽略确认', '是否忽略选中提问?', () => {
  172. return Promise.all(selectedKeys.map(row => User.editAsk({ id: row, ignoreStatus: 1 }))).then(() => {
  173. asyncSMessage('操作成功!');
  174. this.refresh();
  175. });
  176. });
  177. }
  178. renderView() {
  179. const { exercise } = this.state;
  180. return <Block flex>
  181. {exercise && <FilterLayout
  182. show
  183. itemList={this.filterForm}
  184. data={this.state.search}
  185. onChange={data => {
  186. this.search(data);
  187. }} />}
  188. {/* <ActionLayout
  189. itemList={this.actionList}
  190. selectedKeys={this.state.selectedKeys}
  191. onAction={key => this.onAction(key)}
  192. /> */}
  193. <TableLayout
  194. columns={this.columns}
  195. list={this.state.list}
  196. pagination={this.state.page}
  197. loading={this.props.core.loading}
  198. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  199. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  200. selectedKeys={this.state.selectedKeys}
  201. />
  202. </Block>;
  203. }
  204. }