page.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 { TextbookMinYear, TextbookSubject } from '../../../../Constant';
  12. import { formatDate } from '../../../../../src/services/Tools';
  13. export default class extends Page {
  14. initState() {
  15. const yearList = [];
  16. const nowYear = new Date().getFullYear();
  17. for (let i = TextbookMinYear; i <= nowYear; i += 1) {
  18. yearList.push({
  19. title: i.toString(),
  20. key: i.toString(),
  21. });
  22. }
  23. return {
  24. subject: TextbookSubject[0].value,
  25. year: nowYear,
  26. yearList,
  27. textbookSubject: TextbookSubject.map(row => {
  28. return {
  29. title: row.label,
  30. key: row.value,
  31. };
  32. }),
  33. };
  34. }
  35. init() {
  36. Main.getBase()
  37. .then(result => {
  38. this.setState({ base: result });
  39. });
  40. }
  41. initData() {
  42. const data = Object.assign(this.state, this.state.search);
  43. if (data.order) {
  44. data.sortMap = { [data.order]: data.direction };
  45. }
  46. data.filterMap = this.state.search;
  47. this.setState(data);
  48. Textbook.getInfo()
  49. .then(result => {
  50. this.setState(result);
  51. });
  52. console.log(this.state);
  53. this.refreshYear(this.state.year);
  54. }
  55. refreshYear(year) {
  56. this.setState({ year });
  57. Textbook.listYear(year)
  58. .then((list) => {
  59. const monthMap = {};
  60. let lastTime = null;
  61. list.forEach((row) => {
  62. const d = new Date(row.startDate);
  63. const month = d.getMonth() + 1;
  64. row.month = month;
  65. if (lastTime) {
  66. row.period = parseInt((d.getTime() - lastTime.getTime()) / 86400000, 10) - 1;
  67. } else {
  68. row.period = 0;
  69. }
  70. lastTime = d;
  71. if (!monthMap[month]) {
  72. monthMap[month] = [];
  73. }
  74. monthMap[month].push(d.getDate());
  75. });
  76. this.setState({ monthMap, list });
  77. });
  78. }
  79. renderView() {
  80. const { base = {}, yearList, year, monthMap, list } = this.state;
  81. return (
  82. <div>
  83. <div className="top content t-8">
  84. <Link to="/textbook">机经</Link> > <span className="t-1">按年份查询</span>
  85. </div>
  86. <div className="center content">
  87. <div className="t-1 t-s-18 m-b-1">
  88. GMAT历年换库记录
  89. <Select className="f-r" size="small" theme="default" value={year} placeholder={'年份'} list={yearList} onChange={({ key }) => this.refreshYear(key)} />
  90. </div>
  91. <UserTable
  92. size="small"
  93. data={list}
  94. columns={[
  95. { title: '更新时间', key: 'startDate', render: (text) => formatDate(text, 'YYYY-MM-DD') },
  96. { title: '间隔天数', key: 'period' },
  97. { title: '当月换库次数(次)', key: 'month', render: (text) => (monthMap[text] ? monthMap[text].length : 0) },
  98. ]}
  99. />
  100. </div>
  101. <Contact data={base.contact} />
  102. <Footer />
  103. </div>
  104. );
  105. }
  106. }