History.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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={colorDark}
  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. resizeMode="contain"
  89. source={item.amountSymbol == 'M' ? IconCharge : IconPayment}/>
  90. <View style={[styles.itemContent, index > 0 && styles.divide]}>
  91. <View style={ui.flex1}>
  92. <Text style={styles.issueName}>{item.createTime + ': ' + (item.amountSymbol == 'M' ? item.siteName : 'Top Up ' + item.amount)}</Text>
  93. <Text style={styles.issueDesc}>Transaction ID: {item.creditRecordPk}</Text>
  94. </View>
  95. { item.amountSymbol == 'M'
  96. ? <Text style={styles.amountDuct}>- {item.amount}</Text>
  97. : <Text style={styles.amountText}>+ {item.amount}</Text>
  98. }
  99. </View>
  100. </Pressable>
  101. );
  102. })
  103. : <Text style={styles.noResult}>No data</Text>
  104. }
  105. </View>
  106. </View>
  107. );
  108. }
  109. }
  110. const styles = StyleSheet.create({
  111. hide: {
  112. display: 'none'
  113. },
  114. rangeText: {
  115. color: '#000',
  116. fontSize: 14
  117. },
  118. listView: {
  119. marginTop: 16,
  120. minHeight: $vh(30),
  121. backgroundColor: colorLight
  122. },
  123. noResult: {
  124. color: '#999',
  125. fontSize: 14,
  126. padding: 20,
  127. lineHeight: $vh(20),
  128. textAlign: 'center',
  129. },
  130. itemView: {
  131. paddingLeft: 16,
  132. paddingRight: 16,
  133. alignItems: 'center',
  134. flexDirection: 'row'
  135. },
  136. itemContent: {
  137. flex: 1,
  138. marginLeft: 16,
  139. ...$padding(16, 4),
  140. alignItems: 'center',
  141. flexDirection: 'row'
  142. },
  143. divide: {
  144. borderTopWidth: 1,
  145. borderTopColor: '#eee',
  146. },
  147. iconType: {
  148. width: 28,
  149. height: 28
  150. },
  151. issueName: {
  152. color: textPrimary,
  153. fontSize: 12,
  154. paddingBottom: 2
  155. },
  156. issueDesc: {
  157. color: '#999',
  158. fontSize: 11
  159. },
  160. amountDuct: {
  161. color: '#FF2E00',
  162. fontSize: 14
  163. },
  164. amountText: {
  165. color: textPrimary,
  166. fontSize: 14
  167. }
  168. })