page.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Footer from '../../../components/Footer';
  6. import { Contact } from '../../../components/Other';
  7. import Select from '../../../components/Select';
  8. import UserTable from '../../../components/UserTable';
  9. import { Textbook } from '../../../stores/textbook';
  10. import { Main } from '../../../stores/main';
  11. import { TextbookSubject, TextbookQuality, TextbookType } from '../../../../Constant';
  12. import { getMap, formatDate } from '../../../../../src/services/Tools';
  13. const TextbookSubjectMap = getMap(TextbookSubject, 'value', 'label');
  14. const TextbookQualityMap = getMap(TextbookQuality, 'value', 'label');
  15. const TextbookTypeMap = getMap(TextbookType, 'value', 'label');
  16. export default class extends Page {
  17. initState() {
  18. return {
  19. subject: TextbookSubject[0].value,
  20. textbookSubject: TextbookSubject.map(row => {
  21. return {
  22. title: row.label,
  23. key: row.value,
  24. };
  25. }),
  26. textbookQuality: TextbookQuality.map(row => {
  27. return {
  28. title: row.label,
  29. key: row.value,
  30. };
  31. }),
  32. textbookType: TextbookType.map(row => {
  33. return {
  34. title: row.label,
  35. key: row.value,
  36. };
  37. }),
  38. };
  39. }
  40. init() {
  41. Main.getBase()
  42. .then(result => {
  43. this.setState({ base: result });
  44. });
  45. Textbook.getInfo()
  46. .then(result => {
  47. if (!result.hasService) {
  48. linkTo('/textbook');
  49. }
  50. this.setState({ data: result });
  51. });
  52. }
  53. initData() {
  54. const { subject } = this.params;
  55. const data = Object.assign(this.state, this.state.search);
  56. if (data.order) {
  57. data.sortMap = { [data.order]: data.direction };
  58. }
  59. data.filterMap = this.state.search;
  60. this.setState(data);
  61. Textbook.listTopic(Object.assign({ latest: true, subject, order: 'no', direction: 'desc' }, this.state.search, { isOld: !!this.state.search.month }))
  62. .then(result => {
  63. if (this.state.search.page === 1) {
  64. result.list = result.list.map(row => {
  65. row.new = '';
  66. return row;
  67. });
  68. }
  69. this.setState({ list: result.list, total: result.total });
  70. });
  71. }
  72. filter(data) {
  73. data.page = 1;
  74. this.search(data);
  75. }
  76. changeSubject(subject) {
  77. linkTo(`/textbook/topic/list/${subject}`);
  78. }
  79. renderView() {
  80. const { subject } = this.params;
  81. const { base = {}, textbookSubject, textbookQuality, textbookType, keyword, quality, month, data = {}, list = [], page, total } = this.state;
  82. const { latest = {} } = data;
  83. return (
  84. <div>
  85. <div className="top content t-8">
  86. 机经 > 本期机经 > <span className="t-1">{TextbookSubjectMap[subject]}</span>
  87. <Select className="f-r m-t-1" size="small" theme="white" value={subject} list={textbookSubject} onChange={({ key }) => this.changeSubject(key)} />
  88. </div>
  89. <div className="center content">
  90. <div className="t-1 t-s-18 m-b-1">
  91. 【{TextbookSubjectMap[subject]}】{latest.startDate && formatDate(latest.startDate, 'MMDD')} 起{TextbookSubjectMap[subject]}机经整理
  92. <Select className="f-r m-l-1" size="small" theme="default" value={quality} placeholder={'机经质量'} list={textbookQuality} onChange={({ key }) => this.filter({ quality: key })} />
  93. <Select
  94. className="f-r m-l-1"
  95. size="small"
  96. theme="default"
  97. value={month}
  98. list={[{ title: '本月', key: '' }, { title: '考古', key: '1' }]}
  99. onChange={({ key }) => this.filter({ month: key })}
  100. />
  101. {subject === 'quant' && <Select
  102. className="f-r m-l-1"
  103. size="small"
  104. theme="default"
  105. value={keyword}
  106. list={textbookType}
  107. placeholder={'题型'}
  108. onChange={({ key }) => this.filter({ keyword: key })}
  109. />}
  110. </div>
  111. <UserTable
  112. size="small"
  113. data={list}
  114. current={page}
  115. pageSize={this.state.search.size}
  116. total={total}
  117. jump
  118. columns={[
  119. {
  120. title: '文章编号',
  121. key: 'no',
  122. sort: true,
  123. render: (text) => {
  124. return <Link to={`/textbook/topic/detail/${subject}?no=${text}`}>{text}</Link>;
  125. },
  126. },
  127. { title: '关键词', key: 'keyword', render: (text) => (subject === 'quant' ? TextbookTypeMap[text] : text) },
  128. { title: '机经质量', key: 'quality', render: (text) => TextbookQualityMap[text] || '' },
  129. ]}
  130. />
  131. </div>
  132. <Contact data={base.contact} />
  133. <Footer />
  134. </div>
  135. );
  136. }
  137. }