page.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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, AskStatus, 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 AskStatusMap = getMap(AskStatus, '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: AskStatus,
  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. this.columns = [{
  85. title: '板块',
  86. dataIndex: 'askModule',
  87. render: (text) => {
  88. return AskModuleMap[text];
  89. },
  90. }, {
  91. title: '题型',
  92. dataIndex: 'type',
  93. render: (text, record) => {
  94. return QuestionTypeMap[record.question.questionType];
  95. },
  96. }, {
  97. title: '题目id',
  98. dataIndex: 'questionNo.no',
  99. }, {
  100. title: '提问者',
  101. dataIndex: 'user.nickname',
  102. }, {
  103. title: '消费金额',
  104. dataIndex: 'user.totalMoney',
  105. }, {
  106. title: '提问时间',
  107. dataIndex: 'createTime',
  108. render: (text) => {
  109. return formatDate(text);
  110. },
  111. }, {
  112. title: '倒计时',
  113. dataIndex: 'askTime',
  114. render: (text, record) => {
  115. const end = new Date(record.answerTime) || new Date();
  116. const cost = (end.getTime() - new Date(record.createTime).getTime()) / 1000;
  117. if (text) {
  118. if (text - cost > 0) return `${formatSeconds(text - cost)}/${formatSeconds(text)}`;
  119. return `0/${formatSeconds(text)}`;
  120. }
  121. return '-';
  122. },
  123. }, {
  124. title: '回答者',
  125. dataIndex: 'manager.username',
  126. }, {
  127. title: '回答时间',
  128. dataIndex: 'answerTime',
  129. render: (text) => {
  130. return text ? formatDate(text) : '';
  131. },
  132. }, {
  133. title: '回答状态',
  134. dataIndex: 'answerStatus',
  135. render: (text) => {
  136. return AskStatusMap[text] || text;
  137. },
  138. }, {
  139. title: '展示状态',
  140. dataIndex: 'showStatus',
  141. render: (text) => {
  142. return SwitchSelectMap[text] || text;
  143. },
  144. }, {
  145. title: '操作',
  146. dataIndex: 'handler',
  147. render: (text, record) => {
  148. return <div className="table-button">
  149. {(
  150. <Link to={`/student/ask/question/detail/${record.id}`}>编辑</Link>
  151. )}
  152. </div>;
  153. },
  154. }];
  155. bindSearch(this.filterForm, 'userId', this, (search) => {
  156. return User.list(search);
  157. }, (row) => {
  158. return {
  159. title: `${row.nickname}(${row.mobile})`,
  160. value: row.id,
  161. };
  162. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  163. bindSearch(this.filterForm, 'questionNoId', this, (search) => {
  164. return Question.searchNo(search);
  165. }, (row) => {
  166. return {
  167. title: row.title,
  168. value: row.id,
  169. };
  170. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  171. }
  172. initData() {
  173. Question.listAsk(Object.assign({ hasRecord: true }, this.state.search)).then(result => {
  174. this.setTableData(result.list, result.total);
  175. });
  176. }
  177. ignoreAction() {
  178. const { selectedKeys } = this.state;
  179. asyncDelConfirm('忽略确认', '是否忽略选中提问?', () => {
  180. return Promise.all(selectedKeys.map(row => Question.editAsk({ id: row, ignoreStatus: 1 }))).then(() => {
  181. asyncSMessage('操作成功!');
  182. this.refresh();
  183. });
  184. });
  185. }
  186. renderView() {
  187. return <Block flex>
  188. <FilterLayout
  189. show
  190. itemList={this.filterForm}
  191. data={this.state.search}
  192. onChange={data => {
  193. if (data.time.length > 0) {
  194. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  195. }
  196. this.search(data);
  197. }} />
  198. <ActionLayout
  199. itemList={this.actionList}
  200. selectedKeys={this.state.selectedKeys}
  201. onAction={key => this.onAction(key)}
  202. />
  203. <TableLayout
  204. select
  205. columns={this.tableSort(this.columns)}
  206. list={this.state.list}
  207. pagination={this.state.page}
  208. loading={this.props.core.loading}
  209. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  210. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  211. selectedKeys={this.state.selectedKeys}
  212. />
  213. </Block>;
  214. }
  215. }