page.js 3.2 KB

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