PointsHistory.js 4.8 KB

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