page.js 6.6 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, bindSearch, formatDate, formatSeconds } from '@src/services/Tools';
  10. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  11. import { QuestionType, AnswerStatus, MoneyRange, SwitchSelect, AskTarget, AskModule } from '../../../../Constant';
  12. import { User } from '../../../stores/user';
  13. import { Question } from '../../../stores/question';
  14. const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
  15. const AnswerStatusMap = getMap(AnswerStatus, 'value', 'label');
  16. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  17. const AskModuleMap = getMap(AskModule, '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.filterForm = [{
  27. key: 'askModule',
  28. type: 'select',
  29. allowClear: true,
  30. name: '板块',
  31. select: AskModule,
  32. placeholder: '请选择',
  33. }, {
  34. key: 'questionType',
  35. type: 'select',
  36. allowClear: true,
  37. name: '题型',
  38. select: QuestionType,
  39. placeholder: '请选择',
  40. }, {
  41. key: 'answerStatus',
  42. type: 'select',
  43. allowClear: true,
  44. name: '状态',
  45. select: AnswerStatus,
  46. number: true,
  47. }, {
  48. key: 'moneyRang',
  49. type: 'select',
  50. allowClear: true,
  51. name: '消费金额',
  52. select: MoneyRange,
  53. number: true,
  54. }, {
  55. key: 'showStatus',
  56. type: 'select',
  57. allowClear: true,
  58. name: '展示状态',
  59. select: SwitchSelect,
  60. number: true,
  61. }, {
  62. key: 'target',
  63. type: 'select',
  64. allowClear: true,
  65. name: '提问内容',
  66. select: AskTarget,
  67. }, {
  68. key: 'questionNoId',
  69. type: 'select',
  70. allowClear: true,
  71. name: '题目ID',
  72. select: [],
  73. number: true,
  74. placeholder: '请输入',
  75. }, {
  76. key: 'userId',
  77. type: 'select',
  78. name: '用户',
  79. allowClear: true,
  80. select: [],
  81. number: true,
  82. placeholder: '请输入',
  83. }, {
  84. key: 'time',
  85. type: 'daterange',
  86. name: '提问时间',
  87. }];
  88. this.columns = [{
  89. title: '板块',
  90. dataIndex: 'askModule',
  91. render: (text) => {
  92. return AskModuleMap[text];
  93. },
  94. }, {
  95. title: '题型',
  96. dataIndex: 'type',
  97. render: (text, record) => {
  98. return QuestionTypeMap[record.question.questionType];
  99. },
  100. }, {
  101. title: '题目id',
  102. dataIndex: 'questionNo.no',
  103. }, {
  104. title: '提问者',
  105. dataIndex: 'user.nickname',
  106. }, {
  107. title: '消费金额',
  108. dataIndex: 'user.totalMoney',
  109. }, {
  110. title: '提问时间',
  111. dataIndex: 'createTime',
  112. render: (text) => {
  113. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  114. },
  115. }, {
  116. title: '倒计时',
  117. sorter: true,
  118. dataIndex: 'expireTime',
  119. render: (text, record) => {
  120. const end = new Date(record.answerTime) || new Date();
  121. const cost = (end.getTime() - new Date(record.createTime).getTime()) / 1000;
  122. if (text) {
  123. if (record.askTime - cost > 0) return `${formatSeconds(text - cost)}/${formatSeconds(text)}`;
  124. return `0/${formatSeconds(text)}`;
  125. }
  126. return '-';
  127. },
  128. }, {
  129. title: '回答者',
  130. dataIndex: 'manager.username',
  131. }, {
  132. title: '回答时间',
  133. sorter: true,
  134. dataIndex: 'answerTime',
  135. render: (text) => {
  136. return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : '';
  137. },
  138. }, {
  139. title: '回答状态',
  140. dataIndex: 'answerStatus',
  141. render: (text) => {
  142. return AnswerStatusMap[text] || text;
  143. },
  144. }, {
  145. title: '展示状态',
  146. dataIndex: 'showStatus',
  147. render: (text) => {
  148. return SwitchSelectMap[text] || text;
  149. },
  150. }, {
  151. title: '操作',
  152. dataIndex: 'handler',
  153. render: (text, record) => {
  154. return <div className="table-button">
  155. {(
  156. <Link to={`/student/ask/question/detail/${record.id}`}>编辑</Link>
  157. )}
  158. </div>;
  159. },
  160. }];
  161. bindSearch(this.filterForm, 'userId', this, (search) => {
  162. return User.list(search);
  163. }, (row) => {
  164. return {
  165. title: `${row.nickname}(${row.mobile})`,
  166. value: row.id,
  167. };
  168. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  169. bindSearch(this.filterForm, 'questionNoId', this, (search) => {
  170. return Question.searchNo(search);
  171. }, (row) => {
  172. return {
  173. title: row.title,
  174. value: row.id,
  175. };
  176. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  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. Question.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 => Question.editAsk({ id: row, ignoreStatus: 1 }))).then(() => {
  193. asyncSMessage('操作成功!');
  194. this.refresh();
  195. });
  196. });
  197. }
  198. renderView() {
  199. return <Block flex>
  200. <FilterLayout
  201. show
  202. itemList={this.filterForm}
  203. data={this.state.search}
  204. onChange={data => {
  205. if (data.time.length > 0) {
  206. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  207. }
  208. data.page = 1;
  209. this.search(data);
  210. }} />
  211. <ActionLayout
  212. itemList={this.actionList}
  213. selectedKeys={this.state.selectedKeys}
  214. onAction={key => this.onAction(key)}
  215. />
  216. <TableLayout
  217. select
  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. }