page.js 3.8 KB

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