/** * 积分历史列表页面 * @邠心vbe on 2024/05/07 */ import React, { Component } from 'react'; import { View, Text, RefreshControl, FlatList, StyleSheet } from 'react-native'; import { MyRefreshProps } from '../../components/ThemesConfig'; import TextView from '../../components/TextView'; import Dialog from '../../components/Dialog'; import apiVoucher from '../../api/apiVoucher'; import app from '../../../app.json'; export default class PointsHistory extends Component { constructor(props) { super(props); this.state = { dataList: [], hasMore: true, refreshing: false }; } componentDidMount() { Dialog.showProgressDialog(); this.getHistoryList(); } onRefresh() { this.setState({ refreshing: true }) this.getHistoryList(); } getNextPage() { if (this.state.dataList.length > 0 && this.state.hasMore) { console.log("[Points History]", "getNextPage"); const last = this.state.dataList[this.state.dataList.length-1] this.getHistoryList(last.pointsHistoryId); } } getHistoryList(lastPk="") { apiVoucher.getPointsHistory(lastPk).then(res => { if (res.data) { if (lastPk) { if (res.data.length > 0) { const list = this.state.dataList; this.setState({ dataList: list.concat(res.data) }); } else { this.setState({ hasMore: false }) } } else { this.setState({ dataList: res.data, hasMore: true }); } } else { this.setState({ dataList: [] }); } }).catch(err => { toastShort(err) }).finally(() => { this.setState({ refreshing: false }); Dialog.dismissLoading(); }); } listItem = ({item, index, separators}) => { return ( {item.remarks} {item.dateTime} {(item.siteName ?? item.voucherName) + (item.chargeBoxId ? ", " + item.chargeBoxId : "")} {"Transaction ID: " + item.refId} { item.action == "Increase" ? + {item.points} : - {item.points} } ) } divideView = (props) => { return () } bottomView = () => { if (!this.state.hasMore) { return ({$t('wallet.noMore')}) } else { return null } } render() { return ( item.pointsHistoryId} onEndReached={() => this.getNextPage()} onEndReachedThreshold={0.3} refreshControl={ this.onRefresh()} /> } ListEmptyComponent={{$t('points.noData')}} /> ); } } const styles = StyleSheet.create({ listView: { flex: 1 }, itemView: { paddingLeft: 16, paddingRight: 16, alignItems: 'center', flexDirection: 'row' }, itemContent: { flex: 1, //marginLeft: 8, ...$padding(16, 4), alignItems: 'flex-start', flexDirection: 'row' }, divide: { marginLeft: 16, marginRight: 16, borderTopWidth: 1, borderTopColor: '#eee', }, iconType: { width: 28, height: 28, textAlign: 'center', lineHeight: 27, borderWidth: 1, borderRadius: 30, borderColor: textPrimary }, issueName: { color: textPrimary, fontSize: 14, paddingBottom: 2 }, issueDesc: { color: textSecondary, fontSize: 12 }, amountDuct: { color: '#FF2E00', fontSize: 14, paddingLeft: 8 }, amountText: { color: colorPrimary, fontSize: 14, paddingLeft: 8 }, noData: { color: textPlacehoder, fontSize: 12, padding: 20, textAlign: 'center' }, noMore: { color: textPlacehoder, fontSize: 12, padding: 16, textAlign: 'center' } })