import React, {Component} from 'react'; import { View, FlatList, Text, ActivityIndicator, RefreshControl, Alert, SafeAreaView, } from 'react-native'; import {List, SwipeAction, WingBlank} from '@ant-design/react-native'; import public_css from '../../source/css/public_css'; import {RetrieveData} from '../../data/storage'; import {RequestNetwork} from '../../data/encryption'; import notice_css from './notice_css'; import {ToastShow} from '../../components/toast/toast'; import {CleanAll} from '../../components/abnormalMessage/abnormal_message'; let pageNo = 1; //当前第几页 let totalPage = 5; //总的页数 export default class notice_message extends Component { constructor(props) { super(props); this.state = { listData: [], showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中 isLoading: false, }; } render() { return ( this.renderItem(item)} refreshControl={ { this.initData(); }} /> } ListFooterComponent={() => this.renderFooter()} onEndReached={() => this.onEndReached()} onEndReachedThreshold={0.1} /> ); } //页面加载完成后加载数据 async componentDidMount(): void { await this.getNoticeMessageList(); } //数据初始化 initData = async () => { this.setState({ listData: [], isLoading: false, showFoot: 0, }); pageNo = 1; await this.getNoticeMessageList(); }; //上拉加载 onEndReached = () => { if (this.state.showFoot === 0) { if (pageNo >= totalPage) { this.setState({showFoot: 1}); return; } else { pageNo++; this.setState({showFoot: 2}); //获取数据 this.getNoticeMessageList(); } } }; //列表尾部显示 renderFooter = () => { if (this.state.showFoot === 1) { return ( 没有更多数据了 ); } else if (this.state.showFoot === 2) { return ( 正在加载更多数据... ); } else if (this.state.showFoot === 0) { return ( ); } }; //获取公告列表数据 getNoticeMessageList = async () => { let account = await RetrieveData('account'); let token = await RetrieveData('token'); if (token && account) { const url = '/auth/user/msg/findGlobalNotice'; let res = await RequestNetwork( url, token, { mobile: account, pageNum: pageNo, pageSize: 10, }, false, 2, ); if (res) { if (res.code === 0) { totalPage = res.data.pages; this.setList(res.data.records); } else { await this.abnormalMessage(res); } } } }; //设置抬头列表 setList = (data) => { let listDatas = data.map((_, i) => ({ key: data[i].msgId, msgType: data[i].msgType, msgTitle: data[i].msgTitle, msgBrief: data[i].msgBrief, hasRead: data[i].hasRead, createTime: data[i].createTime, })); let list = this.state.listData.concat(listDatas); this.setState({ listData: list, showFoot: 0, }); }; //显示发票抬头列表 renderItem = (data) => ( {data.item.msgTitle} 简介:{data.item.msgBrief} {data.item.createTime} ); // 处理网络请求数据 abnormalMessage = async (jason) => { if (jason.code === 401) { await Alert.alert( '登录失效', '登录状态已失效,请重新登录!', [ { text: '确定', onPress: () => { CleanAll(); this.props.navigation.popToTop(); }, }, ], {cancelable: false}, ); } if (jason.code === 403) { Alert.alert( '权限', '暂无权限操作此模块!', [ { text: '确定', onPress: () => { this.props.navigation.goBack(); }, }, ], {cancelable: false}, ); } if (jason.code !== 401 && jason.code !== 403) { ToastShow(1, jason.msg); } }; }