HistoryList.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. * 交易历史页面
  3. * @邠心vbe on 2024/03/29
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, RefreshControl, FlatList, StyleSheet, Pressable, Image } from 'react-native';
  7. import { MyRefreshProps } from '../../components/ThemesConfig';
  8. import apiWallet from '../../api/apiWallet';
  9. import TextView from '../../components/TextView';
  10. import Dialog from '../../components/Dialog';
  11. import { PageList } from '../Router';
  12. const IconCharge = require('../../images/wallet/ic-type-charge.png');
  13. const IconPayment = require('../../images/wallet/ic-type-payment.png');
  14. export default class HistoryList extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. dataList: [],
  19. hasMore: true,
  20. refreshing: false
  21. };
  22. }
  23. componentDidMount() {
  24. Dialog.showProgressDialog();
  25. this.getHistoryList();
  26. }
  27. onRefresh() {
  28. this.setState({
  29. refreshing: true
  30. })
  31. this.getHistoryList();
  32. }
  33. getNextPage() {
  34. if (this.state.dataList.length > 0 && this.state.hasMore) {
  35. console.log("[Wallet History]", "getNextPage");
  36. const last = this.state.dataList[this.state.dataList.length-1]
  37. this.getHistoryList(last.creditRecordPk);
  38. }
  39. }
  40. getHistoryList(lastPk="") {
  41. apiWallet.getTransactionListV2({latestPk: lastPk}).then(res => {
  42. if (res.data) {
  43. if (lastPk) {
  44. if (res.data.length > 0) {
  45. const list = this.state.dataList;
  46. this.setState({
  47. dataList: list.concat(res.data)
  48. });
  49. } else {
  50. this.setState({
  51. hasMore: false
  52. })
  53. }
  54. } else {
  55. this.setState({
  56. dataList: res.data,
  57. hasMore: true
  58. });
  59. }
  60. } else {
  61. this.setState({
  62. dataList: []
  63. });
  64. }
  65. }).catch(err => {
  66. toastShort(err)
  67. }).finally(() => {
  68. this.setState({
  69. refreshing: false
  70. });
  71. Dialog.dismissLoading();
  72. });
  73. }
  74. toSummary(item) {
  75. if (item.refPk) {
  76. startPage(PageList.summary, { action: 'view', chargingPk: item.refPk });
  77. }
  78. }
  79. getTransTitle(item) {
  80. if (item.amountSymbol == 'M') {
  81. return "Charging Session";
  82. } else {
  83. return "Purchase Credits";
  84. }
  85. }
  86. listItem = ({item, index, separators}) => {
  87. return (
  88. <Pressable
  89. android_ripple={ripple}
  90. style={styles.itemView}
  91. onPress={() => {
  92. this.toSummary(item)
  93. }}>
  94. {/* <Image
  95. style={styles.iconType}
  96. resizeMode="contain"
  97. source={(item.amountSymbol == 'P' || item.remarks) ? IconPayment : IconCharge}/> */}
  98. <View style={styles.itemContent}>
  99. <View style={ui.flex1}>
  100. <TextView style={styles.issueName}>{this.getTransTitle(item)}</TextView>
  101. <TextView style={styles.issueDesc}>{item.createTime}</TextView>
  102. { item.amountSymbol == 'M'
  103. ? <TextView style={styles.issueDesc}>{item.siteName || "Charging"}</TextView>
  104. : <TextView style={styles.issueDesc}>{$t('wallet.topUp') + ", " + item.amount}</TextView>
  105. }
  106. <TextView style={styles.issueDesc}>{$t('wallet.labelTransactionId') + item.creditRecordPk}</TextView>
  107. </View>
  108. { item.amountSymbol == 'M'
  109. ? <TextView style={styles.amountDuct}>- {item.amount}</TextView>
  110. : <TextView style={styles.amountText}>+ {item.amount}</TextView>
  111. }
  112. </View>
  113. </Pressable>
  114. )
  115. }
  116. divideView = (props) => {
  117. return (<View style={styles.divide}></View>)
  118. }
  119. bottomView = () => {
  120. if (!this.state.hasMore) {
  121. return (<Text style={styles.noMore}>{$t('wallet.noMore')}</Text>)
  122. } else {
  123. return null
  124. }
  125. }
  126. render() {
  127. return (
  128. <FlatList
  129. style={styles.listView}
  130. data={this.state.dataList}
  131. renderItem={this.listItem}
  132. ItemSeparatorComponent={this.divideView}
  133. ListFooterComponent={this.bottomView}
  134. keyExtractor={item => item.creditRecordPk}
  135. onEndReached={() => this.getNextPage()}
  136. onEndReachedThreshold={0.3}
  137. refreshControl={
  138. <RefreshControl
  139. {...MyRefreshProps()}
  140. refreshing={this.state.refreshing}
  141. onRefresh={() => this.onRefresh()}
  142. />
  143. }
  144. ListEmptyComponent={<Text style={styles.noData}>{$t('wallet.noHistoryData')}</Text>}
  145. />
  146. );
  147. }
  148. }
  149. const styles = StyleSheet.create({
  150. listView: {
  151. flex: 1
  152. },
  153. itemView: {
  154. paddingLeft: 16,
  155. paddingRight: 16,
  156. alignItems: 'center',
  157. flexDirection: 'row'
  158. },
  159. itemContent: {
  160. flex: 1,
  161. //marginLeft: 16,
  162. ...$padding(16, 4),
  163. alignItems: 'flex-start',
  164. flexDirection: 'row'
  165. },
  166. divide: {
  167. marginLeft: 16,
  168. marginRight: 16,
  169. borderTopWidth: 1,
  170. borderTopColor: '#eee',
  171. },
  172. iconType: {
  173. width: 28,
  174. height: 28
  175. },
  176. issueName: {
  177. color: textPrimary,
  178. fontSize: 14,
  179. paddingBottom: 2
  180. },
  181. issueDesc: {
  182. color: textSecondary,
  183. fontSize: 12
  184. },
  185. amountDuct: {
  186. color: '#FF2E00',
  187. fontSize: 14,
  188. paddingLeft: 8
  189. },
  190. amountText: {
  191. color: colorPrimary,
  192. fontSize: 14,
  193. paddingLeft: 8
  194. },
  195. noData: {
  196. color: textPlacehoder,
  197. fontSize: 14,
  198. padding: 20,
  199. textAlign: 'center'
  200. },
  201. noMore: {
  202. color: textPlacehoder,
  203. fontSize: 14,
  204. padding: 16,
  205. textAlign: 'center'
  206. }
  207. })