page.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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: 'type',
  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: 'questionNoId',
  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: 'type',
  62. render: (text, record) => {
  63. return TextbookTypeMap[record.question.type] || text;
  64. },
  65. }, {
  66. title: '练习册',
  67. dataIndex: 'paper',
  68. render: (text) => {
  69. return (text || {}).text.title;
  70. },
  71. }, {
  72. title: '题目ID',
  73. dataIndex: 'title',
  74. }, {
  75. title: '修改时间',
  76. dataIndex: 'updateTime',
  77. render: (text, record) => {
  78. return formatDate(record.question.updateTime);
  79. },
  80. }, {
  81. title: '操作',
  82. dataIndex: 'handler',
  83. render: (text, record) => {
  84. return <div className="table-button">
  85. {(
  86. <Link to={`/subject/text/question/${record.id}`}>编辑</Link>
  87. )}
  88. </div>;
  89. },
  90. }];
  91. }
  92. init() {
  93. bindSearch(filterForm, 'paperId', this, (search) => {
  94. return Textbook.listPaper(search);
  95. }, (row) => {
  96. return {
  97. title: row.title,
  98. value: row.id,
  99. };
  100. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  101. bindSearch(filterForm, 'questionNoId', this, (search) => {
  102. return Textbook.searchQuestion(search);
  103. }, (row) => {
  104. return {
  105. title: row.title,
  106. value: row.id,
  107. };
  108. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  109. }
  110. initData() {
  111. const { search } = this.state;
  112. const data = Object.assign({}, search);
  113. Textbook.listQuestion(data).then(result => {
  114. this.setTableData(result.list, result.total || 1);
  115. });
  116. }
  117. renderView() {
  118. return <Block flex>
  119. <FilterLayout
  120. show
  121. itemList={filterForm}
  122. data={this.state.search}
  123. onChange={data => {
  124. this.search(data);
  125. }} />
  126. <ActionLayout
  127. itemList={this.actionList}
  128. selectedKeys={this.state.selectedKeys}
  129. onAction={key => this.onAction(key)}
  130. />
  131. <TableLayout
  132. select
  133. columns={this.columns}
  134. list={this.state.list}
  135. pagination={this.state.page}
  136. loading={this.props.core.loading}
  137. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  138. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  139. selectedKeys={this.state.selectedKeys}
  140. />
  141. </Block>;
  142. }
  143. }