import React from 'react'; import './index.less'; import { DatePicker } from 'antd-mobile'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import { formatDate } from '@src/services/Tools'; import { Textbook } from '../../../stores/textbook'; export default class extends Page { initState() { return { date: new Date(), }; } initData() { Textbook.getInfo() .then(result => { this.setState(result); }); this.refreshYear(this.state.date); } refreshYear(date) { this.setState({ date }); Textbook.listYear(date.getFullYear()) .then((list) => { const map = {}; list.forEach((row) => { const d = new Date(row.startDate); const month = d.getMonth() + 1; if (!map[month]) { map[month] = []; } map[month].push(d.getDate()); }); const months = Object.keys(map).map(key => { return { value: key, list: map[key], }; }); this.setState({ months }); }); } renderView() { const { latest = {}, date, months = [] } = this.state; return (
最新换库
{latest.startDate ? formatDate(latest.startDate, 'YYYY年MM月DD日') : ''}
历史记录
{ this.refreshYear(value); }}>
{date.getFullYear()}年
{(months || []).map(month => { return
{month.value}月
{month.list.map(row => { return {row}; })}
; })}
); } }