Summary.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /**
  2. * 新版充电结算页面
  3. * @邠心vbe on 2023/02/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, ScrollView, RefreshControl } from 'react-native';
  7. import apiCharge from '../../api/apiCharge';
  8. import Button from '../../components/Button';
  9. import Dialog from '../../components/Dialog';
  10. import { MyRefreshProps } from '../../components/ThemesConfig';
  11. import utils from '../../utils/utils';
  12. import { PageList } from '../Router';
  13. import { ChargeStyle, TypeImage } from './Charging';
  14. export default class Summary extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. isActully: true,
  19. refreshing: false,
  20. summaryInfo: {},
  21. stationInfo: {}
  22. };
  23. this.canBack = false;
  24. }
  25. componentDidMount() {
  26. const params = this.props.route.params;
  27. if (params.chargingPk) {
  28. Dialog.showProgressDialog();
  29. if (params.name && params.address) {
  30. this.setState({
  31. chargingPk: params.chargingPk,
  32. stationInfo: {
  33. id: params.id,
  34. name: params.name,
  35. address: params.address
  36. }
  37. });
  38. setTimeout(() => {
  39. this.getSummaryData(params.chargingPk);
  40. }, 5000);
  41. } else if (params.action && params.action == "view") {
  42. this.setState({
  43. isActully: false,
  44. chargingPk: params.chargingPk
  45. });
  46. this.getSummaryData(params.chargingPk);
  47. }
  48. }
  49. this.props.navigation.addListener('focus', e => {
  50. this.canBack = false;
  51. });
  52. this.props.navigation.addListener('beforeRemove', e => {
  53. if (this.state.isActully && !this.canBack) {
  54. this.toRating();
  55. e.preventDefault();
  56. }
  57. });
  58. }
  59. getSummaryData(chargingPk) {
  60. apiCharge.getChargeSummary({
  61. chargingPk: chargingPk
  62. }).then(res => {
  63. Dialog.dismissLoading();
  64. if (res.data) {
  65. this.setState({
  66. refreshing: false,
  67. summaryInfo: res.data
  68. });
  69. }
  70. }).catch((err) => {
  71. Dialog.dismissLoading();
  72. toastShort(err);
  73. this.setState({
  74. refreshing: false
  75. });
  76. });
  77. }
  78. onRefresh() {
  79. if (this.state.chargingPk) {
  80. this.setState({
  81. refreshing: true
  82. });
  83. this.getSummaryData(this.state.chargingPk);
  84. }
  85. }
  86. toRating() {
  87. this.canBack = true;
  88. //goBack();
  89. startPage(PageList.home)
  90. //startPage(PageList.rating, this.state.stationInfo);
  91. }
  92. getSummaryText(data) {
  93. if (this.state.summaryInfo?.paymentType == 'Fleet Credit') {
  94. return '-';
  95. } else {
  96. return currency + '' + (data ?? '0');
  97. }
  98. }
  99. render() {
  100. return (
  101. <ScrollView
  102. style={styles.container}
  103. refreshControl={
  104. <RefreshControl
  105. {...MyRefreshProps()}
  106. refreshing={this.state.refreshing}
  107. onRefresh={() => this.onRefresh()}
  108. />
  109. }>
  110. <View style={{height:16}}></View>
  111. <View style={styles.sections}>
  112. <View style={styles.formRow}>
  113. <Text style={styles.label}>{$t('wallet.labelTransactionId')}</Text>
  114. <Text style={styles.text}>{this.state.summaryInfo.transactionPk}</Text>
  115. </View>
  116. <View style={styles.formRow}>
  117. <Text style={styles.label}>{$t('wallet.labelReferenceId')}</Text>
  118. <Text style={styles.text}>{this.state.summaryInfo.chargingPk}</Text>
  119. </View>
  120. <View style={styles.formRow}>
  121. <Text style={styles.label}>{$t('wallet.labelDateTime')}</Text>
  122. <Text style={styles.text}>{this.state.summaryInfo.dateTime}</Text>
  123. </View>
  124. </View>
  125. <View style={styles.sections}>
  126. <Text style={styles.formTitle}>{$t('wallet.labelYourStation')}</Text>
  127. <View style={styles.formRow}>
  128. <Text style={styles.label}>{$t('wallet.labelStationId') + this.state.summaryInfo.chargeBoxPk}</Text>
  129. </View>
  130. <Text style={styles.stationInfoText}>{this.state.summaryInfo?.boxAddress}</Text>
  131. </View>
  132. <View style={styles.sections2}>
  133. <Text style={styles.formTitle}>{$t('wallet.labelYourConnector')}</Text>
  134. <View style={styles.stationInfoView}>
  135. <Image
  136. style={ChargeStyle.infoIcon}
  137. source={this.state.summaryInfo.connectorType?.indexOf('AC') >= 0 ? TypeImage.AC : TypeImage.DC}/>
  138. <View style={ChargeStyle.infoGroup}>
  139. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorType}</Text>
  140. <Text style={ChargeStyle.infoTitle}>{$t('charging.labelType')}</Text>
  141. </View>
  142. <View style={ChargeStyle.infoGroup}>
  143. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorWattage}</Text>
  144. <Text style={ChargeStyle.infoTitle}>{$t('charging.labelPower')}</Text>
  145. </View>
  146. <View style={ChargeStyle.infoGroup}>
  147. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorRate}</Text>
  148. <Text style={ChargeStyle.infoTitle}>{$t('charging.labelRate')}</Text>
  149. </View>
  150. </View>
  151. </View>
  152. <View style={styles.sections}>
  153. <Text style={styles.formTitle}>{$t('wallet.labelBreakdown')}</Text>
  154. <View style={styles.formRow}>
  155. <Text style={styles.label}>{$t('wallet.labelReservationFee')}</Text>
  156. <Text style={styles.text}>{currency}{this.state.summaryInfo.reservationFee ?? 0}</Text>
  157. </View>
  158. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  159. <View style={styles.formRow}>
  160. <Text style={styles.label}>{$t('wallet.labelIdleFee')}</Text>
  161. <Text style={styles.text}>{currency}{this.state.summaryInfo.idleFee}</Text>
  162. </View>
  163. }
  164. <View style={styles.formRow}>
  165. <Text style={styles.label}>{$t('wallet.labelChargeTime')}</Text>
  166. <Text style={styles.text}>{utils.hour2HHmm(this.state.summaryInfo.chargeTime)}</Text>
  167. </View>
  168. <View style={styles.formRow}>
  169. <Text style={styles.label}>{$t('wallet.labelChargeDelivered')}</Text>
  170. <Text style={styles.text}>{this.state.summaryInfo.chargeDelivered ?? 0}kWh</Text>
  171. </View>
  172. <View style={styles.formRow}>
  173. <Text style={styles.label}>{$t('wallet.labelChargeRates')}</Text>
  174. <Text style={styles.text}>{currency}{this.state.summaryInfo.chargeRates ?? '0.0'}</Text>
  175. </View>
  176. </View>
  177. <View style={styles.sections}>
  178. <Text style={styles.formTitle}>{$t('wallet.labelSubtotal')}</Text>
  179. <View style={styles.formRow}>
  180. <Text style={styles.label}>{$t('wallet.labelPaymentMadeBy')}</Text>
  181. <Text style={styles.text}>{this.state.summaryInfo.paymentType}</Text>
  182. </View>
  183. <View style={styles.formRow}>
  184. <Text style={styles.label}>{$t('wallet.labelPreviousBalance')}</Text>
  185. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.previousBalance)}</Text>
  186. </View>
  187. <View style={styles.formRow}>
  188. <Text style={styles.label}>{$t('wallet.labelPayment')}</Text>
  189. <Text style={styles.text}>{currency}{this.state.summaryInfo.payment ?? '0.0'}</Text>
  190. </View>
  191. <View style={styles.formRow}>
  192. <Text style={styles.label}>{$t('wallet.labelExchangeRate')}</Text>
  193. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.exchangeRate)}</Text>
  194. </View>
  195. <View style={styles.formRow}>
  196. <Text style={styles.label}>{$t('wallet.labelFinalPayment')}</Text>
  197. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.finalPayment)}</Text>
  198. </View>
  199. <View style={styles.formRow}>
  200. <Text style={styles.label}>{$t('wallet.labelResultingBalance')}</Text>
  201. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.resultingBalance)}</Text>
  202. </View>
  203. </View>
  204. { this.state.isActully &&
  205. <View style={styles.bottomButton}>
  206. <Text
  207. style={styles.feedback}
  208. onPress={() => startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')}</Text>
  209. <Text style={styles.tipText}>{$t('wallet.tipsReceipt')}</Text>
  210. <Button
  211. text={$t('home.done')}
  212. elevation={1.5}
  213. onClick={() => this.toRating()}/>
  214. </View>
  215. }
  216. </ScrollView>
  217. );
  218. }
  219. }
  220. const styles = StyleSheet.create({
  221. container: {
  222. flex: 1,
  223. paddingLeft: 16,
  224. paddingRight: 16,
  225. backgroundColor: colorLight
  226. },
  227. sections: {
  228. borderRadius: 10,
  229. marginBottom: 16,
  230. backgroundColor: colorLight
  231. },
  232. sections2: {
  233. paddingTop: 0,
  234. paddingLeft: 0,
  235. paddingRight: 0,
  236. paddingBottom: 8,
  237. borderRadius: 10,
  238. marginBottom: 8,
  239. backgroundColor: colorLight
  240. },
  241. formTitle: {
  242. color: '#000',
  243. fontSize: 14,
  244. marginTop: -4,
  245. marginBottom: 6,
  246. paddingBottom: 6,
  247. fontWeight: 'bold',
  248. borderBottomWidth: 1,
  249. borderBottomColor: '#eee'
  250. },
  251. formRow: {
  252. paddingTop: 3,
  253. paddingBottom: 3,
  254. alignItems: 'center',
  255. flexDirection: 'row'
  256. },
  257. label: {
  258. flex: 1,
  259. color: textPrimary,
  260. fontSize: 13,
  261. },
  262. text: {
  263. color: textPrimary,
  264. fontSize: 13,
  265. },
  266. stationInfoView: {
  267. padding: 12,
  268. marginBottom: 0,
  269. alignItems: 'center',
  270. flexDirection: 'row',
  271. justifyContent: 'space-between'
  272. },
  273. stationInfoText: {
  274. color: '#999',
  275. fontSize: 11
  276. },
  277. connectorView: {
  278. alignItems: 'center',
  279. flexDirection: 'row'
  280. },
  281. typeIcon: {
  282. width: 36,
  283. height: 36
  284. },
  285. feedback: {
  286. color: '#12A5F9',
  287. fontSize: 14,
  288. textAlign: 'center',
  289. marginBottom: 16,
  290. ...ui.underline
  291. },
  292. bottomButton: {
  293. marginTop: 32,
  294. marginBottom: 16
  295. },
  296. tipText: {
  297. color: textPrimary,
  298. fontSize: 12,
  299. textAlign: 'center',
  300. marginBottom: 8
  301. }
  302. });