SummaryV2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. import app from '../../../app.json';
  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. top: {},
  22. station: {},
  23. connector: {},
  24. chargingFee: {},
  25. idleFee: {},
  26. reservationFee: {},
  27. payment: {}
  28. },
  29. chargingPk: ""
  30. };
  31. this.canBack = false;
  32. }
  33. componentDidMount() {
  34. const params = this.props.route.params;
  35. if (params.chargingPk) {
  36. Dialog.showProgressDialog();
  37. this.setState({
  38. chargingPk: params.chargingPk
  39. })
  40. if (params.action && params.action == "view") {
  41. this.setState({
  42. isActully: false
  43. });
  44. this.getSummaryData(params.chargingPk);
  45. } else {
  46. setTimeout(() => {
  47. this.getSummaryData(params.chargingPk);
  48. }, 3000);
  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.getChargeSummaryV2({
  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. getTaxTitle(title="") {
  103. if (this.state.summaryInfo?.taxRate) {
  104. return title.replace("$s", this.state.summaryInfo.taxRate)
  105. } else {
  106. return title;
  107. }
  108. }
  109. render() {
  110. return (
  111. <ScrollView
  112. style={styles.container}
  113. refreshControl={
  114. <RefreshControl
  115. {...MyRefreshProps()}
  116. refreshing={this.state.refreshing}
  117. onRefresh={() => this.onRefresh()}
  118. />
  119. }>
  120. { utils.isNotEmpty(this.state.summaryInfo.top) &&
  121. <View style={styles.headerView}>
  122. { this.state.isActully && <>
  123. <Octicons
  124. name="check-circle-fill"
  125. color={colorAccent}
  126. size={56}/>
  127. <Text style={styles.topTitle}>{$t('receipt.successful')}</Text>
  128. <Text style={styles.topDesc}>{$t('receipt.chargingSessionComplete')}</Text>
  129. </>}
  130. { utils.isNotEmpty(this.state.summaryInfo.top.company) &&
  131. <View style={styles.formRow}>
  132. <Text style={styles.label}>{$t('sign.labelCompany')}:</Text>
  133. <Text style={styles.text}>{this.state.summaryInfo.top.company}</Text>
  134. </View>
  135. }
  136. { utils.isNotEmpty(this.state.summaryInfo.top.registrationNo) &&
  137. <View style={styles.formRow}>
  138. <Text style={styles.label}>{$t('receipt.labelRegistrationNo')}</Text>
  139. <Text style={styles.text}>{this.state.summaryInfo.top.registrationNo}</Text>
  140. </View>
  141. }
  142. <View style={styles.formRow}>
  143. <Text style={styles.label}>{$t('receipt.labelTransactionID')}</Text>
  144. <Text style={styles.text}>{this.state.summaryInfo.top.transactionId}</Text>
  145. </View>
  146. <View style={styles.formRow}>
  147. <Text style={styles.label}>{$t('receipt.labelReferenceID')}</Text>
  148. <Text style={styles.text}>{this.state.summaryInfo.top.referenceId}</Text>
  149. </View>
  150. <View style={styles.formRow}>
  151. <Text style={styles.label}>{$t('receipt.labelDateTime')}</Text>
  152. <Text style={styles.text}>{this.state.summaryInfo.top.dateTime}</Text>
  153. </View>
  154. </View>
  155. }
  156. {/* <View style={styles.sections}>
  157. <View style={styles.formRow}>
  158. <Text style={styles.label}>{$t('wallet.labelTransactionId')}</Text>
  159. <Text style={styles.text}>{this.state.summaryInfo.transactionPk}</Text>
  160. </View>
  161. <View style={styles.formRow}>
  162. <Text style={styles.label}>{$t('wallet.labelReferenceId')}</Text>
  163. <Text style={styles.text}>{this.state.summaryInfo.chargingPk}</Text>
  164. </View>
  165. <View style={styles.formRow}>
  166. <Text style={styles.label}>{$t('wallet.labelDateTime')}</Text>
  167. <Text style={styles.text}>{this.state.summaryInfo.dateTime}</Text>
  168. </View>
  169. </View> */}
  170. { utils.isNotEmpty(this.state.summaryInfo.station) &&
  171. <View style={styles.sections}>
  172. <Text style={styles.formTitle}>{$t('wallet.labelYourStation')}</Text>
  173. <View style={styles.formRow}>
  174. <Text style={styles.label}>{$t('wallet.labelStationId')}</Text>
  175. <Text style={styles.text}>{this.state.summaryInfo.station.stationId}</Text>
  176. </View>
  177. <View style={styles.formRow}>
  178. <Text style={styles.label}>{$t('receipt.labelSiteName')}</Text>
  179. <Text style={styles.text}>{this.state.summaryInfo.station.siteName ?? "-"}</Text>
  180. </View>
  181. </View>
  182. }
  183. { utils.isNotEmpty(this.state.summaryInfo.connector) &&
  184. <View style={styles.sections}>
  185. <Text style={styles.formTitle}>{$t('wallet.labelYourConnector')}</Text>
  186. <View style={styles.formRow}>
  187. <Text style={styles.label}>{$t('charging.labelType')}:</Text>
  188. <Text style={styles.text}>{this.state.summaryInfo.connector.type}</Text>
  189. </View>
  190. <View style={styles.formRow}>
  191. <Text style={styles.label}>{$t('charging.labelPower')}:</Text>
  192. <Text style={styles.text}>{this.state.summaryInfo.connector.power}</Text>
  193. </View>
  194. <View style={styles.formRow}>
  195. <Text style={styles.label}>{$t('charging.labelRates')}:</Text>
  196. <Text style={styles.text}>{this.state.summaryInfo.connector.rates}</Text>
  197. </View>
  198. </View>
  199. }
  200. { utils.isNotEmpty(this.state.summaryInfo.chargingFee) &&
  201. <View style={styles.sections}>
  202. <Text style={styles.formTitle}>{$t('receipt.breakdownChargingFees')}</Text>
  203. <View style={styles.formRow}>
  204. <Text style={styles.label}>{$t('wallet.labelChargeTime')}</Text>
  205. <Text style={styles.text}>{this.state.summaryInfo.chargingFee.chargeTime ?? "-"}</Text>
  206. </View>
  207. <View style={styles.formRow}>
  208. <Text style={styles.label}>{$t('wallet.labelChargeDelivered')}</Text>
  209. <Text style={styles.text}>{this.state.summaryInfo.chargingFee.chargeDelivered ?? 0}</Text>
  210. </View>
  211. <View style={styles.formRow}>
  212. <Text style={styles.label}>{this.getTaxTitle($t('receipt.labelChargTransSubtotal2'))}</Text>
  213. <Text style={styles.text}>{this.state.summaryInfo.chargingFee.transactionSubtotal}</Text>
  214. </View>
  215. </View>
  216. }
  217. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  218. <View style={styles.sections}>
  219. <Text style={styles.formTitle}>{$t('receipt.breakdownIdlesFees')}</Text>
  220. <View style={styles.formRow}>
  221. <Text style={styles.label}>{$t('receipt.labelIdleStartTime')}</Text>
  222. <Text style={styles.text}>{this.state.summaryInfo.idleFee.startTime}</Text>
  223. </View>
  224. <View style={styles.formRow}>
  225. <Text style={styles.label}>{$t('receipt.labelIdleDuration')}</Text>
  226. <Text style={styles.text}>{this.state.summaryInfo.idleFee.duration}</Text>
  227. </View>
  228. <View style={styles.formRow}>
  229. <Text style={styles.label}>{this.getTaxTitle($t('receipt.labelIdleFeeSubtotal2'))}</Text>
  230. <Text style={styles.text}>{this.state.summaryInfo.idleFee.subtotal}</Text>
  231. </View>
  232. </View>
  233. }
  234. { utils.isNotEmpty(this.state.summaryInfo.reservationFee) &&
  235. <View style={styles.sections}>
  236. <Text style={styles.formTitle}>{$t('receipt.breakdownReservationFees')}</Text>
  237. <View style={styles.formRow}>
  238. <Text style={styles.label}>{$t('receipt.labelTimeReservation')}</Text>
  239. <Text style={styles.text}>{this.state.summaryInfo.reservationFee.reservationTime}</Text>
  240. </View>
  241. <View style={styles.formRow}>
  242. <Text style={styles.label}>{$t('receipt.labelDurationReservation')}</Text>
  243. <Text style={styles.text}>{this.state.summaryInfo.reservationFee.reservationDuration}</Text>
  244. </View>
  245. <View style={styles.formRow}>
  246. <Text style={styles.label}>{this.getTaxTitle($t('receipt.labelReservationFeeSubtotal2'))}</Text>
  247. <Text style={styles.text}>{this.state.summaryInfo.reservationFee.reservationFeeSubtotal}</Text>
  248. </View>
  249. </View>
  250. }
  251. { utils.isNotEmpty(this.state.summaryInfo.payment) &&
  252. <View style={styles.sections}>
  253. <Text style={styles.formTitle}>{$t('receipt.breakdownPayment')}</Text>
  254. <View style={styles.formRow}>
  255. <Text style={styles.label}>{$t('wallet.labelPaymentMadeBy')}</Text>
  256. <Text style={styles.text}>{this.state.summaryInfo.payment.paymentMadeBy ?? "-"}</Text>
  257. </View>
  258. { utils.isNotEmpty(this.state.summaryInfo.payment.transactionSubtotal) &&
  259. <View style={styles.formRow}>
  260. <Text style={styles.label}>{this.getTaxTitle($t('receipt.labelChargTransSubtotal2'))}</Text>
  261. <Text style={styles.text}>{this.state.summaryInfo.payment.transactionSubtotal}</Text>
  262. </View>
  263. }
  264. { utils.isNotEmpty(this.state.summaryInfo.payment.idleFeeSubtotal) &&
  265. <View style={styles.formRow}>
  266. <Text style={styles.label}>{this.getTaxTitle($t('receipt.labelIdleFeeSubtotal2'))}</Text>
  267. <Text style={styles.text}>{this.state.summaryInfo.payment.idleFeeSubtotal}</Text>
  268. </View>
  269. }
  270. { utils.isNotEmpty(this.state.summaryInfo.payment.reservationFeeSubtotal) &&
  271. <View style={styles.formRow}>
  272. <Text style={styles.label}>{this.getTaxTitle($t('receipt.labelReservationFeeSubtotal2'))}</Text>
  273. <Text style={styles.text}>{this.state.summaryInfo.payment.reservationFeeSubtotal}</Text>
  274. </View>
  275. }
  276. { utils.isNotEmpty(this.state.summaryInfo.payment.finalPayment) &&
  277. <View style={styles.formRow}>
  278. <Text style={styles.label}>
  279. { utils.isNotEmpty(this.state.summaryInfo.payment.discountCredit)
  280. ? $t('receipt.labelAfterDiscount')
  281. : $t('receipt.labelFinalPaymentAmount')
  282. }
  283. </Text>
  284. <Text style={styles.text}>{this.state.summaryInfo.payment.finalPayment ?? "-"}</Text>
  285. </View>
  286. }
  287. {/* <View style={styles.formRow}>
  288. <Text style={styles.label}>{$t('wallet.labelChargeRates')}</Text>
  289. <Text style={styles.text}>{currency}{this.state.summaryInfo.chargeRates ?? '0.0'}</Text>
  290. </View> */}
  291. <View style={styles.formRow}>
  292. <Text style={styles.label}>{$t('wallet.labelExchangeRate')}</Text>
  293. <Text style={styles.text}>{this.state.summaryInfo.payment.exchangeRate ?? "-"}</Text>
  294. </View>
  295. {/* <View style={styles.formRow}>
  296. <Text style={styles.label}>{$t('wallet.labelPreviousBalance')}</Text>
  297. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.previousBalance)}</Text>
  298. </View> */}
  299. <View style={styles.formRow}>
  300. <Text style={styles.label}>{$t('wallet.labelResultingBalance')}</Text>
  301. <Text style={styles.text}>{this.state.summaryInfo.payment.resultingBalance ?? "-"}</Text>
  302. </View>
  303. </View>
  304. }
  305. { this.state.isActully &&
  306. <View style={styles.bottomButton}>
  307. <Text
  308. style={styles.feedback}
  309. onPress={() => startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')}</Text>
  310. {/* <Text style={styles.tipText}>{$t('wallet.tipsReceipt')}</Text> */}
  311. <Button
  312. text={$t('home.done')}
  313. elevation={1.5}
  314. onClick={() => this.toRating()}/>
  315. </View>
  316. }
  317. </ScrollView>
  318. );
  319. }
  320. }
  321. const styles = StyleSheet.create({
  322. container: {
  323. flex: 1,
  324. paddingLeft: 16,
  325. paddingRight: 16,
  326. backgroundColor: colorLight
  327. },
  328. headerView: {
  329. alignItems: 'center',
  330. paddingTop: 16,
  331. paddingBottom: 24
  332. },
  333. topTitle: {
  334. color: textPrimary,
  335. fontSize: 16,
  336. marginTop: 8,
  337. paddingLeft: 8,
  338. fontWeight: 'bold'
  339. },
  340. topDesc: {
  341. color: textPrimary,
  342. fontSize: 14,
  343. marginBottom: 32
  344. },
  345. sections: {
  346. borderRadius: 10,
  347. marginBottom: 12,
  348. backgroundColor: colorLight
  349. },
  350. sections2: {
  351. paddingTop: 0,
  352. paddingLeft: 0,
  353. paddingRight: 0,
  354. paddingBottom: 8,
  355. borderRadius: 10,
  356. marginBottom: 8,
  357. backgroundColor: colorLight
  358. },
  359. formTitle: {
  360. color: '#000',
  361. fontSize: 14,
  362. marginTop: -4,
  363. marginBottom: 6,
  364. paddingBottom: 6,
  365. fontWeight: 'bold',
  366. borderBottomWidth: 1,
  367. borderBottomColor: textPrimary
  368. },
  369. formRow: {
  370. paddingTop: 3,
  371. paddingBottom: 3,
  372. alignItems: 'center',
  373. flexDirection: 'row'
  374. },
  375. label: {
  376. flex: 1,
  377. color: textPrimary,
  378. fontSize: 13,
  379. },
  380. text: {
  381. color: textPrimary,
  382. fontSize: 12,
  383. fontWeight: 'bold'
  384. },
  385. stationInfoView: {
  386. padding: 12,
  387. marginBottom: 0,
  388. alignItems: 'center',
  389. flexDirection: 'row',
  390. justifyContent: 'space-between'
  391. },
  392. stationInfoText: {
  393. color: '#999',
  394. fontSize: 11
  395. },
  396. connectorView: {
  397. alignItems: 'center',
  398. flexDirection: 'row'
  399. },
  400. typeIcon: {
  401. width: 36,
  402. height: 36
  403. },
  404. feedback: {
  405. color: '#12A5F9',
  406. fontSize: 14,
  407. textAlign: 'center',
  408. marginBottom: 16,
  409. ...ui.underline
  410. },
  411. bottomButton: {
  412. marginTop: 32,
  413. marginBottom: 16
  414. },
  415. tipText: {
  416. color: textPrimary,
  417. fontSize: 12,
  418. textAlign: 'center',
  419. marginBottom: 8
  420. }
  421. });