History.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. getTransTitle(item) {
  67. let title = item.createTime;
  68. if (item.remarks) {
  69. title += ': ' + item.remarks;
  70. } else if (item.amountSymbol == 'M') {
  71. title += ': ' + (item.siteName || "Charging");
  72. } else {
  73. title += ': ' + $t('wallet.topUp');
  74. }
  75. return title;
  76. }
  77. render() {
  78. return (
  79. <View style={this.props.shown ? ui.flex1 : styles.hide}>
  80. {/* <View style={ui.flexcc}>
  81. <Text style={styles.rangeText}>9th Aug to 12th Aug</Text>
  82. <MaterialIcons
  83. name='arrow-drop-down'
  84. color={colorDark}
  85. size={28}/>
  86. </View> */}
  87. <View style={styles.listView}>
  88. { this.state.historyList.length > 0
  89. ? this.state.historyList.map((item, index) => {
  90. return (
  91. <Pressable
  92. key={index}
  93. android_ripple={ripple}
  94. style={styles.itemView}
  95. onPress={() => {
  96. this.toSummary(index)
  97. }}>
  98. <Image
  99. style={styles.iconType}
  100. resizeMode="contain"
  101. source={(item.amountSymbol == 'P' || item.remarks) ? IconPayment : IconCharge}/>
  102. <View style={[styles.itemContent, index > 0 && styles.divide]}>
  103. <View style={ui.flex1}>
  104. <TextView style={styles.issueName}>{this.getTransTitle(item)}</TextView>
  105. <TextView style={styles.issueDesc}>{$t('wallet.labelTransactionId') + item.creditRecordPk}</TextView>
  106. </View>
  107. { item.amountSymbol == 'M'
  108. ? <TextView style={styles.amountDuct}>- {item.amount}</TextView>
  109. : <TextView style={styles.amountText}>+ {item.amount}</TextView>
  110. }
  111. </View>
  112. </Pressable>
  113. );
  114. })
  115. : <Text style={styles.noResult}>{$t('wallet.noHistoryData')}</Text>
  116. }
  117. </View>
  118. </View>
  119. );
  120. }
  121. }
  122. const styles = StyleSheet.create({
  123. hide: {
  124. display: 'none'
  125. },
  126. rangeText: {
  127. color: '#000',
  128. fontSize: 14
  129. },
  130. listView: {
  131. marginTop: 16,
  132. minHeight: $vh(30),
  133. backgroundColor: colorLight
  134. },
  135. noResult: {
  136. color: '#999',
  137. fontSize: 14,
  138. padding: 20,
  139. lineHeight: $vh(20),
  140. textAlign: 'center',
  141. },
  142. itemView: {
  143. paddingLeft: 16,
  144. paddingRight: 16,
  145. alignItems: 'center',
  146. flexDirection: 'row'
  147. },
  148. itemContent: {
  149. flex: 1,
  150. marginLeft: 16,
  151. ...$padding(16, 4),
  152. alignItems: 'center',
  153. flexDirection: 'row'
  154. },
  155. divide: {
  156. borderTopWidth: 1,
  157. borderTopColor: '#eee',
  158. },
  159. iconType: {
  160. width: 28,
  161. height: 28
  162. },
  163. issueName: {
  164. color: textPrimary,
  165. fontSize: 12,
  166. paddingBottom: 2
  167. },
  168. issueDesc: {
  169. color: '#999',
  170. fontSize: 11
  171. },
  172. amountDuct: {
  173. color: '#FF2E00',
  174. fontSize: 14
  175. },
  176. amountText: {
  177. color: textPrimary,
  178. fontSize: 14
  179. }
  180. })