| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /**
- * 钱包明细页面
- * @邠心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 { 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 (
- <View style={this.props.shown ? ui.flex1 : styles.hide}>
- {/* <View style={ui.flexcc}>
- <Text style={styles.rangeText}>9th Aug to 12th Aug</Text>
- <MaterialIcons
- name='arrow-drop-down'
- color='#333'
- size={28}/>
- </View> */}
- <View style={styles.listView}>
- { this.state.historyList.length > 0
- ? this.state.historyList.map((item, index) => {
- return (
- <Pressable
- key={index}
- android_ripple={ripple}
- style={styles.itemView}
- onPress={() => {
- this.toSummary(index)
- }}>
- <Image
- style={styles.iconType}
- source={item.amountSymbol == 'M' ? IconCharge : IconPayment}/>
- <View style={styles.itemContent}>
- <View style={ui.flex1}>
- <Text style={styles.issueName}>{item.createTime + ': ' + (item.amountSymbol == 'M' ? item.siteName : 'Top Up ' + item.amount)}</Text>
- <Text style={styles.issueDesc}>Transaction ID: {item.creditRecordPk}</Text>
- </View>
- { item.amountSymbol == 'M'
- ? <Text style={styles.amountDuct}>- {item.amount}</Text>
- : <Text style={styles.amountText}>+ {item.amount}</Text>
- }
- </View>
- </Pressable>
- );
- })
- : <Text style={styles.noResult}>No data</Text>
- }
- </View>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- hide: {
- display: 'none'
- },
- rangeText: {
- color: '#000',
- fontSize: 14
- },
- listView: {
- marginTop: 16,
- backgroundColor: 'white'
- },
- noResult: {
- color: '#999',
- fontSize: 14,
- padding: 20,
- textAlign: 'center',
- },
- itemView: {
- paddingLeft: 16,
- paddingRight: 16,
- alignItems: 'center',
- flexDirection: 'row'
- },
- itemContent: {
- flex: 1,
- marginLeft: 16,
- paddingTop: 16,
- paddingLeft: 2,
- paddingRight: 2,
- paddingBottom: 16,
- borderBottomWidth: 1,
- borderBottomColor: '#eee',
- alignItems: 'center',
- flexDirection: 'row'
- },
- iconType: {
- width: 28,
- height: 28
- },
- issueName: {
- color: '#333',
- fontSize: 12,
- paddingBottom: 2
- },
- issueDesc: {
- color: '#999',
- fontSize: 11
- },
- amountDuct: {
- color: '#FF2E00',
- fontSize: 14
- },
- amountText: {
- color: '#333',
- fontSize: 14
- }
- })
|