History.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * 钱包明细页面
  3. * @邠心vbe on 2021/05/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, Pressable } from 'react-native';
  7. import apiWallet from '../../api/apiWallet';
  8. import { PageList } from '../Router';
  9. const IconCharge = require('../../images/wallet/ic-type-charge.png');
  10. const IconPayment = require('../../images/wallet/ic-type-payment.png');
  11. export default class History extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. historyList: []
  16. };
  17. this.refreshing = false;
  18. }
  19. componentDidMount() {
  20. this.getHistory(true);
  21. }
  22. componentDidUpdate() {
  23. if (this.props.refresh && !this.refreshing && this.props.shown) {
  24. this.refreshing = true;
  25. this.getHistory(true);
  26. }
  27. }
  28. getLastPk() {
  29. if (this.state.historyList.length > 0) {
  30. return this.state.historyList[this.state.historyList.length-1].creditRecordPk;
  31. }
  32. return null;
  33. }
  34. getHistory(refresh) {
  35. apiWallet.getTransactionList({latestPk: refresh ? '' : this.getLastPk()}).then(res => {
  36. this.stopRefresh();
  37. if (res.data) {
  38. if (refresh) {
  39. this.setState({
  40. historyList: res.data
  41. });
  42. } else {
  43. const list = this.state.historyList;
  44. this.setState({
  45. historyList: list.concat(res.data)
  46. });
  47. }
  48. }
  49. }).catch(err => {
  50. this.stopRefresh();
  51. });
  52. }
  53. stopRefresh() {
  54. if (this.props.refreshed) {
  55. this.props.refreshed();
  56. }
  57. this.refreshing = false;
  58. }
  59. toSummary(index) {
  60. const station = this.state.historyList[index];
  61. if (station.refPk) {
  62. startPage(PageList.summary, { action: 'view', chargingPk: station.refPk });
  63. }
  64. }
  65. render() {
  66. return (
  67. <View style={this.props.shown ? ui.flex1 : styles.hide}>
  68. {/* <View style={ui.flexcc}>
  69. <Text style={styles.rangeText}>9th Aug to 12th Aug</Text>
  70. <MaterialIcons
  71. name='arrow-drop-down'
  72. color='#333'
  73. size={28}/>
  74. </View> */}
  75. <View style={styles.listView}>
  76. { this.state.historyList.length > 0
  77. ? this.state.historyList.map((item, index) => {
  78. return (
  79. <Pressable
  80. key={index}
  81. android_ripple={ripple}
  82. style={styles.itemView}
  83. onPress={() => {
  84. this.toSummary(index)
  85. }}>
  86. <Image
  87. style={styles.iconType}
  88. source={item.amountSymbol == 'M' ? IconCharge : IconPayment}/>
  89. <View style={styles.itemContent}>
  90. <View style={ui.flex1}>
  91. <Text style={styles.issueName}>{item.createTime + ': ' + (item.amountSymbol == 'M' ? item.siteName : 'Top Up ' + item.amount)}</Text>
  92. <Text style={styles.issueDesc}>Transaction ID: {item.creditRecordPk}</Text>
  93. </View>
  94. { item.amountSymbol == 'M'
  95. ? <Text style={styles.amountDuct}>- {item.amount}</Text>
  96. : <Text style={styles.amountText}>+ {item.amount}</Text>
  97. }
  98. </View>
  99. </Pressable>
  100. );
  101. })
  102. : <Text style={styles.noResult}>No data</Text>
  103. }
  104. </View>
  105. </View>
  106. );
  107. }
  108. }
  109. const styles = StyleSheet.create({
  110. hide: {
  111. display: 'none'
  112. },
  113. rangeText: {
  114. color: '#000',
  115. fontSize: 14
  116. },
  117. listView: {
  118. marginTop: 16,
  119. backgroundColor: 'white'
  120. },
  121. noResult: {
  122. color: '#999',
  123. fontSize: 14,
  124. padding: 20,
  125. textAlign: 'center',
  126. },
  127. itemView: {
  128. paddingLeft: 16,
  129. paddingRight: 16,
  130. alignItems: 'center',
  131. flexDirection: 'row'
  132. },
  133. itemContent: {
  134. flex: 1,
  135. marginLeft: 16,
  136. paddingTop: 16,
  137. paddingLeft: 2,
  138. paddingRight: 2,
  139. paddingBottom: 16,
  140. borderBottomWidth: 1,
  141. borderBottomColor: '#eee',
  142. alignItems: 'center',
  143. flexDirection: 'row'
  144. },
  145. iconType: {
  146. width: 28,
  147. height: 28
  148. },
  149. issueName: {
  150. color: '#333',
  151. fontSize: 12,
  152. paddingBottom: 2
  153. },
  154. issueDesc: {
  155. color: '#999',
  156. fontSize: 11
  157. },
  158. amountDuct: {
  159. color: '#FF2E00',
  160. fontSize: 14
  161. },
  162. amountText: {
  163. color: '#333',
  164. fontSize: 14
  165. }
  166. })