page.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React from 'react';
  2. import { 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, bindSearch, formatDate } from '@src/services/Tools';
  11. // import { asyncSMessage } from '@src/services/AsyncTools';
  12. import { TextbookType } from '../../../../Constant';
  13. // import { System } from '../../../stores/system';
  14. import { Textbook } from '../../../stores/textbook';
  15. // import { Slient } from '../../../stores/slient';
  16. const TextbookTypeMap = getMap(TextbookType, 'value', 'label');
  17. const filterForm = [
  18. {
  19. key: 'questionType',
  20. type: 'select',
  21. allowClear: true,
  22. name: '题型',
  23. select: TextbookType,
  24. placeholder: '请选择',
  25. number: true,
  26. },
  27. {
  28. key: 'paperId',
  29. type: 'select',
  30. allowClear: true,
  31. name: '练习册',
  32. select: [],
  33. placeholder: '请选择',
  34. number: true,
  35. },
  36. {
  37. key: 'id',
  38. type: 'select',
  39. allowClear: true,
  40. name: '题目ID',
  41. select: [],
  42. number: true,
  43. placeholder: '请输入',
  44. },
  45. ];
  46. export default class extends Page {
  47. constructor(props) {
  48. super(props);
  49. this.actionList = [{
  50. key: 'add',
  51. name: '新建',
  52. render: (item) => {
  53. return <Button onClick={() => {
  54. linkTo('/subject/textbook/question');
  55. }}>{item.name}</Button>;
  56. },
  57. }];
  58. this.categoryMap = {};
  59. this.columns = [{
  60. title: '题型',
  61. dataIndex: 'questionType',
  62. render: (text, record) => {
  63. return TextbookTypeMap[record.question.questionType] || text;
  64. },
  65. }, {
  66. title: '练习册',
  67. dataIndex: 'paper.title',
  68. }, {
  69. title: '题目ID',
  70. dataIndex: 'title',
  71. }, {
  72. title: '修改时间',
  73. dataIndex: 'updateTime',
  74. render: (text, record) => {
  75. return formatDate(record.question.updateTime, 'YYYY-MM-DD HH:mm:ss');
  76. },
  77. }, {
  78. title: '操作',
  79. dataIndex: 'handler',
  80. render: (text, record) => {
  81. return <div className="table-button">
  82. {(
  83. <Link to={`/subject/text/question/${record.id}`}>编辑</Link>
  84. )}
  85. </div>;
  86. },
  87. }];
  88. }
  89. init() {
  90. bindSearch(filterForm, 'paperId', this, (search) => {
  91. return Textbook.listPaper(search);
  92. }, (row) => {
  93. return {
  94. title: row.title,
  95. value: row.id,
  96. };
  97. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  98. bindSearch(filterForm, 'id', this, (search) => {
  99. return Textbook.searchQuestion(search);
  100. }, (row) => {
  101. return {
  102. title: row.title,
  103. value: row.id,
  104. };
  105. }, this.state.search.id ? Number(this.state.search.id) : null, null);
  106. }
  107. initData() {
  108. const { search } = this.state;
  109. const data = Object.assign({}, search);
  110. Textbook.listQuestion(data).then(result => {
  111. this.setTableData(result.list, result.total || 1);
  112. });
  113. }
  114. renderView() {
  115. return <Block flex>
  116. <FilterLayout
  117. show
  118. itemList={filterForm}
  119. data={this.state.search}
  120. onChange={data => {
  121. data.page = 1;
  122. this.search(data);
  123. }} />
  124. <ActionLayout
  125. itemList={this.actionList}
  126. selectedKeys={this.state.selectedKeys}
  127. onAction={key => this.onAction(key)}
  128. />
  129. <TableLayout
  130. columns={this.tableSort(this.columns)}
  131. list={this.state.list}
  132. pagination={this.state.page}
  133. loading={this.props.core.loading}
  134. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  135. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  136. selectedKeys={this.state.selectedKeys}
  137. />
  138. </Block>;
  139. }
  140. }