/** * 钱包明细页面 * @邠心vbe on 2021/05/08 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, Image, Pressable } from 'react-native'; import apiWallet from '../../api/apiWallet'; import TextView from '../../components/TextView'; 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 History extends Component { constructor(props) { super(props); this.state = { historyList: [] }; this.refreshing = false; } componentDidMount() { this.getHistory(true); } componentDidUpdate() { if (this.props.refresh && !this.refreshing && this.props.shown) { this.refreshing = true; this.getHistory(true); } } getLastPk() { if (this.state.historyList.length > 0) { return this.state.historyList[this.state.historyList.length-1].creditRecordPk; } return null; } getHistory(refresh) { apiWallet.getTransactionList({latestPk: refresh ? '' : this.getLastPk()}).then(res => { this.stopRefresh(); if (res.data) { if (refresh) { this.setState({ historyList: res.data }); } else { const list = this.state.historyList; this.setState({ historyList: list.concat(res.data) }); } } }).catch(err => { this.stopRefresh(); }); } stopRefresh() { if (this.props.refreshed) { this.props.refreshed(); } this.refreshing = false; } toSummary(index) { const station = this.state.historyList[index]; if (station.refPk) { startPage(PageList.summary, { action: 'view', chargingPk: station.refPk }); } } render() { return ( {/* 9th Aug to 12th Aug */} { this.state.historyList.length > 0 ? this.state.historyList.map((item, index) => { return ( { this.toSummary(index) }}> 0 && styles.divide]}> {item.createTime + ': ' + (item.amountSymbol == 'M' ? item.siteName : $t('wallet.topUp') + ' ' + item.amount)} {$t('wallet.labelTransactionId') + item.creditRecordPk} { item.amountSymbol == 'M' ? - {item.amount} : + {item.amount} } ); }) : {$t('wallet.noHistoryData')} } ); } } const styles = StyleSheet.create({ hide: { display: 'none' }, rangeText: { color: '#000', fontSize: 14 }, listView: { marginTop: 16, minHeight: $vh(30), backgroundColor: colorLight }, noResult: { color: '#999', fontSize: 14, padding: 20, lineHeight: $vh(20), textAlign: 'center', }, itemView: { paddingLeft: 16, paddingRight: 16, alignItems: 'center', flexDirection: 'row' }, itemContent: { flex: 1, marginLeft: 16, ...$padding(16, 4), alignItems: 'center', flexDirection: 'row' }, divide: { borderTopWidth: 1, borderTopColor: '#eee', }, iconType: { width: 28, height: 28 }, issueName: { color: textPrimary, fontSize: 12, paddingBottom: 2 }, issueDesc: { color: '#999', fontSize: 11 }, amountDuct: { color: '#FF2E00', fontSize: 14 }, amountText: { color: textPrimary, fontSize: 14 } })