SummaryV3.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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 app from '../../../app.json';
  14. import TextView from '../../components/TextView';
  15. export default class SummaryV3 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. { utils.isNotEmpty(this.state.summaryInfo.station) &&
  196. <View style={styles.sections}>
  197. <TextView style={styles.formTitle}>{$t('wallet.labelYourStation')}</TextView>
  198. <View style={styles.formRow}>
  199. <TextView style={styles.label}>{$t('wallet.labelStationId')}</TextView>
  200. <TextView style={styles.text}>{this.state.summaryInfo.station.stationId}</TextView>
  201. </View>
  202. <View style={styles.formRow}>
  203. <TextView style={styles.label}>{$t('receipt.labelSiteName')}</TextView>
  204. <TextView style={styles.text}>{this.state.summaryInfo.station.siteName ?? "-"}</TextView>
  205. </View>
  206. </View>
  207. }
  208. { utils.isNotEmpty(this.state.summaryInfo.connector) &&
  209. <View style={styles.sections}>
  210. <TextView style={styles.formTitle}>{$t('wallet.labelYourConnector')}</TextView>
  211. <View style={styles.formRow}>
  212. <TextView style={styles.label}>{$t('charging.labelType')}:</TextView>
  213. <TextView style={styles.text}>{this.state.summaryInfo.connector.type}</TextView>
  214. </View>
  215. <View style={styles.formRow}>
  216. <TextView style={styles.label}>{$t('charging.labelPower')}:</TextView>
  217. <TextView style={styles.text}>{this.state.summaryInfo.connector.power}</TextView>
  218. </View>
  219. <View style={styles.formRow}>
  220. <TextView style={styles.label}>{$t('charging.labelRates')}:</TextView>
  221. <TextView style={styles.text}>{this.state.summaryInfo.connector.rates}</TextView>
  222. </View>
  223. </View>
  224. }
  225. { utils.isNotEmpty(this.state.summaryInfo.pointsReward) &&
  226. <View style={styles.sections}>
  227. <TextView style={styles.formTitle}>{$t('receipt.labelPointsRewards')}</TextView>
  228. <View style={styles.formRow}>
  229. <TextView style={styles.label}>{$t('receipt.labelPointsRewarded')}:</TextView>
  230. <TextView style={styles.text}>{this.state.summaryInfo.pointsReward + " " + $t('points.points')}</TextView>
  231. </View>
  232. </View>
  233. }
  234. { utils.isNotEmpty(this.state.summaryInfo.vouchers) &&
  235. <View style={styles.sections}>
  236. <TextView style={styles.formTitle}>{$t('receipt.labelVoucherUsage')}</TextView>
  237. { this.state.summaryInfo.vouchers?.map((item, index) => (
  238. <View style={styles.formRow} key={index}>
  239. <View style={ui.flex1}>
  240. <TextView style={styles.label}>{item.voucherName}</TextView>
  241. <TextView style={styles.voucherDesc}>{item.voucherDesc}</TextView>
  242. </View>
  243. <TextView style={styles.text}>{"(" + item.voucherValue + ")"}</TextView>
  244. </View>)
  245. )}
  246. </View>
  247. }
  248. { utils.isNotEmpty(this.state.summaryInfo.chargingFee) &&
  249. <View style={styles.sections}>
  250. <TextView style={styles.formTitle}>{$t('receipt.breakdownChargingFees')}</TextView>
  251. <View style={styles.formRow}>
  252. <TextView style={styles.label}>{$t('wallet.labelChargeTime')}</TextView>
  253. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.chargeTime ?? "-"}</TextView>
  254. </View>
  255. <View style={styles.formRow}>
  256. <TextView style={styles.label}>{$t('wallet.labelChargeDelivered')}</TextView>
  257. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.chargeDelivered ?? 0}</TextView>
  258. </View>
  259. <View style={styles.formRow}>
  260. <TextView style={styles.label}>{$t('receipt.labelChargTransSubtotal3')}</TextView>
  261. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.transactionSubtotal}</TextView>
  262. </View>
  263. </View>
  264. }
  265. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  266. <View style={styles.sections}>
  267. <TextView style={styles.formTitle}>{$t('receipt.breakdownIdlesFees')}</TextView>
  268. <View style={styles.formRow}>
  269. <TextView style={styles.label}>{$t('receipt.labelIdleStartTime')}</TextView>
  270. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.startTime}</TextView>
  271. </View>
  272. <View style={styles.formRow}>
  273. <TextView style={styles.label}>{$t('receipt.labelIdleDuration')}</TextView>
  274. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.duration}</TextView>
  275. </View>
  276. <View style={styles.formRow}>
  277. <TextView style={styles.label}>{$t('receipt.labelIdleFeeSubtotal3')}</TextView>
  278. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.subtotal}</TextView>
  279. </View>
  280. </View>
  281. }
  282. { utils.isNotEmpty(this.state.summaryInfo.reservationFee) &&
  283. <View style={styles.sections}>
  284. <TextView style={styles.formTitle}>{$t('receipt.breakdownReservationFees')}</TextView>
  285. <View style={styles.formRow}>
  286. <TextView style={styles.label}>{$t('receipt.labelTimeReservation')}</TextView>
  287. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationTime}</TextView>
  288. </View>
  289. <View style={styles.formRow}>
  290. <TextView style={styles.label}>{$t('receipt.labelDurationReservation')}</TextView>
  291. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationDuration}</TextView>
  292. </View>
  293. <View style={styles.formRow}>
  294. <TextView style={styles.label}>{$t('receipt.labelReservationFeeSubtotal3')}</TextView>
  295. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationFeeSubtotal}</TextView>
  296. </View>
  297. </View>
  298. }
  299. { utils.isNotEmpty(this.state.summaryInfo.payment) &&
  300. <View style={styles.sections}>
  301. <TextView style={styles.formTitle}>{$t('receipt.breakdownPayment')}</TextView>
  302. <View style={styles.formRow}>
  303. <TextView style={styles.label}>{$t('wallet.labelPaymentMadeBy')}</TextView>
  304. <TextView style={styles.text}>{this.state.summaryInfo.payment.paymentMadeBy ?? "-"}</TextView>
  305. </View>
  306. { utils.isNotEmpty(this.state.summaryInfo.payment.transactionSubtotal) &&
  307. <View style={styles.formRow}>
  308. <TextView style={styles.label}>{$t('receipt.labelChargTransSubtotal3')}</TextView>
  309. <TextView style={styles.text}>{this.state.summaryInfo.payment.transactionSubtotal}</TextView>
  310. </View>
  311. }
  312. { utils.isNotEmpty(this.state.summaryInfo.payment.idleFeeSubtotal) &&
  313. <View style={styles.formRow}>
  314. <TextView style={styles.label}>{$t('receipt.labelIdleFeeSubtotal3')}</TextView>
  315. <TextView style={styles.text}>{this.state.summaryInfo.payment.idleFeeSubtotal}</TextView>
  316. </View>
  317. }
  318. { utils.isNotEmpty(this.state.summaryInfo.payment.reservationFeeSubtotal) &&
  319. <View style={styles.formRow}>
  320. <TextView style={styles.label}>{$t('receipt.labelReservationFeeSubtotal3')}</TextView>
  321. <TextView style={styles.text}>{this.state.summaryInfo.payment.reservationFeeSubtotal}</TextView>
  322. </View>
  323. }
  324. { utils.isNotEmpty(this.state.summaryInfo.payment.finalPayment) &&
  325. <View style={styles.formRow}>
  326. <TextView style={styles.label}>
  327. { utils.isNotEmpty(this.state.summaryInfo.payment.discountCredit)
  328. ? $t('receipt.labelAfterDiscount')
  329. : $t('receipt.labelFinalPaymentAmount')
  330. }
  331. </TextView>
  332. <TextView style={styles.text}>{this.state.summaryInfo.payment.finalPayment ?? "-"}</TextView>
  333. </View>
  334. }
  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. <View style={styles.formRow}>
  340. <TextView style={styles.label}>{$t('wallet.labelResultingBalance')}</TextView>
  341. <TextView style={styles.text}>{this.state.summaryInfo.payment.resultingBalance ?? "-"}</TextView>
  342. </View>
  343. </View>
  344. }
  345. { (this.state.isActully && utils.isNotEmpty(this.state.summaryInfo.top)) &&
  346. <View style={styles.bottomButton}>
  347. <TextView
  348. style={styles.feedback}
  349. onPress={() => startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')}</TextView>
  350. {/* <Text style={styles.tipText}>{$t('wallet.tipsReceipt')}</Text> */}
  351. <Button
  352. text={$t('home.done')}
  353. elevation={1.5}
  354. onClick={() => this.toRating()}/>
  355. </View>
  356. }
  357. </ScrollView>
  358. );
  359. }
  360. }
  361. }
  362. const styles = StyleSheet.create({
  363. container: {
  364. flex: 1,
  365. paddingLeft: 16,
  366. paddingRight: 16,
  367. backgroundColor: colorLight
  368. },
  369. headerView: {
  370. alignItems: 'center',
  371. paddingTop: 16,
  372. paddingBottom: 24
  373. },
  374. topTitle: {
  375. color: textPrimary,
  376. fontSize: 16,
  377. marginTop: 8,
  378. paddingLeft: 8,
  379. fontWeight: 'bold'
  380. },
  381. topDesc: {
  382. color: textPrimary,
  383. fontSize: 14,
  384. marginBottom: 32
  385. },
  386. sections: {
  387. borderRadius: 10,
  388. marginBottom: 12,
  389. backgroundColor: colorLight
  390. },
  391. sections2: {
  392. paddingTop: 0,
  393. paddingLeft: 0,
  394. paddingRight: 0,
  395. paddingBottom: 8,
  396. borderRadius: 10,
  397. marginBottom: 8,
  398. backgroundColor: colorLight
  399. },
  400. formTitle: {
  401. color: '#000',
  402. fontSize: 14,
  403. marginTop: -4,
  404. marginBottom: 6,
  405. paddingBottom: 6,
  406. fontWeight: 'bold',
  407. borderBottomWidth: 1,
  408. borderBottomColor: textPrimary
  409. },
  410. formRow: {
  411. paddingTop: 3,
  412. paddingBottom: 3,
  413. alignItems: 'center',
  414. flexDirection: 'row'
  415. },
  416. label: {
  417. flex: 1,
  418. color: textPrimary,
  419. fontSize: 13,
  420. },
  421. text: {
  422. color: textPrimary,
  423. fontSize: 12,
  424. fontWeight: 'bold'
  425. },
  426. stationInfoView: {
  427. padding: 12,
  428. marginBottom: 0,
  429. alignItems: 'center',
  430. flexDirection: 'row',
  431. justifyContent: 'space-between'
  432. },
  433. stationInfoText: {
  434. color: '#999',
  435. fontSize: 11
  436. },
  437. connectorView: {
  438. alignItems: 'center',
  439. flexDirection: 'row'
  440. },
  441. typeIcon: {
  442. width: 36,
  443. height: 36
  444. },
  445. feedback: {
  446. color: '#12A5F9',
  447. fontSize: 14,
  448. textAlign: 'center',
  449. marginBottom: 16,
  450. ...ui.underline
  451. },
  452. bottomButton: {
  453. marginTop: 32,
  454. marginBottom: 16
  455. },
  456. tipText: {
  457. color: textPrimary,
  458. fontSize: 12,
  459. textAlign: 'center',
  460. marginBottom: 8
  461. },
  462. processContent: {
  463. flex: 1,
  464. justifyContent: 'center'
  465. },
  466. processTitle: {
  467. color: textTitle,
  468. fontSize: 24,
  469. fontWeight: 'bold',
  470. textAlign: 'center'
  471. },
  472. processText: {
  473. color: textPrimary,
  474. fontSize: 14,
  475. textAlign: 'center',
  476. paddingTop: 16
  477. },
  478. voucherDesc: {
  479. flex: 1,
  480. color: textCancel,
  481. fontSize: 13
  482. }
  483. });