SummaryV2.js 16 KB

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