import React from 'react'; import { Badge, ListView } from 'antd-mobile'; import './index.less'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import { formatDate } from '@src/services/Tools'; import ListData from '@src/services/ListData'; import { My } from '../../../stores/my'; export default class extends Page { initState() { return { listMap: {}, }; } initData() { return this.initListKeys(['message']) .then(() => { return this.getList('message', 1); }); } initListKeys(keys) { const { listMap } = this.state; keys.forEach((key) => { listMap[key] = new ListData(); }); this.setState({ listMap }); return Promise.resolve(); } getList(key, page) { My.message(Object.assign({ page }, this.state.search)) .then((result) => { const { listMap } = this.state; if (page === 1) { // todo 是否重新读取第一页为刷新所有数据 listMap[key] = new ListData(); } listMap[key].get(page, result, this.state.search.size); this.setState({ listMap }); }); } readAll() { My.readAllMessage() .then(() => { this.refresh(); }); } renderView() { return (
{ this.readAll(); }}> 全部已读2
{this.renderList()}
); } renderRow(rowData) { return
{rowData.title} {rowData.isRead > 0 && }
{rowData.description}
{rowData.link && 查看详情}
{formatDate(rowData.createTime, 'YYYY-MM-DD')}
{formatDate(rowData.createTime, 'HH:mm:ss')}
; } renderList() { const { listMap } = this.state; const { message = {} } = listMap; const { dataSource = {}, bottom, loading, finish, maxSectionId = 1, total } = message; if (total === 0) return this.renderEmpty(); return { this.lv = el; }} dataSource={dataSource} renderFooter={() => (
{loading ? '加载中...' : (bottom ? '没有更多了' : '')}
)} renderRow={(rowData, sectionID, rowID) => this.renderRow(rowData, sectionID, rowID)} style={{ height: this.state.height, overflow: 'auto', }} pageSize={this.state.search.size} scrollRenderAheadDistance={500} onEndReached={() => { if (loading) return; if (bottom) { if (!finish) { message.finish = true; // this.setState({ time: new Date() }) } return; } this.getList('message', maxSectionId + 1); }} onEndReachedThreshold={10} />; } renderEmpty() { return
; } }