PointsHistory.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. * 积分历史列表页面
  3. * @邠心vbe on 2024/05/07
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, RefreshControl, FlatList, StyleSheet } from 'react-native';
  7. import { MyRefreshProps } from '../../components/ThemesConfig';
  8. import TextView from '../../components/TextView';
  9. import Dialog from '../../components/Dialog';
  10. import apiVoucher from '../../api/apiVoucher';
  11. import app from '../../../app.json';
  12. export default class PointsHistory extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. dataList: [],
  17. hasMore: true,
  18. refreshing: false
  19. };
  20. }
  21. componentDidMount() {
  22. Dialog.showProgressDialog();
  23. this.getHistoryList();
  24. }
  25. onRefresh() {
  26. this.setState({
  27. refreshing: true
  28. })
  29. this.getHistoryList();
  30. }
  31. getNextPage() {
  32. if (this.state.dataList.length > 0 && this.state.hasMore) {
  33. console.log("[Points History]", "getNextPage");
  34. const last = this.state.dataList[this.state.dataList.length-1]
  35. this.getHistoryList(last.pointsHistoryId);
  36. }
  37. }
  38. getHistoryList(lastPk="") {
  39. apiVoucher.getPointsHistory(lastPk).then(res => {
  40. if (res.data) {
  41. if (lastPk) {
  42. if (res.data.length > 0) {
  43. const list = this.state.dataList;
  44. this.setState({
  45. dataList: list.concat(res.data)
  46. });
  47. } else {
  48. this.setState({
  49. hasMore: false
  50. })
  51. }
  52. } else {
  53. this.setState({
  54. dataList: res.data,
  55. hasMore: true
  56. });
  57. }
  58. } else {
  59. this.setState({
  60. dataList: []
  61. });
  62. }
  63. }).catch(err => {
  64. toastShort(err)
  65. }).finally(() => {
  66. this.setState({
  67. refreshing: false
  68. });
  69. Dialog.dismissLoading();
  70. });
  71. }
  72. listItem = ({item, index, separators}) => {
  73. return (
  74. <View style={styles.itemView}>
  75. <View style={styles.itemContent}>
  76. <View style={ui.flex1}>
  77. <TextView style={styles.issueName}>{item.remarks}</TextView>
  78. <TextView style={styles.issueDesc}>{item.dateTime}</TextView>
  79. <TextView style={styles.issueDesc}>{(item.siteName ?? item.voucherName) + (item.chargeBoxId ? ", " + item.chargeBoxId : "")}</TextView>
  80. <TextView style={styles.issueDesc}>{"Transaction ID: " + item.refId}</TextView>
  81. </View>
  82. { item.action == "Increase"
  83. ? <TextView style={styles.amountText}>+ {item.points}</TextView>
  84. : <TextView style={styles.amountDuct}>- {item.points}</TextView>
  85. }
  86. </View>
  87. </View>
  88. )
  89. }
  90. divideView = (props) => {
  91. return (<View style={styles.divide}></View>)
  92. }
  93. bottomView = () => {
  94. if (!this.state.hasMore) {
  95. return (<Text style={styles.noMore}>{$t('wallet.noMore')}</Text>)
  96. } else {
  97. return null
  98. }
  99. }
  100. render() {
  101. return (
  102. <FlatList
  103. style={styles.listView}
  104. data={this.state.dataList}
  105. renderItem={this.listItem}
  106. ItemSeparatorComponent={this.divideView}
  107. ListFooterComponent={this.bottomView}
  108. keyExtractor={item => item.pointsHistoryId}
  109. onEndReached={() => this.getNextPage()}
  110. onEndReachedThreshold={0.3}
  111. refreshControl={
  112. <RefreshControl
  113. {...MyRefreshProps()}
  114. refreshing={this.state.refreshing}
  115. onRefresh={() => this.onRefresh()}
  116. />
  117. }
  118. ListEmptyComponent={<Text style={styles.noData}>{$t('points.noData')}</Text>}
  119. />
  120. );
  121. }
  122. }
  123. const styles = StyleSheet.create({
  124. listView: {
  125. flex: 1
  126. },
  127. itemView: {
  128. paddingLeft: 16,
  129. paddingRight: 16,
  130. alignItems: 'center',
  131. flexDirection: 'row'
  132. },
  133. itemContent: {
  134. flex: 1,
  135. //marginLeft: 8,
  136. ...$padding(16, 4),
  137. alignItems: 'flex-start',
  138. flexDirection: 'row'
  139. },
  140. divide: {
  141. marginLeft: 16,
  142. marginRight: 16,
  143. borderTopWidth: 1,
  144. borderTopColor: '#eee',
  145. },
  146. iconType: {
  147. width: 28,
  148. height: 28,
  149. textAlign: 'center',
  150. lineHeight: 27,
  151. borderWidth: 1,
  152. borderRadius: 30,
  153. borderColor: textPrimary
  154. },
  155. issueName: {
  156. color: textPrimary,
  157. fontSize: 14,
  158. paddingBottom: 2
  159. },
  160. issueDesc: {
  161. color: textSecondary,
  162. fontSize: 12
  163. },
  164. amountDuct: {
  165. color: '#FF2E00',
  166. fontSize: 14,
  167. paddingLeft: 8
  168. },
  169. amountText: {
  170. color: colorPrimary,
  171. fontSize: 14,
  172. paddingLeft: 8
  173. },
  174. noData: {
  175. color: textPlacehoder,
  176. fontSize: 12,
  177. padding: 20,
  178. textAlign: 'center'
  179. },
  180. noMore: {
  181. color: textPlacehoder,
  182. fontSize: 12,
  183. padding: 16,
  184. textAlign: 'center'
  185. }
  186. })