History.js 4.5 KB

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