page.js 4.8 KB

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