/** * 交易历史页面 * @邠心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'; import VbeSkeleton from '../../components/VbeSkeleton'; 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 = { loading: true, dataList: [], hasMore: true, refreshing: false, loadingList: ["", "", "", ""] }; } componentDidMount() { setTimeout(() => { this.getHistoryList(); }, 500); } 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({ loading: false, refreshing: false }); }); } toSummary(item) { if (item.refPk) { startPage(PageList.summary, { action: 'view', chargingPk: item.refPk }); } } getTransTitle(item) { let title = item.createTime; if (item.remarks) { title += ': ' + item.remarks; } else if (item.amountSymbol == 'M') { title += ': ' + (item.siteName || "Charging"); } else { title += ': ' + $t('wallet.topUp'); } return title; } listItem = ({item, index, separators}) => { return ( { this.toSummary(item) }}> {this.getTransTitle(item)} {$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() { if (this.state.loading) { return ( { this.state.loadingList.map((item, index) => )} ) } else { 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: 'center', flexDirection: 'row' }, divide: { marginLeft: 60, marginRight: 16, borderTopWidth: 1, borderTopColor: '#eee', }, iconType: { width: 32, height: 32 }, issueName: { color: textPrimary, fontSize: 12, paddingBottom: 2 }, issueDesc: { color: '#999', fontSize: 11 }, amountDuct: { color: '#FF2E00', fontSize: 14, paddingLeft: 8 }, amountText: { color: textPrimary, fontSize: 14, paddingLeft: 8 }, noData: { color: textPlacehoder, fontSize: 14, padding: 20, textAlign: 'center' }, noMore: { color: textPlacehoder, fontSize: 14, padding: 16, textAlign: 'center' } })