Summary.js 10 KB

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