1
0

page.js 5.3 KB

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