page.js 6.1 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 } from '@src/services/Tools';
  10. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  11. import { QuestionType, AnswerStatus, 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 AnswerStatusMap = getMap(AnswerStatus, '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: AnswerStatus,
  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. key: 'time',
  85. type: 'daterange',
  86. name: '提问时间',
  87. }];
  88. this.columns = [{
  89. title: '板块',
  90. dataIndex: 'askModule',
  91. render: (text) => {
  92. return AskModuleMap[text];
  93. },
  94. }, {
  95. title: '题型',
  96. dataIndex: 'type',
  97. render: (text, record) => {
  98. return QuestionTypeMap[record.question.questionType];
  99. },
  100. }, {
  101. title: '题目id',
  102. dataIndex: 'questionNo.no',
  103. }, {
  104. title: '提问者',
  105. dataIndex: 'user.nickname',
  106. }, {
  107. title: '消费金额',
  108. dataIndex: 'user.totalMoney',
  109. }, {
  110. title: '提问时间',
  111. dataIndex: 'createTime',
  112. render: (text) => {
  113. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  114. },
  115. }, {
  116. title: '回答者',
  117. dataIndex: 'manager.username',
  118. }, {
  119. title: '回答时间',
  120. sorter: true,
  121. dataIndex: 'answerTime',
  122. render: (text) => {
  123. return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : '';
  124. },
  125. }, {
  126. title: '回答状态',
  127. dataIndex: 'answerStatus',
  128. render: (text) => {
  129. return AnswerStatusMap[text] || text;
  130. },
  131. }, {
  132. title: '展示状态',
  133. dataIndex: 'showStatus',
  134. render: (text) => {
  135. return SwitchSelectMap[text] || text;
  136. },
  137. }, {
  138. title: '操作',
  139. dataIndex: 'handler',
  140. render: (text, record) => {
  141. return <div className="table-button">
  142. {(
  143. <Link to={`/interaction/ask/question/detail/${record.id}`}>编辑</Link>
  144. )}
  145. </div>;
  146. },
  147. }];
  148. bindSearch(this.filterForm, 'userId', this, (search) => {
  149. return User.list(search);
  150. }, (row) => {
  151. return {
  152. title: `${row.nickname}(${row.mobile})`,
  153. value: row.id,
  154. };
  155. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  156. bindSearch(this.filterForm, 'questionNoId', this, (search) => {
  157. return Question.searchNo(search);
  158. }, (row) => {
  159. return {
  160. title: row.title,
  161. value: row.id,
  162. };
  163. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  164. }
  165. initData() {
  166. const { search } = this.state;
  167. const data = Object.assign({ hasRecord: false }, search);
  168. if (data.time) {
  169. data.startTime = data.time[0] || '';
  170. data.endTime = data.time[1] || '';
  171. }
  172. Question.listAsk(data).then(result => {
  173. this.setTableData(result.list, result.total);
  174. });
  175. }
  176. ignoreAction() {
  177. const { selectedKeys } = this.state;
  178. asyncDelConfirm('忽略确认', '是否忽略选中提问?', () => {
  179. return Promise.all(selectedKeys.map(row => Question.editAsk({ id: row, ignoreStatus: 1 }))).then(() => {
  180. asyncSMessage('操作成功!');
  181. this.refresh();
  182. });
  183. });
  184. }
  185. renderView() {
  186. return <Block flex>
  187. <FilterLayout
  188. show
  189. itemList={this.filterForm}
  190. data={this.state.search}
  191. onChange={data => {
  192. if (data.time.length > 0) {
  193. data.time = [data.time[0].format('YYYY-MM-DD 00:00:00'), data.time[1].format('YYYY-MM-DD 23:59:59')];
  194. }
  195. data.page = 1;
  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. }