page.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. number: true,
  49. allowClear: true,
  50. }];
  51. this.columns = [{
  52. title: '单项',
  53. dataIndex: 'textbookSubject',
  54. render: (text) => {
  55. return TextbookSubjectMap[text] || '';
  56. },
  57. }, {
  58. title: '所属库',
  59. dataIndex: 'library',
  60. render: (text) => {
  61. return `${formatDate(text.startDate, 'YYYY-MM-DD')}-${text.endDate ? `${formatDate(text.endDate, 'YYYY-MM-DD')}` : '至今'}`;
  62. },
  63. }, {
  64. title: '题目序号',
  65. dataIndex: 'no',
  66. }, {
  67. title: '关键词',
  68. dataIndex: 'keyword',
  69. }, {
  70. title: '机经质量',
  71. dataIndex: 'quality',
  72. render: (text) => {
  73. return TextbookQualityMap[text] || '';
  74. },
  75. }, {
  76. title: '操作',
  77. dataIndex: 'handler',
  78. render: (text, record) => {
  79. return <div className="table-button">
  80. {(
  81. <Link to={`/textbook/topic/detail/${record.id}`}>编辑</Link>
  82. )}
  83. {(
  84. <a onClick={() => {
  85. this.deleteAction(record);
  86. }}>删除</a>
  87. )}
  88. </div>;
  89. },
  90. }];
  91. bindSearch(this.filterForm, 'libraryId', this, (search) => {
  92. return Textbook.listLibrary(search);
  93. }, (row) => {
  94. return {
  95. title: `${formatDate(row.startDate, 'YYYY-MM-DD')}-${row.endDate ? `${formatDate(row.endDate, 'YYYY-MM-DD')}` : '至今'}`,
  96. value: row.id,
  97. };
  98. }, this.state.search.libraryId ? Number(this.state.search.libraryId) : null, null);
  99. }
  100. initData() {
  101. const { search } = this.state;
  102. const data = Object.assign({}, search);
  103. Textbook.listTopic(data).then(result => {
  104. this.setTableData(result.list, result.total || 1);
  105. });
  106. }
  107. loadHistory(record) {
  108. Textbook.listHistory({ libraryId: record.id }).then(result => {
  109. this.setState({ history: result.list });
  110. });
  111. }
  112. deleteAction(row) {
  113. asyncDelConfirm('删除确认', '是否删除选中用户?', () => {
  114. return Textbook.delTopic({ id: row.userId }).then(() => {
  115. asyncSMessage('操作成功!');
  116. this.refresh();
  117. });
  118. });
  119. }
  120. renderView() {
  121. return <Block flex>
  122. <FilterLayout
  123. show
  124. itemList={this.filterForm}
  125. data={this.state.search}
  126. onChange={data => {
  127. data.page = 1;
  128. this.search(data);
  129. }} />
  130. <ActionLayout
  131. itemList={this.actionList}
  132. selectedKeys={this.state.selectedKeys}
  133. onAction={key => this.onAction(key)}
  134. />
  135. <TableLayout
  136. columns={this.tableSort(this.columns)}
  137. list={this.state.list}
  138. pagination={this.state.page}
  139. loading={this.props.core.loading}
  140. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  141. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  142. selectedKeys={this.state.selectedKeys}
  143. />
  144. </Block>;
  145. }
  146. }