History.js 6.3 KB

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