SummaryV2.js 18 KB

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