page.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import React from 'react';
  2. import { Modal, Button } from 'antd';
  3. import { Link } from 'react-router-dom';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { getMap, formatDate, bindSearch } from '@src/services/Tools';
  11. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. import { FeedbackStatus, FeedbackModule, MoneyRange, AskTarget } from '../../../../Constant';
  13. import { User } from '../../../stores/user';
  14. const FeedbackStatusMap = getMap(FeedbackStatus, 'value', 'label');
  15. const FeedbackModuleMap = getMap(FeedbackModule, 'value', 'label');
  16. const AskTargetMap = getMap(AskTarget, 'value', 'label');
  17. export default class extends Page {
  18. init() {
  19. this.actionList = [{
  20. key: 'handle',
  21. type: 'danger',
  22. name: '批量修改',
  23. needSelect: 1,
  24. }, {
  25. key: 'nohandle',
  26. type: 'danger',
  27. name: '批量不修改',
  28. needSelect: 1,
  29. }, {
  30. key: 'ignore',
  31. type: 'danger',
  32. name: '批量忽略',
  33. needSelect: 1,
  34. }];
  35. this.filterForm = [{
  36. key: 'module',
  37. type: 'select',
  38. allowClear: true,
  39. name: '类型',
  40. select: FeedbackModule,
  41. placeholder: '请选择',
  42. }, {
  43. key: 'status',
  44. type: 'select',
  45. allowClear: true,
  46. name: '处理状态',
  47. number: true,
  48. select: FeedbackStatus,
  49. }, {
  50. key: 'userId',
  51. type: 'select',
  52. name: '用户',
  53. allowClear: true,
  54. select: [],
  55. number: true,
  56. placeholder: '请输入',
  57. }, {
  58. key: 'money',
  59. type: 'select',
  60. allowClear: true,
  61. name: '消费金额',
  62. select: MoneyRange,
  63. number: true,
  64. }, {
  65. key: 'keyword',
  66. type: 'input',
  67. allowClear: true,
  68. name: '勘误名称',
  69. }];
  70. this.columns = [
  71. {
  72. title: '类型',
  73. dataIndex: 'module',
  74. render: (text) => {
  75. return FeedbackModuleMap[text];
  76. },
  77. },
  78. {
  79. title: '提交时间',
  80. dataIndex: 'createTime',
  81. render: (text) => {
  82. return text ? formatDate(text) : '-';
  83. },
  84. },
  85. {
  86. title: '提交人',
  87. dataIndex: 'user.nickname',
  88. },
  89. {
  90. title: '消费金额',
  91. dataIndex: 'user.totalMoney',
  92. },
  93. {
  94. title: '勘误对象',
  95. dataIndex: 'title',
  96. }, {
  97. title: '处理状态',
  98. dataIndex: 'status',
  99. render: (text) => {
  100. return FeedbackStatusMap[text] || text;
  101. },
  102. }, {
  103. title: '操作',
  104. dataIndex: 'handler',
  105. render: (text, record) => {
  106. return <div className="table-button">
  107. {(
  108. <a onClick={() => {
  109. this.detailAction(record);
  110. }}>查看</a>
  111. )}
  112. </div>;
  113. },
  114. },
  115. ];
  116. bindSearch(this.filterForm, 'userId', this, (search) => {
  117. return User.list(search);
  118. }, (row) => {
  119. return {
  120. title: `${row.nickname}(${row.mobile})`,
  121. value: row.id,
  122. };
  123. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  124. }
  125. initData() {
  126. User.listFeedbackError(this.state.search).then(result => {
  127. result.list = result.list.map(row => {
  128. row.position = row.position.split(',');
  129. return row;
  130. });
  131. this.setTableData(result.list, result.total);
  132. });
  133. }
  134. detailAction(row) {
  135. this.setState({ detail: row });
  136. }
  137. handleDetail() {
  138. const { detail } = this.state;
  139. asyncDelConfirm('处理确认', '是否处理选中记录?', () => {
  140. return User.editFeedbackError({ id: detail.id, status: 1 }).then(() => {
  141. asyncSMessage('操作成功!');
  142. this.setState({ detail: null });
  143. this.refresh();
  144. });
  145. });
  146. }
  147. nohandleDetail() {
  148. const { detail } = this.state;
  149. asyncDelConfirm('不处理确认', '是否不处理选中记录?', () => {
  150. return User.editFeedbackError({ id: detail.id, status: 3 }).then(() => {
  151. asyncSMessage('操作成功!');
  152. this.setState({ detail: null });
  153. this.refresh();
  154. });
  155. });
  156. }
  157. ignoreDetail() {
  158. const { detail } = this.state;
  159. asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => {
  160. return User.editFeedbackError({ id: detail.id, status: 2 }).then(() => {
  161. asyncSMessage('操作成功!');
  162. this.setState({ detail: null });
  163. this.refresh();
  164. });
  165. });
  166. }
  167. handleAction() {
  168. const { selectedKeys } = this.state;
  169. asyncDelConfirm('修改确认', '是否修改选中记录?', () => {
  170. return Promise.all(selectedKeys.map(row => User.editFeedbackError({ id: row, status: 1 }))).then(() => {
  171. asyncSMessage('操作成功!');
  172. this.refresh();
  173. });
  174. });
  175. }
  176. nohandleAction() {
  177. const { selectedKeys } = this.state;
  178. asyncDelConfirm('不修改确认', '是否不修改选中记录?', () => {
  179. return Promise.all(selectedKeys.map(row => User.editFeedbackError({ id: row, status: 3 }))).then(() => {
  180. asyncSMessage('操作成功!');
  181. this.refresh();
  182. });
  183. });
  184. }
  185. ignoreAction() {
  186. const { selectedKeys } = this.state;
  187. asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => {
  188. return Promise.all(selectedKeys.map(row => User.editFeedbackError({ id: row, status: 2 }))).then(() => {
  189. asyncSMessage('操作成功!');
  190. this.refresh();
  191. });
  192. });
  193. }
  194. renderView() {
  195. return <Block flex>
  196. <FilterLayout
  197. show
  198. itemList={this.filterForm}
  199. data={this.state.search}
  200. onChange={data => {
  201. this.search(data);
  202. }} />
  203. <ActionLayout
  204. itemList={this.actionList}
  205. selectedKeys={this.state.selectedKeys}
  206. onAction={key => this.onAction(key)}
  207. />
  208. <TableLayout
  209. select
  210. columns={this.tableSort(this.columns)}
  211. list={this.state.list}
  212. pagination={this.state.page}
  213. loading={this.props.core.loading}
  214. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  215. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  216. selectedKeys={this.state.selectedKeys}
  217. />
  218. {this.state.detail && <Modal visible title='勘误详情' footer={null} closable onCancel={() => {
  219. this.setState({ detail: null });
  220. }}>
  221. <p>类型:{FeedbackModuleMap[this.state.detail.module]}</p>
  222. {this.state.detail.module === 'data' && <p>勘误对象:{<Link to={`/course/data/detail/${this.state.detail.moduleId}`}>{this.state.detail.title}</Link>}</p>}
  223. {this.state.detail.module === 'question' && <p>勘误对象:{<Link to={`/subject/question/${this.state.detail.moduleId}`}>{this.state.detail.title}-{AskTargetMap[this.state.detail.position[0]]}</Link>}</p>}
  224. {this.state.detail.position.length > 1 && <p>错误位置:{this.state.detail.position[0]}页,{this.state.detail.position[1]}行{this.state.detail.position[2] ? `题号:${this.state.detail.position[2]}` : ''}</p>}
  225. <p>错误内容:{this.state.detail.originContent}</p>
  226. <p>应修改为:{this.state.detail.content}</p>
  227. {!this.state.detail.status && <p><Button type="primary" onClick={() => {
  228. this.handleDetail();
  229. }}>确认修改</Button><Button type="primary" onClick={() => {
  230. this.nohandleDetail();
  231. }}>无需修改</Button><Button type="ghost" onClick={() => {
  232. this.ignoreDetail();
  233. }}>忽略</Button></p>}
  234. </Modal>}
  235. </Block>;
  236. }
  237. }