page.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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, FeedbackQuestionType } from '../../../../Constant';
  13. import { User } from '../../../stores/user';
  14. import { Question } from '../../../stores/question';
  15. import { Course } from '../../../stores/course';
  16. const FeedbackStatusMap = getMap(FeedbackStatus, 'value', 'label');
  17. const FeedbackModuleMap = getMap(FeedbackModule, 'value', 'label');
  18. const FeedbackQuestionTypeMap = getMap(FeedbackQuestionType, 'value', 'label');
  19. const AskTargetMap = getMap(AskTarget, 'value', 'label');
  20. export default class extends Page {
  21. init() {
  22. this.actionList = [{
  23. key: 'handle',
  24. type: 'danger',
  25. name: '批量修改',
  26. needSelect: 1,
  27. }, {
  28. key: 'nohandle',
  29. type: 'danger',
  30. name: '批量不修改',
  31. needSelect: 1,
  32. }, {
  33. key: 'ignore',
  34. type: 'danger',
  35. name: '批量忽略',
  36. needSelect: 1,
  37. }];
  38. this.filterF = null;
  39. this.filterForm = [{
  40. key: 'module',
  41. type: 'select',
  42. allowClear: true,
  43. name: '类型',
  44. select: FeedbackModule,
  45. placeholder: '请选择',
  46. onChange: (value) => {
  47. this.changeSearch(this.filterForm, this, value, null);
  48. this.filterF.setFieldsValue({ questionType: null, keyword: null, target: null, moduleId: null });
  49. },
  50. }, {
  51. key: 'questionType',
  52. type: 'select',
  53. allowClear: true,
  54. name: '单项',
  55. select: FeedbackQuestionType,
  56. }, {
  57. key: 'keyword',
  58. type: 'input',
  59. allowClear: true,
  60. name: '题目id',
  61. placeholder: '题目ID',
  62. }, {
  63. key: 'target',
  64. type: 'select',
  65. allowClear: true,
  66. name: '勘误区域',
  67. select: AskTarget,
  68. }, {
  69. key: 'moduleId',
  70. type: 'select',
  71. allowClear: true,
  72. name: '资料',
  73. select: [],
  74. placeholder: '资料',
  75. }, {
  76. key: 'status',
  77. type: 'select',
  78. allowClear: true,
  79. name: '处理状态',
  80. number: true,
  81. select: FeedbackStatus,
  82. }, {
  83. key: 'userId',
  84. type: 'select',
  85. name: '用户',
  86. allowClear: true,
  87. select: [],
  88. number: true,
  89. placeholder: '请输入',
  90. }, {
  91. key: 'moneyRang',
  92. type: 'select',
  93. allowClear: true,
  94. name: '消费金额',
  95. select: MoneyRange,
  96. number: true,
  97. }, {
  98. key: 'keyword',
  99. type: 'input',
  100. allowClear: true,
  101. name: '勘误名称',
  102. }];
  103. this.columns = [{
  104. title: '类型',
  105. dataIndex: 'module',
  106. render: (text) => {
  107. return FeedbackModuleMap[text];
  108. },
  109. }, {
  110. title: '学科单项',
  111. dataIndex: 'questionType',
  112. render: (text) => {
  113. return FeedbackQuestionTypeMap[text];
  114. },
  115. }, {
  116. title: '对象',
  117. dataIndex: 'title',
  118. }, {
  119. title: '勘误区域',
  120. dataIndex: 'position',
  121. render: (text) => {
  122. return AskTargetMap[text[0]] || '';
  123. },
  124. }, {
  125. title: '提交时间',
  126. dataIndex: 'createTime',
  127. render: (text) => {
  128. return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : '-';
  129. },
  130. }, {
  131. title: '用户',
  132. dataIndex: 'user.nickname',
  133. }, {
  134. title: '消费金额',
  135. dataIndex: 'user.totalMoney',
  136. }, {
  137. title: '处理状态',
  138. dataIndex: 'status',
  139. render: (text) => {
  140. return FeedbackStatusMap[text] || text;
  141. },
  142. }, {
  143. title: '操作',
  144. dataIndex: 'handler',
  145. render: (text, record) => {
  146. return <div className="table-button">
  147. {(
  148. <a onClick={() => {
  149. this.detailAction(record);
  150. }}>查看</a>
  151. )}
  152. </div>;
  153. },
  154. }];
  155. bindSearch(this.filterForm, 'userId', this, (search) => {
  156. return User.list(search);
  157. }, (row) => {
  158. return {
  159. title: `${row.nickname}(${row.mobile})`,
  160. value: row.id,
  161. };
  162. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  163. this.changeSearch(this.filterForm, this, this.state.search.module, this.state.search.moduleId);
  164. }
  165. changeSearch(list, component, key, value) {
  166. if (key === 'data') {
  167. bindSearch(list, 'moduleId', component, (search) => {
  168. if (key === 'question') {
  169. return Question.listNo(search);
  170. }
  171. return Course.listData(search);
  172. }, (row) => {
  173. if (key === 'question') {
  174. return {
  175. title: row.title,
  176. value: row.questionId,
  177. };
  178. }
  179. return {
  180. title: row.title,
  181. value: row.id,
  182. };
  183. }, value ? Number(value) : null, null);
  184. list[1].disabled = true;
  185. list[2].disabled = true;
  186. list[3].disabled = true;
  187. list[4].disabled = false;
  188. } else if (key === 'question') {
  189. list[1].disabled = false;
  190. list[2].disabled = false;
  191. list[3].disabled = false;
  192. list[4].disabled = true;
  193. } else {
  194. list[1].disabled = true;
  195. list[2].disabled = true;
  196. list[3].disabled = true;
  197. list[4].disabled = true;
  198. }
  199. component.setState({ load: false });
  200. }
  201. initData() {
  202. User.listFeedbackError(this.state.search).then(result => {
  203. result.list = result.list.map(row => {
  204. row.position = row.position.split(',');
  205. return row;
  206. });
  207. this.setTableData(result.list, result.total);
  208. });
  209. }
  210. detailAction(row) {
  211. this.setState({ detail: row });
  212. }
  213. handleDetail() {
  214. const { detail } = this.state;
  215. asyncDelConfirm('处理确认', '是否处理选中记录?', () => {
  216. return User.editFeedbackError({ id: detail.id, status: 1 }).then(() => {
  217. asyncSMessage('操作成功!');
  218. this.setState({ detail: null });
  219. this.refresh();
  220. });
  221. });
  222. }
  223. nohandleDetail() {
  224. const { detail } = this.state;
  225. asyncDelConfirm('不处理确认', '是否不处理选中记录?', () => {
  226. return User.editFeedbackError({ id: detail.id, status: 3 }).then(() => {
  227. asyncSMessage('操作成功!');
  228. this.setState({ detail: null });
  229. this.refresh();
  230. });
  231. });
  232. }
  233. ignoreDetail() {
  234. const { detail } = this.state;
  235. asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => {
  236. return User.editFeedbackError({ id: detail.id, status: 2 }).then(() => {
  237. asyncSMessage('操作成功!');
  238. this.setState({ detail: null });
  239. this.refresh();
  240. });
  241. });
  242. }
  243. handleAction() {
  244. const { selectedKeys } = this.state;
  245. asyncDelConfirm('修改确认', '是否修改选中记录?', () => {
  246. return Promise.all(selectedKeys.map(row => User.editFeedbackError({ id: row, status: 1 }))).then(() => {
  247. asyncSMessage('操作成功!');
  248. this.refresh();
  249. });
  250. });
  251. }
  252. nohandleAction() {
  253. const { selectedKeys } = this.state;
  254. asyncDelConfirm('不修改确认', '是否不修改选中记录?', () => {
  255. return Promise.all(selectedKeys.map(row => User.editFeedbackError({ id: row, status: 3 }))).then(() => {
  256. asyncSMessage('操作成功!');
  257. this.refresh();
  258. });
  259. });
  260. }
  261. ignoreAction() {
  262. const { selectedKeys } = this.state;
  263. asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => {
  264. return Promise.all(selectedKeys.map(row => User.editFeedbackError({ id: row, status: 2 }))).then(() => {
  265. asyncSMessage('操作成功!');
  266. this.refresh();
  267. });
  268. });
  269. }
  270. renderView() {
  271. return <Block flex>
  272. <FilterLayout
  273. show
  274. ref={(ref) => { this.filterF = ref; }}
  275. itemList={this.filterForm}
  276. data={this.state.search}
  277. onChange={data => {
  278. data.page = 1;
  279. this.search(data);
  280. }} />
  281. <ActionLayout
  282. itemList={this.actionList}
  283. selectedKeys={this.state.selectedKeys}
  284. onAction={key => this.onAction(key)}
  285. />
  286. <TableLayout
  287. select
  288. columns={this.tableSort(this.columns)}
  289. list={this.state.list}
  290. pagination={this.state.page}
  291. loading={this.props.core.loading}
  292. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  293. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  294. selectedKeys={this.state.selectedKeys}
  295. />
  296. {this.state.detail && <Modal visible title='勘误详情' footer={null} closable onCancel={() => {
  297. this.setState({ detail: null });
  298. }}>
  299. <p>类型:{FeedbackModuleMap[this.state.detail.module]}</p>
  300. {this.state.detail.module === 'data' && <p>勘误对象:{<Link to={`/course/data/detail/${this.state.detail.moduleId}`}>{this.state.detail.title}</Link>}</p>}
  301. {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>}
  302. {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>}
  303. <p>错误内容:{this.state.detail.originContent}</p>
  304. <p>应修改为:{this.state.detail.content}</p>
  305. {!this.state.detail.status && <p><Button type="primary" onClick={() => {
  306. this.handleDetail();
  307. }}>确认修改</Button><Button type="primary" onClick={() => {
  308. this.nohandleDetail();
  309. }}>无需修改</Button><Button type="ghost" onClick={() => {
  310. this.ignoreDetail();
  311. }}>忽略</Button></p>}
  312. </Modal>}
  313. </Block>;
  314. }
  315. }