SummaryV3.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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 Summary 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.chargingFee) &&
  226. <View style={styles.sections}>
  227. <TextView style={styles.formTitle}>{$t('receipt.breakdownChargingFees')}</TextView>
  228. <View style={styles.formRow}>
  229. <TextView style={styles.label}>{$t('wallet.labelChargeTime')}</TextView>
  230. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.chargeTime ?? "-"}</TextView>
  231. </View>
  232. <View style={styles.formRow}>
  233. <TextView style={styles.label}>{$t('wallet.labelChargeDelivered')}</TextView>
  234. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.chargeDelivered ?? 0}</TextView>
  235. </View>
  236. <View style={styles.formRow}>
  237. <TextView style={styles.label}>{$t('receipt.labelChargTransSubtotal3')}</TextView>
  238. <TextView style={styles.text}>{this.state.summaryInfo.chargingFee.transactionSubtotal}</TextView>
  239. </View>
  240. </View>
  241. }
  242. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  243. <View style={styles.sections}>
  244. <TextView style={styles.formTitle}>{$t('receipt.breakdownIdlesFees')}</TextView>
  245. <View style={styles.formRow}>
  246. <TextView style={styles.label}>{$t('receipt.labelIdleStartTime')}</TextView>
  247. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.startTime}</TextView>
  248. </View>
  249. <View style={styles.formRow}>
  250. <TextView style={styles.label}>{$t('receipt.labelIdleDuration')}</TextView>
  251. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.duration}</TextView>
  252. </View>
  253. <View style={styles.formRow}>
  254. <TextView style={styles.label}>{$t('receipt.labelIdleFeeSubtotal3')}</TextView>
  255. <TextView style={styles.text}>{this.state.summaryInfo.idleFee.subtotal}</TextView>
  256. </View>
  257. </View>
  258. }
  259. { utils.isNotEmpty(this.state.summaryInfo.reservationFee) &&
  260. <View style={styles.sections}>
  261. <TextView style={styles.formTitle}>{$t('receipt.breakdownReservationFees')}</TextView>
  262. <View style={styles.formRow}>
  263. <TextView style={styles.label}>{$t('receipt.labelTimeReservation')}</TextView>
  264. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationTime}</TextView>
  265. </View>
  266. <View style={styles.formRow}>
  267. <TextView style={styles.label}>{$t('receipt.labelDurationReservation')}</TextView>
  268. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationDuration}</TextView>
  269. </View>
  270. <View style={styles.formRow}>
  271. <TextView style={styles.label}>{$t('receipt.labelReservationFeeSubtotal3')}</TextView>
  272. <TextView style={styles.text}>{this.state.summaryInfo.reservationFee.reservationFeeSubtotal}</TextView>
  273. </View>
  274. </View>
  275. }
  276. { utils.isNotEmpty(this.state.summaryInfo.payment) &&
  277. <View style={styles.sections}>
  278. <TextView style={styles.formTitle}>{$t('receipt.breakdownPayment')}</TextView>
  279. <View style={styles.formRow}>
  280. <TextView style={styles.label}>{$t('wallet.labelPaymentMadeBy')}</TextView>
  281. <TextView style={styles.text}>{this.state.summaryInfo.payment.paymentMadeBy ?? "-"}</TextView>
  282. </View>
  283. { utils.isNotEmpty(this.state.summaryInfo.payment.transactionSubtotal) &&
  284. <View style={styles.formRow}>
  285. <TextView style={styles.label}>{$t('receipt.labelChargTransSubtotal3')}</TextView>
  286. <TextView style={styles.text}>{this.state.summaryInfo.payment.transactionSubtotal}</TextView>
  287. </View>
  288. }
  289. { utils.isNotEmpty(this.state.summaryInfo.payment.idleFeeSubtotal) &&
  290. <View style={styles.formRow}>
  291. <TextView style={styles.label}>{$t('receipt.labelIdleFeeSubtotal3')}</TextView>
  292. <TextView style={styles.text}>{this.state.summaryInfo.payment.idleFeeSubtotal}</TextView>
  293. </View>
  294. }
  295. { utils.isNotEmpty(this.state.summaryInfo.payment.reservationFeeSubtotal) &&
  296. <View style={styles.formRow}>
  297. <TextView style={styles.label}>{$t('receipt.labelReservationFeeSubtotal3')}</TextView>
  298. <TextView style={styles.text}>{this.state.summaryInfo.payment.reservationFeeSubtotal}</TextView>
  299. </View>
  300. }
  301. { utils.isNotEmpty(this.state.summaryInfo.payment.finalPayment) &&
  302. <View style={styles.formRow}>
  303. <TextView style={styles.label}>
  304. { utils.isNotEmpty(this.state.summaryInfo.payment.discountCredit)
  305. ? $t('receipt.labelAfterDiscount')
  306. : $t('receipt.labelFinalPaymentAmount')
  307. }
  308. </TextView>
  309. <TextView style={styles.text}>{this.state.summaryInfo.payment.finalPayment ?? "-"}</TextView>
  310. </View>
  311. }
  312. <View style={styles.formRow}>
  313. <TextView style={styles.label}>{$t('wallet.labelExchangeRate')}</TextView>
  314. <TextView style={styles.text}>{this.state.summaryInfo.payment.exchangeRate ?? "-"}</TextView>
  315. </View>
  316. <View style={styles.formRow}>
  317. <TextView style={styles.label}>{$t('wallet.labelResultingBalance')}</TextView>
  318. <TextView style={styles.text}>{this.state.summaryInfo.payment.resultingBalance ?? "-"}</TextView>
  319. </View>
  320. </View>
  321. }
  322. { (this.state.isActully && utils.isNotEmpty(this.state.summaryInfo.top)) &&
  323. <View style={styles.bottomButton}>
  324. <TextView
  325. style={styles.feedback}
  326. onPress={() => startPage(PageList.feedback)}>{$t('wallet.linkSubmitFeedback')}</TextView>
  327. {/* <Text style={styles.tipText}>{$t('wallet.tipsReceipt')}</Text> */}
  328. <Button
  329. text={$t('home.done')}
  330. elevation={1.5}
  331. onClick={() => this.toRating()}/>
  332. </View>
  333. }
  334. </ScrollView>
  335. );
  336. }
  337. }
  338. }
  339. const styles = StyleSheet.create({
  340. container: {
  341. flex: 1,
  342. paddingLeft: 16,
  343. paddingRight: 16,
  344. backgroundColor: colorLight
  345. },
  346. headerView: {
  347. alignItems: 'center',
  348. paddingTop: 16,
  349. paddingBottom: 24
  350. },
  351. topTitle: {
  352. color: textPrimary,
  353. fontSize: 16,
  354. marginTop: 8,
  355. paddingLeft: 8,
  356. fontWeight: 'bold'
  357. },
  358. topDesc: {
  359. color: textPrimary,
  360. fontSize: 14,
  361. marginBottom: 32
  362. },
  363. sections: {
  364. borderRadius: 10,
  365. marginBottom: 12,
  366. backgroundColor: colorLight
  367. },
  368. sections2: {
  369. paddingTop: 0,
  370. paddingLeft: 0,
  371. paddingRight: 0,
  372. paddingBottom: 8,
  373. borderRadius: 10,
  374. marginBottom: 8,
  375. backgroundColor: colorLight
  376. },
  377. formTitle: {
  378. color: '#000',
  379. fontSize: 14,
  380. marginTop: -4,
  381. marginBottom: 6,
  382. paddingBottom: 6,
  383. fontWeight: 'bold',
  384. borderBottomWidth: 1,
  385. borderBottomColor: textPrimary
  386. },
  387. formRow: {
  388. paddingTop: 3,
  389. paddingBottom: 3,
  390. alignItems: 'center',
  391. flexDirection: 'row'
  392. },
  393. label: {
  394. flex: 1,
  395. color: textPrimary,
  396. fontSize: 13,
  397. },
  398. text: {
  399. color: textPrimary,
  400. fontSize: 12,
  401. fontWeight: 'bold'
  402. },
  403. stationInfoView: {
  404. padding: 12,
  405. marginBottom: 0,
  406. alignItems: 'center',
  407. flexDirection: 'row',
  408. justifyContent: 'space-between'
  409. },
  410. stationInfoText: {
  411. color: '#999',
  412. fontSize: 11
  413. },
  414. connectorView: {
  415. alignItems: 'center',
  416. flexDirection: 'row'
  417. },
  418. typeIcon: {
  419. width: 36,
  420. height: 36
  421. },
  422. feedback: {
  423. color: '#12A5F9',
  424. fontSize: 14,
  425. textAlign: 'center',
  426. marginBottom: 16,
  427. ...ui.underline
  428. },
  429. bottomButton: {
  430. marginTop: 32,
  431. marginBottom: 16
  432. },
  433. tipText: {
  434. color: textPrimary,
  435. fontSize: 12,
  436. textAlign: 'center',
  437. marginBottom: 8
  438. },
  439. processContent: {
  440. flex: 1,
  441. justifyContent: 'center'
  442. },
  443. processTitle: {
  444. color: textTitle,
  445. fontSize: 24,
  446. fontWeight: 'bold',
  447. textAlign: 'center'
  448. },
  449. processText: {
  450. color: textPrimary,
  451. fontSize: 14,
  452. textAlign: 'center',
  453. paddingTop: 16
  454. }
  455. });