page.js 4.1 KB

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