page.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 } from '@src/services/Tools';
  10. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  11. import { QuestionType, AskStatus, MoneyRange, SwitchSelect, AskTarget } 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. export default class extends Page {
  18. init() {
  19. this.actionList = [{
  20. key: 'ignore',
  21. type: 'danger',
  22. name: '批量忽略',
  23. needSelect: 1,
  24. }];
  25. this.filterForm = [{
  26. key: 'type',
  27. type: 'select',
  28. allowClear: true,
  29. name: '题型',
  30. select: QuestionType,
  31. placeholder: '请选择',
  32. number: true,
  33. }, {
  34. key: 'status',
  35. type: 'select',
  36. allowClear: true,
  37. name: '状态',
  38. select: AskStatus,
  39. }, {
  40. key: 'money',
  41. type: 'select',
  42. allowClear: true,
  43. name: '消费金额',
  44. select: MoneyRange,
  45. }, {
  46. key: 'showStatus',
  47. type: 'select',
  48. allowClear: true,
  49. name: '展示状态',
  50. select: SwitchSelect,
  51. }, {
  52. key: 'target',
  53. type: 'select',
  54. allowClear: true,
  55. name: '提问内容',
  56. select: AskTarget,
  57. }, {
  58. key: 'questionNoId',
  59. type: 'select',
  60. allowClear: true,
  61. name: '题目ID',
  62. select: [],
  63. number: true,
  64. placeholder: '请输入',
  65. }, {
  66. key: 'userId',
  67. type: 'select',
  68. name: '用户',
  69. allowClear: true,
  70. select: [],
  71. number: true,
  72. placeholder: '请输入',
  73. }];
  74. this.columns = [
  75. {
  76. title: '题型',
  77. dataIndex: 'type',
  78. render: (text, record) => {
  79. return QuestionTypeMap[record.question.type];
  80. },
  81. },
  82. {
  83. title: '题目id',
  84. dataIndex: 'questionNo.no',
  85. },
  86. {
  87. title: '提问时间',
  88. dataIndex: 'createTime',
  89. render: (text) => {
  90. return formatDate(text);
  91. },
  92. },
  93. {
  94. title: '提问摘要',
  95. dataIndex: 'content',
  96. }, {
  97. title: '提问者',
  98. dataIndex: 'user.nickname',
  99. }, {
  100. title: '回答状态',
  101. dataIndex: 'answerStatus',
  102. render: (text) => {
  103. return AskStatusMap[text] || text;
  104. },
  105. }, {
  106. title: '回答者',
  107. dataIndex: 'manager.username',
  108. }, {
  109. title: '回答时间',
  110. dataIndex: 'answerTime',
  111. }, {
  112. title: '展示状态',
  113. dataIndex: 'showStatus',
  114. render: (text) => {
  115. return SwitchSelectMap[text] || text;
  116. },
  117. }, {
  118. title: '操作',
  119. dataIndex: 'handler',
  120. render: (text, record) => {
  121. return <div className="table-button">
  122. {(
  123. <Link to={`/user/ask/detail/${record.id}`}>编辑</Link>
  124. )}
  125. </div>;
  126. },
  127. },
  128. ];
  129. bindSearch(this.filterForm, 'userId', this, (search) => {
  130. return User.list(search);
  131. }, (row) => {
  132. return {
  133. title: `${row.nickname}(${row.mobile})`,
  134. value: row.id,
  135. };
  136. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  137. bindSearch(this.filterForm, 'questionNoId', this, (search) => {
  138. return Question.searchNo(search);
  139. }, (row) => {
  140. return {
  141. title: row.title,
  142. value: row.id,
  143. };
  144. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  145. }
  146. initData() {
  147. Question.listAsk(this.state.search).then(result => {
  148. this.setTableData(result.list, result.total);
  149. });
  150. }
  151. ignoreAction() {
  152. const { selectedKeys } = this.state;
  153. asyncDelConfirm('忽略确认', '是否忽略选中提问?', () => {
  154. return Promise.all(selectedKeys.map(row => Question.editAsk({ id: row, answerStatus: 2 }))).then(() => {
  155. asyncSMessage('操作成功!');
  156. this.refresh();
  157. });
  158. });
  159. }
  160. renderView() {
  161. return <Block flex>
  162. <FilterLayout
  163. show
  164. itemList={this.filterForm}
  165. data={this.state.search}
  166. onChange={data => {
  167. if (data.time.length > 0) {
  168. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  169. }
  170. this.search(data);
  171. }} />
  172. <ActionLayout
  173. itemList={this.actionList}
  174. selectedKeys={this.state.selectedKeys}
  175. onAction={key => this.onAction(key)}
  176. />
  177. <TableLayout
  178. select
  179. columns={this.columns}
  180. list={this.state.list}
  181. pagination={this.state.page}
  182. loading={this.props.core.loading}
  183. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  184. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  185. selectedKeys={this.state.selectedKeys}
  186. />
  187. </Block>;
  188. }
  189. }