SummaryV3.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /**
  2. * V3新版充电结算页面
  3. * @邠心vbe on 2023/12/22
  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 TextView from '../../components/TextView';
  14. export default class SummaryV3 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. isPendding: false
  31. };
  32. this.action = "";
  33. this.canBack = false;
  34. }
  35. componentDidMount() {
  36. const params = this.props.route.params;
  37. if (params.chargingPk) {
  38. Dialog.showProgressDialog();
  39. this.setState({
  40. chargingPk: params.chargingPk
  41. })
  42. if (params.action && params.action == "view") {
  43. this.setState({
  44. isActully: false
  45. });
  46. this.getSummaryData(params.chargingPk);
  47. } else {
  48. setTimeout(() => {
  49. this.getSummaryData(params.chargingPk);
  50. }, 1500);
  51. }
  52. }
  53. if (params.action) {
  54. this.action = params.action;
  55. }
  56. this.props.navigation.addListener('focus', e => {
  57. this.canBack = false;
  58. });
  59. this.props.navigation.addListener('beforeRemove', e => {
  60. if (this.state.isActully && !this.canBack) {
  61. this.toRating();
  62. e.preventDefault();
  63. }
  64. });
  65. }
  66. getSummaryData(chargingPk) {
  67. apiCharge.getChargeSummaryV2({
  68. chargingPk: chargingPk
  69. }).then(res => {
  70. Dialog.dismissLoading();
  71. if (res.data) {
  72. this.setState({
  73. refreshing: false,
  74. summaryInfo: res.data,
  75. isPendding: (res.data.hasSettled != true)
  76. });
  77. }
  78. }).catch((err) => {
  79. Dialog.dismissLoading();
  80. toastShort(err);
  81. this.setState({
  82. isPendding: true,
  83. refreshing: false
  84. });
  85. });
  86. }
  87. onRefresh() {
  88. if (this.state.chargingPk) {
  89. this.setState({
  90. refreshing: true
  91. });
  92. this.getSummaryData(this.state.chargingPk);
  93. }
  94. }
  95. toRating() {
  96. this.canBack = true;
  97. if (this.action == "view") {
  98. goBack();
  99. } else {
  100. //routeUtil.resetToHome(this.props);
  101. startPage(PageList.home);
  102. //startPage(PageList.rating, this.state.stationInfo);
  103. }
  104. }
  105. toTransaction() {
  106. if (this.action == "view") {
  107. goBack();
  108. } else {
  109. startPage(PageList.wallet)
  110. }
  111. }
  112. getSummaryText(data) {
  113. if (this.state.summaryInfo?.paymentType == 'Fleet Credit') {
  114. return '-';
  115. } else {
  116. return currency + '' + (data ?? '0');
  117. }
  118. }
  119. getTaxTitle(title="") {
  120. if (this.state.summaryInfo?.taxRate) {
  121. return title.replace("$s", this.state.summaryInfo.taxRate)
  122. } else {
  123. return title;
  124. }
  125. }
  126. render() {
  127. if (this.state.isPendding) {
  128. return (
  129. <View style={styles.container}>
  130. <View style={styles.processContent}>
  131. <TextView style={styles.processTitle}>{$t("receipt.processTitle")}</TextView>
  132. <TextView style={styles.processText}>{$t("receipt.processMessage1")}</TextView>
  133. <TextView style={styles.processText}>
  134. {$t("receipt.processMessage2")}
  135. <Text style={[ui.bold, ui.underline]} onPress={() => this.toTransaction()}>{$t("receipt.processMessage3")}</Text>.
  136. </TextView>
  137. <TextView style={styles.processText}>{$t("receipt.processMessage4")}</TextView>
  138. </View>
  139. <View style={styles.bottomButton}>
  140. <Button
  141. text={$t('home.done')}
  142. elevation={1.5}
  143. onClick={() => this.toRating()}/>
  144. </View>
  145. </View>
  146. )
  147. } else {
  148. return (
  149. <ScrollView
  150. style={styles.container}
  151. refreshControl={
  152. <RefreshControl
  153. {...MyRefreshProps()}
  154. refreshing={this.state.refreshing}
  155. onRefresh={() => this.onRefresh()}
  156. />
  157. }>
  158. { utils.isNotEmpty(this.state.summaryInfo.top) &&
  159. <View style={styles.headerView}>
  160. { this.state.isActully && <>
  161. <Octicons
  162. name="check-circle-fill"
  163. color={colorAccent}
  164. size={56}/>
  165. <TextView style={styles.topTitle}>{$t('receipt.successful')}</TextView>
  166. <TextView style={styles.topDesc}>{$t('receipt.chargingSessionComplete')}</TextView>
  167. </>}
  168. { utils.isNotEmpty(this.state.summaryInfo.top.company) &&
  169. <View style={styles.formRow}>
  170. <TextView style={styles.label}>{$t('sign.labelCompany')}:</TextView>
  171. <TextView style={styles.text}>{this.state.summaryInfo.top.company}</TextView>
  172. </View>
  173. }
  174. { utils.isNotEmpty(this.state.summaryInfo.top.registrationNo) &&
  175. <View style={styles.formRow}>
  176. <TextView style={styles.label}>{$t('receipt.labelRegistrationNo')}</TextView>
  177. <TextView style={styles.text}>{this.state.summaryInfo.top.registrationNo}</TextView>
  178. </View>
  179. }
  180. <View style={styles.formRow}>
  181. <TextView style={styles.label}>{$t('receipt.labelTransactionID')}</TextView>
  182. <TextView style={styles.text}>{this.state.summaryInfo.top.transactionId}</TextView>
  183. </View>
  184. <View style={styles.formRow}>
  185. <TextView style={styles.label}>{$t('receipt.labelReferenceID')}</TextView>
  186. <TextView style={styles.text}>{this.state.summaryInfo.top.referenceId}</TextView>
  187. </View>
  188. <View style={styles.formRow}>
  189. <TextView style={styles.label}>{$t('receipt.labelDateTime')}</TextView>
  190. <TextView style={styles.text}>{this.state.summaryInfo.top.dateTime}</TextView>
  191. </View>
  192. </View>
  193. }
  194. { utils.isNotEmpty(this.state.summaryInfo.station) &&
  195. <View style={styles.sections}>
  196. <TextView style={styles.formTitle}>{$t('wallet.labelYourStation')}</TextView>
  197. <View style={styles.formRow}>
  198. <TextView style={styles.label}>{$t('wallet.labelStationId')}</TextView>
  199. <TextView style={styles.text}>{this.state.summaryInfo.station.stationId}</TextView>
  200. </View>
  201. <View style={styles.formRow}>
  202. <TextView style={styles.label}>{$t('receipt.labelSiteName')}</TextView>
  203. <TextView style={styles.text}>{this.state.summaryInfo.station.siteName ?? "-"}</TextView>
  204. </View>
  205. </View>
  206. }
  207. { utils.isNotEmpty(this.state.summaryInfo.connector) &&
  208. <View style={styles.sections}>
  209. <TextView style={styles.formTitle}>{$t('wallet.labelYourConnector')}</TextView>
  210. <View style={styles.formRow}>
  211. <TextView style={styles.label}>{$t('charging.labelType')}:</TextView>
  212. <TextView style={styles.text}>{this.state.summaryInfo.connector.type}</TextView>
  213. </View>
  214. <View style={styles.formRow}>
  215. <TextView style={styles.label}>{$t('charging.labelPower')}:</TextView>
  216. <TextView style={styles.text}>{this.state.summaryInfo.connector.power}</TextView>
  217. </View>
  218. <View style={styles.formRow}>
  219. <TextView style={styles.label}>{$t('charging.labelRates')}:</TextView>
  220. <TextView style={styles.text}>{this.state.summaryInfo.connector.rates}</TextView>
  221. </View>
  222. </View>
  223. }
  224. { utils.isNotEmpty(this.state.summaryInfo.payment?.pointsReward) &&
  225. <View style={styles.sections}>
  226. <TextView style={styles.formTitle}>{$t('receipt.labelPointsRewards')}</TextView>
  227. <View style={styles.formRow}>
  228. <TextView style={styles.label}>{$t('receipt.labelPointsRewarded')}:</TextView>
  229. <TextView style={styles.text}>{this.state.summaryInfo.payment.pointsReward + " " + $t('points.points')}</TextView>
  230. </View>
  231. </View>
  232. }
  233. { utils.isNotEmpty(this.state.summaryInfo.vouchers) &&
  234. <View style={styles.sections}>
  235. <TextView style={styles.formTitle}>{$t('receipt.labelVoucherUsage')}</TextView>
  236. { this.state.summaryInfo.vouchers?.map((item, index) => (
  237. <View style={styles.formRow} key={index}>
  238. <View style={ui.flex1}>
  239. <TextView style={styles.label}>{item.voucherName}</TextView>
  240. <TextView style={styles.voucherDesc}>{item.voucherDesc}</TextView>
  241. </View>
  242. <TextView style={styles.text}>{"(" + item.voucherCurrencySymbol + " " + item.voucherCredit + ")"}</TextView>
  243. </View>)
  244. )}
  245. </View>
  246. }
  247. { utils.isNotEmpty(this.state.summaryInfo.chargingFee) &&
  248. <View style={styles.sections}>
  249. <TextView style={styles.formTitle}>{$t('receipt.breakdownChargingFees')}</TextView>
  250. <View style={styles.formRow}>
  251. <TextView style={styles.label}>{$t('wallet.labelChargeTime')}</TextView>
  252. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.chargeTime ?? "-"}</TextView>
  253. </View>
  254. <View style={styles.formRow}>
  255. <TextView style={styles.label}>{$t('wallet.labelChargeDelivered')}</TextView>
  256. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.chargeDelivered ?? 0}</TextView>
  257. </View>
  258. <View style={styles.formRow}>
  259. <TextView style={styles.label}>{$t('receipt.labelChargTransSubtotal3')}</TextView>
  260. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.transactionSubtotal}</TextView>
  261. </View>
  262. </View>
  263. }
  264. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  265. <View style={styles.sections}>
  266. <TextView style={styles.formTitle}>{$t('receipt.breakdownIdlesFees')}</TextView>
  267. <View style={styles.formRow}>
  268. <TextView style={styles.label}>{$t('receipt.labelIdleStartTime')}</TextView>
  269. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.startTime}</TextView>
  270. </View>
  271. <View style={styles.formRow}>
  272. <TextView style={styles.label}>{$t('receipt.labelIdleDuration')}</TextView>
  273. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.duration}</TextView>
  274. </View>
  275. <View style={styles.formRow}>
  276. <TextView style={styles.label}>{$t('receipt.labelIdleFeeSubtotal3')}</TextView>
  277. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.subtotal}</TextView>
  278. </View>
  279. </View>
  280. }
  281. { utils.isNotEmpty(this.state.summaryInfo.reservationFee) &&
  282. <View style={styles.sections}>
  283. <TextView style={styles.formTitle}>{$t('receipt.breakdownReservationFees')}</TextView>
  284. <View style={styles.formRow}>
  285. <TextView style={styles.label}>{$t('receipt.labelTimeReservation')}</TextView>
  286. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationTime}</TextView>
  287. </View>
  288. <View style={styles.formRow}>
  289. <TextView style={styles.label}>{$t('receipt.labelDurationReservation')}</TextView>
  290. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationDuration}</TextView>
  291. </View>
  292. <View style={styles.formRow}>
  293. <TextView style={styles.label}>{$t('receipt.labelReservationFeeSubtotal3')}</TextView>
  294. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationFeeSubtotal}</TextView>
  295. </View>
  296. </View>
  297. }
  298. { utils.isNotEmpty(this.state.summaryInfo.payment) &&
  299. <View style={styles.sections}>
  300. <TextView style={styles.formTitle}>{$t('receipt.breakdownPayment')}</TextView>
  301. <View style={styles.formRow}>
  302. <TextView style={styles.label}>{$t('wallet.labelPaymentMadeBy')}</TextView>
  303. <TextView style={styles.text}>{this.state.summaryInfo.payment.paymentMadeBy ?? "-"}</TextView>
  304. </View>
  305. { utils.isNotEmpty(this.state.summaryInfo.payment.transactionSubtotal) &&
  306. <View style={styles.formRow}>
  307. <TextView style={styles.label}>{$t('receipt.labelChargTransSubtotal3')}</TextView>
  308. <TextView style={styles.text}>{this.state.summaryInfo.payment.transactionSubtotal}</TextView>
  309. </View>
  310. }
  311. { utils.isNotEmpty(this.state.summaryInfo.payment.idleFeeSubtotal) &&
  312. <View style={styles.formRow}>
  313. <TextView style={styles.label}>{$t('receipt.labelIdleFeeSubtotal3')}</TextView>
  314. <TextView style={styles.text}>{this.state.summaryInfo.payment.idleFeeSubtotal}</TextView>
  315. </View>
  316. }
  317. { utils.isNotEmpty(this.state.summaryInfo.payment.reservationFeeSubtotal) &&
  318. <View style={styles.formRow}>
  319. <TextView style={styles.label}>{$t('receipt.labelReservationFeeSubtotal3')}</TextView>
  320. <TextView style={styles.text}>{this.state.summaryInfo.payment.reservationFeeSubtotal}</TextView>
  321. </View>
  322. }
  323. { utils.isNotEmpty(this.state.summaryInfo.payment.finalPayment) &&
  324. <View style={styles.formRow}>
  325. <TextView style={styles.label}>
  326. { utils.isNotEmpty(this.state.summaryInfo.payment.discountCredit)
  327. ? $t('receipt.labelAfterDiscount')
  328. : $t('receipt.labelFinalPaymentAmount')
  329. }
  330. </TextView>
  331. <TextView style={styles.text}>{this.state.summaryInfo.payment.finalPayment ?? "-"}</TextView>
  332. </View>
  333. }
  334. { utils.isNotEmpty(this.state.summaryInfo.payment.exchangeRate) &&
  335. <View style={styles.formRow}>
  336. <TextView style={styles.label}>{$t('wallet.labelExchangeRate')}</TextView>
  337. <TextView style={styles.text}>{this.state.summaryInfo.payment.exchangeRate ?? "-"}</TextView>
  338. </View>
  339. }
  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. voucherDesc: {
  489. flex: 1,
  490. color: textCancel,
  491. fontSize: 13
  492. }
  493. });