History.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * 钱包明细页面
  3. * @邠心vbe on 2021/05/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, Pressable, TouchableOpacity } from 'react-native';
  7. import apiWallet from '../../api/apiWallet';
  8. import TextView from '../../components/TextView';
  9. import { PageList } from '../Router';
  10. import app from '../../../app.json';
  11. const IconCharge = require('../../images/wallet/ic-type-charge.png');
  12. const IconPayment = require('../../images/wallet/ic-type-payment.png');
  13. export default class History extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. historyList: []
  18. };
  19. this.refreshing = false;
  20. }
  21. componentDidMount() {
  22. this.getHistory();
  23. }
  24. componentDidUpdate() {
  25. if (this.props.refresh && !this.refreshing && this.props.shown) {
  26. this.refreshing = true;
  27. this.getHistory();
  28. }
  29. }
  30. getLastPk() {
  31. if (this.state.historyList.length > 0) {
  32. return this.state.historyList[this.state.historyList.length-1].creditRecordPk;
  33. }
  34. return null;
  35. }
  36. getHistory() {
  37. if (app.v3.overview) {
  38. this.getHistoryV2();
  39. return;
  40. }
  41. apiWallet.getTransactionList({latestPk: ''}).then(res => {
  42. this.stopRefresh();
  43. if (res.data) {
  44. this.setState({
  45. historyList: res.data
  46. });
  47. }
  48. }).catch(err => {
  49. this.setState({
  50. historyList: []
  51. });
  52. this.stopRefresh();
  53. });
  54. }
  55. getHistoryV2() {
  56. apiWallet.getTransactionListV2({latestPk: ''}).then(res => {
  57. this.stopRefresh();
  58. if (res.data && res.data.length) {
  59. this.setState({
  60. historyList: res.data.slice(10)
  61. });
  62. } else {
  63. this.setState({
  64. historyList: []
  65. });
  66. }
  67. }).catch(err => {
  68. this.setState({
  69. historyList: []
  70. });
  71. this.stopRefresh();
  72. });
  73. }
  74. stopRefresh() {
  75. if (this.props.refreshed) {
  76. this.props.refreshed();
  77. }
  78. this.refreshing = false;
  79. }
  80. toSummary(index) {
  81. const station = this.state.historyList[index];
  82. if (station.refPk) {
  83. startPage(PageList.summary, { action: 'view', chargingPk: station.refPk });
  84. }
  85. }
  86. getTransTitle(item) {
  87. let title = item.createTime;
  88. if (item.remarks) {
  89. title += ': ' + item.remarks;
  90. } else if (item.amountSymbol == 'M') {
  91. title += ': ' + (item.siteName || "Charging");
  92. } else {
  93. title += ': ' + $t('wallet.topUp');
  94. }
  95. return title;
  96. }
  97. toHistoryList() {
  98. startPage(PageList.history);
  99. }
  100. render() {
  101. return (
  102. <View style={this.props.shown ? ui.flex1 : styles.hide}>
  103. {/* <View style={ui.flexcc}>
  104. <Text style={styles.rangeText}>9th Aug to 12th Aug</Text>
  105. <MaterialIcons
  106. name='arrow-drop-down'
  107. color={colorDark}
  108. size={28}/>
  109. </View> */}
  110. <View style={styles.listView}>
  111. { this.state.historyList.length > 0
  112. ? <>
  113. {
  114. this.state.historyList.map((item, index) => {
  115. return (
  116. <Pressable
  117. key={index}
  118. android_ripple={ripple}
  119. style={styles.itemView}
  120. onPress={() => {
  121. this.toSummary(index)
  122. }}>
  123. <Image
  124. style={styles.iconType}
  125. resizeMode="contain"
  126. source={(item.amountSymbol == 'P' || item.remarks) ? IconPayment : IconCharge}/>
  127. <View style={[styles.itemContent, index > 0 && styles.divide]}>
  128. <View style={ui.flex1}>
  129. <TextView style={styles.issueName}>{this.getTransTitle(item)}</TextView>
  130. <TextView style={styles.issueDesc}>{$t('wallet.labelTransactionId') + item.creditRecordPk}</TextView>
  131. </View>
  132. { item.amountSymbol == 'M'
  133. ? <TextView style={styles.amountDuct}>- {item.amount}</TextView>
  134. : <TextView style={styles.amountText}>+ {item.amount}</TextView>
  135. }
  136. </View>
  137. </Pressable>
  138. );
  139. })
  140. }
  141. </>
  142. : <Text style={styles.noResult}>{$t('wallet.noHistoryData')}</Text>
  143. }
  144. </View>
  145. { (app.v3.overview && this.state.historyList.length > 0) &&
  146. <TouchableOpacity
  147. style={styles.moreButton}
  148. activeOpacity={0.4}
  149. onPress={() => this.toHistoryList()}>
  150. <Text
  151. style={ui.link}>
  152. {$t("wallet.viewMore")}
  153. </Text>
  154. </TouchableOpacity>
  155. }
  156. </View>
  157. );
  158. }
  159. }
  160. const styles = StyleSheet.create({
  161. hide: {
  162. display: 'none'
  163. },
  164. rangeText: {
  165. color: '#000',
  166. fontSize: 14
  167. },
  168. listView: {
  169. marginTop: 16,
  170. minHeight: $vh(30),
  171. backgroundColor: colorLight
  172. },
  173. noResult: {
  174. color: '#999',
  175. fontSize: 14,
  176. padding: 20,
  177. lineHeight: $vh(20),
  178. textAlign: 'center',
  179. },
  180. itemView: {
  181. paddingLeft: 16,
  182. paddingRight: 16,
  183. alignItems: 'center',
  184. flexDirection: 'row'
  185. },
  186. itemContent: {
  187. flex: 1,
  188. marginLeft: 16,
  189. ...$padding(16, 4),
  190. alignItems: 'center',
  191. flexDirection: 'row'
  192. },
  193. divide: {
  194. borderTopWidth: 1,
  195. borderTopColor: '#eee',
  196. },
  197. iconType: {
  198. width: 28,
  199. height: 28
  200. },
  201. issueName: {
  202. color: textPrimary,
  203. fontSize: 12,
  204. paddingBottom: 2
  205. },
  206. issueDesc: {
  207. color: '#999',
  208. fontSize: 11
  209. },
  210. amountDuct: {
  211. color: '#FF2E00',
  212. fontSize: 14
  213. },
  214. amountText: {
  215. color: textPrimary,
  216. fontSize: 14
  217. },
  218. moreButton: {
  219. padding: 16,
  220. alignItems: 'center',
  221. marginBottom: 8
  222. }
  223. })