page.js 5.5 KB

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