SummaryV2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /**
  2. * 新版充电结算页面
  3. * @邠心vbe on 2023/02/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, 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. export default class Summary extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. isActully: true,
  18. refreshing: false,
  19. summaryInfo: {
  20. top: {},
  21. station: {},
  22. connector: {},
  23. chargingFee: {},
  24. idleFee: {},
  25. reservationFee: {},
  26. payment: {}
  27. },
  28. chargingPk: ""
  29. };
  30. this.canBack = false;
  31. }
  32. componentDidMount() {
  33. const params = this.props.route.params;
  34. if (params.chargingPk) {
  35. Dialog.showProgressDialog();
  36. this.setState({
  37. chargingPk: params.chargingPk
  38. })
  39. if (params.action && params.action == "view") {
  40. this.setState({
  41. isActully: false
  42. });
  43. this.getSummaryData(params.chargingPk);
  44. } else {
  45. setTimeout(() => {
  46. this.getSummaryData(params.chargingPk);
  47. }, 3000);
  48. }
  49. }
  50. this.props.navigation.addListener('focus', e => {
  51. this.canBack = false;
  52. });
  53. this.props.navigation.addListener('beforeRemove', e => {
  54. if (this.state.isActully && !this.canBack) {
  55. this.toRating();
  56. e.preventDefault();
  57. }
  58. });
  59. }
  60. getSummaryData(chargingPk) {
  61. apiCharge.getChargeSummaryV2({
  62. chargingPk: chargingPk
  63. }).then(res => {
  64. Dialog.dismissLoading();
  65. if (res.data) {
  66. this.setState({
  67. refreshing: false,
  68. summaryInfo: res.data
  69. });
  70. }
  71. }).catch((err) => {
  72. Dialog.dismissLoading();
  73. toastShort(err);
  74. this.setState({
  75. refreshing: false
  76. });
  77. });
  78. }
  79. onRefresh() {
  80. if (this.state.chargingPk) {
  81. this.setState({
  82. refreshing: true
  83. });
  84. this.getSummaryData(this.state.chargingPk);
  85. }
  86. }
  87. toRating() {
  88. this.canBack = true;
  89. //goBack();
  90. //routeUtil.resetToHome(this.props);
  91. startPage(PageList.home);
  92. //startPage(PageList.rating, this.state.stationInfo);
  93. }
  94. getSummaryText(data) {
  95. if (this.state.summaryInfo?.paymentType == 'Fleet Credit') {
  96. return '-';
  97. } else {
  98. return currency + '' + (data ?? '0');
  99. }
  100. }
  101. render() {
  102. return (
  103. <ScrollView
  104. style={styles.container}
  105. refreshControl={
  106. <RefreshControl
  107. {...MyRefreshProps()}
  108. refreshing={this.state.refreshing}
  109. onRefresh={() => this.onRefresh()}
  110. />
  111. }>
  112. { utils.isNotEmpty(this.state.summaryInfo.top) &&
  113. <View style={styles.headerView}>
  114. <Octicons
  115. name="check-circle-fill"
  116. color={colorAccent}
  117. size={56}/>
  118. <Text style={styles.topTitle}>{$t('receipt.successful')}</Text>
  119. <Text style={styles.topDesc}>{$t('receipt.chargingSessionComplete')}</Text>
  120. { utils.isNotEmpty(this.state.summaryInfo.top.company) &&
  121. <View style={styles.formRow}>
  122. <Text style={styles.label}>{$t('sign.labelCompany')}:</Text>
  123. <Text style={styles.text}>{this.state.summaryInfo.top.company}</Text>
  124. </View>
  125. }
  126. { utils.isNotEmpty(this.state.summaryInfo.top.registrationNo) &&
  127. <View style={styles.formRow}>
  128. <Text style={styles.label}>{$t('receipt.labelRegistrationNo')}</Text>
  129. <Text style={styles.text}>{this.state.summaryInfo.top.registrationNo}</Text>
  130. </View>
  131. }
  132. <View style={styles.formRow}>
  133. <Text style={styles.label}>{$t('receipt.labelTransactionID')}</Text>
  134. <Text style={styles.text}>{this.state.summaryInfo.top.transactionId}</Text>
  135. </View>
  136. <View style={styles.formRow}>
  137. <Text style={styles.label}>{$t('receipt.labelReferenceID')}</Text>
  138. <Text style={styles.text}>{this.state.summaryInfo.top.referenceId}</Text>
  139. </View>
  140. <View style={styles.formRow}>
  141. <Text style={styles.label}>{$t('receipt.labelDateTime')}</Text>
  142. <Text style={styles.text}>{this.state.summaryInfo.top.dateTime}</Text>
  143. </View>
  144. </View>
  145. }
  146. {/* <View style={styles.sections}>
  147. <View style={styles.formRow}>
  148. <Text style={styles.label}>{$t('wallet.labelTransactionId')}</Text>
  149. <Text style={styles.text}>{this.state.summaryInfo.transactionPk}</Text>
  150. </View>
  151. <View style={styles.formRow}>
  152. <Text style={styles.label}>{$t('wallet.labelReferenceId')}</Text>
  153. <Text style={styles.text}>{this.state.summaryInfo.chargingPk}</Text>
  154. </View>
  155. <View style={styles.formRow}>
  156. <Text style={styles.label}>{$t('wallet.labelDateTime')}</Text>
  157. <Text style={styles.text}>{this.state.summaryInfo.dateTime}</Text>
  158. </View>
  159. </View> */}
  160. { utils.isNotEmpty(this.state.summaryInfo.station) &&
  161. <View style={styles.sections}>
  162. <Text style={styles.formTitle}>{$t('wallet.labelYourStation')}</Text>
  163. <View style={styles.formRow}>
  164. <Text style={styles.label}>{$t('wallet.labelStationId')}</Text>
  165. <Text style={styles.text}>{this.state.summaryInfo.station.stationId}</Text>
  166. </View>
  167. <View style={styles.formRow}>
  168. <Text style={styles.label}>{$t('receipt.labelSiteName')}</Text>
  169. <Text style={styles.text}>{this.state.summaryInfo.station.siteName ?? "-"}</Text>
  170. </View>
  171. </View>
  172. }
  173. { utils.isNotEmpty(this.state.summaryInfo.connector) &&
  174. <View style={styles.sections}>
  175. <Text style={styles.formTitle}>{$t('wallet.labelYourConnector')}</Text>
  176. <View style={styles.formRow}>
  177. <Text style={styles.label}>{$t('charging.labelType')}</Text>
  178. <Text style={styles.text}>{this.state.summaryInfo.connector.type}</Text>
  179. </View>
  180. <View style={styles.formRow}>
  181. <Text style={styles.label}>{$t('charging.labelPower')}</Text>
  182. <Text style={styles.text}>{this.state.summaryInfo.connector.power}</Text>
  183. </View>
  184. <View style={styles.formRow}>
  185. <Text style={styles.label}>{$t('charging.labelRates')}</Text>
  186. <Text style={styles.text}>{this.state.summaryInfo.connector.rates}</Text>
  187. </View>
  188. </View>
  189. }
  190. { utils.isNotEmpty(this.state.summaryInfo.chargingFee) &&
  191. <View style={styles.sections}>
  192. <Text style={styles.formTitle}>{$t('receipt.breakdownChargingFees')}</Text>
  193. <View style={styles.formRow}>
  194. <Text style={styles.label}>{$t('wallet.labelChargeTime')}</Text>
  195. <Text style={styles.text}>{this.state.summaryInfo.chargingFee.chargeTime ?? "-"}</Text>
  196. </View>
  197. <View style={styles.formRow}>
  198. <Text style={styles.label}>{$t('wallet.labelChargeDelivered')}</Text>
  199. <Text style={styles.text}>{this.state.summaryInfo.chargingFee.chargeDelivered ?? 0}</Text>
  200. </View>
  201. <View style={styles.formRow}>
  202. <Text style={styles.label}>{$t('receipt.labelChargTransSubtotal')}</Text>
  203. <Text style={styles.text}>{this.state.summaryInfo.chargingFee.transactionSubtotal}</Text>
  204. </View>
  205. </View>
  206. }
  207. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  208. <View style={styles.sections}>
  209. <Text style={styles.formTitle}>{$t('receipt.breakdownIdlesFees')}</Text>
  210. <View style={styles.formRow}>
  211. <Text style={styles.label}>{$t('receipt.labelIdleStartTime')}</Text>
  212. <Text style={styles.text}>{this.state.summaryInfo.idleFee.startTime}</Text>
  213. </View>
  214. <View style={styles.formRow}>
  215. <Text style={styles.label}>{$t('receipt.labelIdleDuration')}</Text>
  216. <Text style={styles.text}>{this.state.summaryInfo.idleFee.duration}</Text>
  217. </View>
  218. <View style={styles.formRow}>
  219. <Text style={styles.label}>{$t('receipt.labelIdleFeeSubtotal')}</Text>
  220. <Text style={styles.text}>{this.state.summaryInfo.idleFee.subtotal}</Text>
  221. </View>
  222. </View>
  223. }
  224. { utils.isNotEmpty(this.state.summaryInfo.reservationFee) &&
  225. <View style={styles.sections}>
  226. <Text style={styles.formTitle}>{$t('receipt.breakdownReservationFees')}</Text>
  227. <View style={styles.formRow}>
  228. <Text style={styles.label}>{$t('receipt.labelTimeReservation')}</Text>
  229. <Text style={styles.text}>{this.state.summaryInfo.reservationFee.reservationTime}</Text>
  230. </View>
  231. <View style={styles.formRow}>
  232. <Text style={styles.label}>{$t('receipt.labelDurationReservation')}</Text>
  233. <Text style={styles.text}>{this.state.summaryInfo.reservationFee.reservationDuration}</Text>
  234. </View>
  235. <View style={styles.formRow}>
  236. <Text style={styles.label}>{$t('receipt.labelReservationFeeSubtotal')}</Text>
  237. <Text style={styles.text}>{this.state.summaryInfo.reservationFee.reservationFeeSubtotal}</Text>
  238. </View>
  239. </View>
  240. }
  241. { utils.isNotEmpty(this.state.summaryInfo.payment) &&
  242. <View style={styles.sections}>
  243. <Text style={styles.formTitle}>{$t('receipt.breakdownPayment')}</Text>
  244. <View style={styles.formRow}>
  245. <Text style={styles.label}>{$t('wallet.labelPaymentMadeBy')}</Text>
  246. <Text style={styles.text}>{this.state.summaryInfo.payment.paymentMadeBy ?? "-"}</Text>
  247. </View>
  248. { utils.isNotEmpty(this.state.summaryInfo.payment.transactionSubtotal) &&
  249. <View style={styles.formRow}>
  250. <Text style={styles.label}>{$t('receipt.labelChargTransSubtotal')}</Text>
  251. <Text style={styles.text}>{this.state.summaryInfo.payment.transactionSubtotal}</Text>
  252. </View>
  253. }
  254. { utils.isNotEmpty(this.state.summaryInfo.payment.idleFeeSubtotal) &&
  255. <View style={styles.formRow}>
  256. <Text style={styles.label}>{$t('receipt.labelIdleFeeSubtotal')}</Text>
  257. <Text style={styles.text}>{this.state.summaryInfo.payment.idleFeeSubtotal}</Text>
  258. </View>
  259. }
  260. { utils.isNotEmpty(this.state.summaryInfo.payment.reservationFeeSubtotal) &&
  261. <View style={styles.formRow}>
  262. <Text style={styles.label}>{$t('receipt.labelReservationFeeSubtotal')}</Text>
  263. <Text style={styles.text}>{this.state.summaryInfo.payment.reservationFeeSubtotal}</Text>
  264. </View>
  265. }
  266. <View style={styles.formRow}>
  267. <Text style={styles.label}>{$t('receipt.labelFinalPaymentAmount')}</Text>
  268. <Text style={styles.text}>{this.state.summaryInfo.payment.finalPayment ?? "-"}</Text>
  269. </View>
  270. {/* <View style={styles.formRow}>
  271. <Text style={styles.label}>{$t('wallet.labelChargeRates')}</Text>
  272. <Text style={styles.text}>{currency}{this.state.summaryInfo.chargeRates ?? '0.0'}</Text>
  273. </View> */}
  274. <View style={styles.formRow}>
  275. <Text style={styles.label}>{$t('wallet.labelExchangeRate')}</Text>
  276. <Text style={styles.text}>{this.state.summaryInfo.payment.exchangeRate ?? "-"}</Text>
  277. </View>
  278. {/* <View style={styles.formRow}>
  279. <Text style={styles.label}>{$t('wallet.labelPreviousBalance')}</Text>
  280. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.previousBalance)}</Text>
  281. </View> */}
  282. <View style={styles.formRow}>
  283. <Text style={styles.label}>{$t('wallet.labelResultingBalance')}</Text>
  284. <Text style={styles.text}>{this.state.summaryInfo.payment.resultingBalance ?? "-"}</Text>
  285. </View>
  286. </View>
  287. }
  288. { this.state.isActully &&
  289. <View style={styles.bottomButton}>
  290. <Text
  291. style={styles.feedback}
  292. onPress={() => startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')}</Text>
  293. {/* <Text style={styles.tipText}>{$t('wallet.tipsReceipt')}</Text> */}
  294. <Button
  295. text={$t('home.done')}
  296. elevation={1.5}
  297. onClick={() => this.toRating()}/>
  298. </View>
  299. }
  300. </ScrollView>
  301. );
  302. }
  303. }
  304. const styles = StyleSheet.create({
  305. container: {
  306. flex: 1,
  307. paddingLeft: 16,
  308. paddingRight: 16,
  309. backgroundColor: colorLight
  310. },
  311. headerView: {
  312. alignItems: 'center',
  313. paddingTop: 16,
  314. paddingBottom: 24
  315. },
  316. topTitle: {
  317. color: textPrimary,
  318. fontSize: 16,
  319. marginTop: 8,
  320. paddingLeft: 8,
  321. fontWeight: 'bold'
  322. },
  323. topDesc: {
  324. color: textPrimary,
  325. fontSize: 14,
  326. marginBottom: 32
  327. },
  328. sections: {
  329. borderRadius: 10,
  330. marginBottom: 12,
  331. backgroundColor: colorLight
  332. },
  333. sections2: {
  334. paddingTop: 0,
  335. paddingLeft: 0,
  336. paddingRight: 0,
  337. paddingBottom: 8,
  338. borderRadius: 10,
  339. marginBottom: 8,
  340. backgroundColor: colorLight
  341. },
  342. formTitle: {
  343. color: '#000',
  344. fontSize: 14,
  345. marginTop: -4,
  346. marginBottom: 6,
  347. paddingBottom: 6,
  348. fontWeight: 'bold',
  349. borderBottomWidth: 1,
  350. borderBottomColor: textPrimary
  351. },
  352. formRow: {
  353. paddingTop: 3,
  354. paddingBottom: 3,
  355. alignItems: 'center',
  356. flexDirection: 'row'
  357. },
  358. label: {
  359. flex: 1,
  360. color: textPrimary,
  361. fontSize: 13,
  362. },
  363. text: {
  364. color: textPrimary,
  365. fontSize: 12,
  366. fontWeight: 'bold'
  367. },
  368. stationInfoView: {
  369. padding: 12,
  370. marginBottom: 0,
  371. alignItems: 'center',
  372. flexDirection: 'row',
  373. justifyContent: 'space-between'
  374. },
  375. stationInfoText: {
  376. color: '#999',
  377. fontSize: 11
  378. },
  379. connectorView: {
  380. alignItems: 'center',
  381. flexDirection: 'row'
  382. },
  383. typeIcon: {
  384. width: 36,
  385. height: 36
  386. },
  387. feedback: {
  388. color: '#12A5F9',
  389. fontSize: 14,
  390. textAlign: 'center',
  391. marginBottom: 16,
  392. ...ui.underline
  393. },
  394. bottomButton: {
  395. marginTop: 32,
  396. marginBottom: 16
  397. },
  398. tipText: {
  399. color: textPrimary,
  400. fontSize: 12,
  401. textAlign: 'center',
  402. marginBottom: 8
  403. }
  404. });