page.js 3.9 KB

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