page.js 4.4 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 { asyncDelConfirm, asyncSMessage } from '@src/services/AsyncTools';
  12. // import { TextbookType } from '../../../../Constant';
  13. import { Textbook } from '../../../stores/textbook';
  14. import { TextbookSubject, TextbookQuality } from '../../../../Constant';
  15. // import { Slient } from '../../../stores/slient';
  16. const TextbookSubjectMap = getMap(TextbookSubject, 'value', 'label');
  17. const TextbookQualityMap = getMap(TextbookQuality, 'value', 'label');
  18. export default class extends Page {
  19. constructor(props) {
  20. super(props);
  21. this.actionList = [{
  22. key: 'add',
  23. name: '新建',
  24. render: (item) => {
  25. return <Button onClick={() => {
  26. linkTo('/textbook/topic/detail');
  27. }}>{item.name}</Button>;
  28. },
  29. }];
  30. this.filterForm = [{
  31. key: 'textbookSubject',
  32. type: 'select',
  33. name: '单项',
  34. select: TextbookSubject,
  35. allowClear: true,
  36. }, {
  37. key: 'libraryId',
  38. type: 'select',
  39. name: '换库表',
  40. select: [],
  41. number: true,
  42. allowClear: true,
  43. }, {
  44. key: 'quality',
  45. type: 'select',
  46. name: '机经质量',
  47. select: TextbookQuality,
  48. allowClear: true,
  49. }];
  50. this.columns = [{
  51. title: '单项',
  52. dataIndex: 'textbookSubject',
  53. render: (text) => {
  54. return TextbookSubjectMap[text] || '';
  55. },
  56. }, {
  57. title: '所属库',
  58. dataIndex: 'library',
  59. render: (text) => {
  60. return `${formatDate(text.startDate, 'YYYY-MM-DD')}-${text.endDate ? `${formatDate(text.endDate, 'YYYY-MM-DD')}` : '至今'}`;
  61. },
  62. }, {
  63. title: '题目序号',
  64. dataIndex: 'no',
  65. }, {
  66. title: '关键词',
  67. dataIndex: 'keyword',
  68. }, {
  69. title: '机经质量',
  70. dataIndex: 'quality',
  71. render: (text) => {
  72. return TextbookQualityMap[text] || '';
  73. },
  74. }, {
  75. title: '操作',
  76. dataIndex: 'handler',
  77. render: (text, record) => {
  78. return <div className="table-button">
  79. {(
  80. <Link to={`/textbook/topic/detail/${record.id}`}>编辑</Link>
  81. )}
  82. {(
  83. <a onClick={() => {
  84. this.deleteAction(record);
  85. }}>删除</a>
  86. )}
  87. </div>;
  88. },
  89. }];
  90. bindSearch(this.filterForm, 'libraryId', this, (search) => {
  91. return Textbook.listLibrary(search);
  92. }, (row) => {
  93. return {
  94. title: `${formatDate(row.startDate, 'YYYY-MM-DD')}-${row.endDate ? `${formatDate(row.endDate, 'YYYY-MM-DD')}` : '至今'}`,
  95. value: row.id,
  96. };
  97. }, this.state.search.libraryId ? Number(this.state.search.libraryId) : null, null);
  98. }
  99. initData() {
  100. const { search } = this.state;
  101. const data = Object.assign({}, search);
  102. Textbook.listTopic(data).then(result => {
  103. this.setTableData(result.list, result.total || 1);
  104. });
  105. }
  106. loadHistory(record) {
  107. Textbook.listHistory({ libraryId: record.id }).then(result => {
  108. this.setState({ history: result.list });
  109. });
  110. }
  111. deleteAction(row) {
  112. asyncDelConfirm('删除确认', '是否删除选中记录?', () => {
  113. return Textbook.delTopic({ id: row.id }).then(() => {
  114. asyncSMessage('操作成功!');
  115. this.refresh();
  116. });
  117. });
  118. }
  119. renderView() {
  120. return <Block flex>
  121. <FilterLayout
  122. show
  123. itemList={this.filterForm}
  124. data={this.state.search}
  125. onChange={data => {
  126. data.page = 1;
  127. this.search(data);
  128. }} />
  129. <ActionLayout
  130. itemList={this.actionList}
  131. selectedKeys={this.state.selectedKeys}
  132. onAction={key => this.onAction(key)}
  133. />
  134. <TableLayout
  135. columns={this.tableSort(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. </Block>;
  144. }
  145. }