/** * 交易历史页面 * @邠心vbe on 2024/03/29 */ import React, { Component } from 'react'; import { View, Text, RefreshControl, FlatList, StyleSheet, Pressable, Image } from 'react-native'; import { MyRefreshProps } from '../../components/ThemesConfig'; import apiWallet from '../../api/apiWallet'; import TextView from '../../components/TextView'; import Dialog from '../../components/Dialog'; import { PageList } from '../Router'; const IconCharge = require('../../images/wallet/ic-type-charge.png'); const IconPayment = require('../../images/wallet/ic-type-payment.png'); export default class HistoryList 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("[Wallet History]", "getNextPage"); const last = this.state.dataList[this.state.dataList.length-1] this.getHistoryList(last.creditRecordPk); } } getHistoryList(lastPk="") { apiWallet.getTransactionListV2({latestPk: 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(); }); } toSummary(item) { if (item.refPk) { startPage(PageList.summary, { action: 'view', chargingPk: item.refPk }); } } getTransTitle(item) { if (item.amountSymbol == 'M') { return "Charging Session"; } else { return "Purchase Credits"; } } listItem = ({item, index, separators}) => { return ( { this.toSummary(item) }}> {/* */} {this.getTransTitle(item)} {item.createTime} { item.amountSymbol == 'M' ? {item.siteName || "Charging"} : {$t('wallet.topUp') + ", " + item.amount} } {$t('wallet.labelTransactionId') + item.creditRecordPk} { item.amountSymbol == 'M' ? - {item.amount} : + {item.amount} } ) } divideView = (props) => { return () } bottomView = () => { if (!this.state.hasMore) { return ({$t('wallet.noMore')}) } else { return null } } render() { return ( item.creditRecordPk} onEndReached={() => this.getNextPage()} onEndReachedThreshold={0.3} refreshControl={ this.onRefresh()} /> } ListEmptyComponent={{$t('wallet.noHistoryData')}} /> ); } } const styles = StyleSheet.create({ listView: { flex: 1 }, itemView: { paddingLeft: 16, paddingRight: 16, alignItems: 'center', flexDirection: 'row' }, itemContent: { flex: 1, //marginLeft: 16, ...$padding(16, 4), alignItems: 'flex-start', flexDirection: 'row' }, divide: { marginLeft: 16, marginRight: 16, borderTopWidth: 1, borderTopColor: '#eee', }, iconType: { width: 28, height: 28 }, 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: 14, padding: 20, textAlign: 'center' }, noMore: { color: textPlacehoder, fontSize: 14, padding: 16, textAlign: 'center' } })