page.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import './index.less';
  3. import { DatePicker } from 'antd-mobile';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { formatDate } from '@src/services/Tools';
  7. import { Textbook } from '../../../stores/textbook';
  8. export default class extends Page {
  9. initState() {
  10. return {
  11. date: new Date(),
  12. };
  13. }
  14. initData() {
  15. Textbook.getInfo()
  16. .then(result => {
  17. this.setState(result);
  18. });
  19. this.refreshYear(this.state.date);
  20. }
  21. refreshYear(date) {
  22. this.setState({ date });
  23. Textbook.listYear(date.getFullYear())
  24. .then((list) => {
  25. const map = {};
  26. list.forEach((row) => {
  27. const d = new Date(row.startDate);
  28. const month = d.getMonth() + 1;
  29. if (!map[month]) {
  30. map[month] = [];
  31. }
  32. map[month].push(d.getDate());
  33. });
  34. const months = Object.keys(map).map(key => {
  35. return {
  36. value: key,
  37. list: map[key],
  38. };
  39. });
  40. this.setState({ months });
  41. });
  42. }
  43. renderView() {
  44. const { latest = {}, date, months = [] } = this.state;
  45. return (
  46. <div>
  47. <div className="title">最新换库</div>
  48. <div className="main">{latest.startDate ? formatDate(latest.startDate, 'YYYY年MM月DD日') : ''}</div>
  49. <div className="title">
  50. 历史记录
  51. <div className="date">
  52. <DatePicker value={date} mode="year" onChange={value => {
  53. this.refreshYear(value);
  54. }}>
  55. <div>
  56. {date.getFullYear()}年
  57. <Assets name="down_down3" />
  58. </div>
  59. </DatePicker>
  60. </div>
  61. </div>
  62. <div className="list">
  63. {(months || []).map(month => {
  64. return <div className="item">
  65. <div className="d">{month.value}月</div>
  66. <div className="v">
  67. {month.list.map(row => {
  68. return <span>{row}</span>;
  69. })}
  70. </div>
  71. </div>;
  72. })}
  73. </div>
  74. </div>
  75. );
  76. }
  77. }