Summary.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**
  2. * 新版充电结算页面
  3. * @邠心vbe on 2023/02/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Image, 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 { ChargeStyle, TypeImage } from './Charging';
  14. export default class Summary extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. isActully: true,
  19. refreshing: false,
  20. summaryInfo: {},
  21. stationInfo: {}
  22. };
  23. this.canBack = false;
  24. }
  25. componentDidMount() {
  26. const params = this.props.route.params;
  27. if (params.chargingPk) {
  28. Dialog.showProgressDialog();
  29. if (params.name && params.address) {
  30. this.setState({
  31. chargingPk: params.chargingPk,
  32. stationInfo: {
  33. id: params.id,
  34. name: params.name,
  35. address: params.address
  36. }
  37. });
  38. setTimeout(() => {
  39. this.getSummaryData(params.chargingPk);
  40. }, 5000);
  41. } else if (params.action && params.action == "view") {
  42. this.setState({
  43. isActully: false,
  44. chargingPk: params.chargingPk
  45. });
  46. this.getSummaryData(params.chargingPk);
  47. }
  48. }
  49. this.props.navigation.addListener('focus', e => {
  50. this.canBack = false;
  51. });
  52. this.props.navigation.addListener('beforeRemove', e => {
  53. if (this.state.isActully && !this.canBack) {
  54. this.toRating();
  55. e.preventDefault();
  56. }
  57. });
  58. }
  59. getSummaryData(chargingPk) {
  60. apiCharge.getChargeSummary({
  61. chargingPk: chargingPk
  62. }).then(res => {
  63. Dialog.dismissLoading();
  64. if (res.data) {
  65. this.setState({
  66. refreshing: false,
  67. summaryInfo: res.data
  68. });
  69. }
  70. }).catch(err => {
  71. Dialog.dismissLoading();
  72. toastShort(err);
  73. this.setState({
  74. refreshing: false
  75. });
  76. });
  77. }
  78. onRefresh() {
  79. if (this.state.chargingPk) {
  80. this.setState({
  81. refreshing: true
  82. });
  83. this.getSummaryData(this.state.chargingPk);
  84. }
  85. }
  86. toRating() {
  87. this.canBack = true;
  88. //goBack();
  89. startPage(PageList.home)
  90. //startPage(PageList.rating, this.state.stationInfo);
  91. }
  92. getSummaryText(data) {
  93. if (this.state.summaryInfo?.paymentType == 'Fleet Credit') {
  94. return '-';
  95. } else {
  96. return currency + '' + (data ?? '0');
  97. }
  98. }
  99. render() {
  100. return (
  101. <ScrollView
  102. style={styles.container}
  103. refreshControl={
  104. <RefreshControl
  105. {...MyRefreshProps}
  106. refreshing={this.state.refreshing}
  107. onRefresh={() => this.onRefresh()}
  108. />
  109. }>
  110. <View style={{height:16}}></View>
  111. <View style={styles.sections}>
  112. <View style={styles.formRow}>
  113. <Text style={styles.label}>Transation ID:</Text>
  114. <Text style={styles.text}>{this.state.summaryInfo.transactionPk}</Text>
  115. </View>
  116. <View style={styles.formRow}>
  117. <Text style={styles.label}>Reference ID:</Text>
  118. <Text style={styles.text}>{this.state.summaryInfo.chargingPk}</Text>
  119. </View>
  120. <View style={styles.formRow}>
  121. <Text style={styles.label}>Date Time:</Text>
  122. <Text style={styles.text}>{this.state.summaryInfo.dateTime}</Text>
  123. </View>
  124. </View>
  125. <View style={styles.sections}>
  126. <Text style={styles.formTitle}>Your Station</Text>
  127. <View style={styles.formRow}>
  128. <Text style={styles.label}>Station ID: {this.state.summaryInfo.chargeBoxPk}</Text>
  129. </View>
  130. <Text style={styles.stationInfoText}>{this.state.summaryInfo.boxAddress}</Text>
  131. </View>
  132. <View style={styles.sections2}>
  133. <Text style={styles.formTitle}>Your Connector</Text>
  134. <View style={styles.stationInfoView}>
  135. <Image
  136. style={ChargeStyle.infoIcon}
  137. source={this.state.summaryInfo.connectorType?.indexOf('AC') >= 0 ? TypeImage.AC : TypeImage.DC}/>
  138. <View style={ChargeStyle.infoGroup}>
  139. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorType}</Text>
  140. <Text style={ChargeStyle.infoTitle}>Type</Text>
  141. </View>
  142. <View style={ChargeStyle.infoGroup}>
  143. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorWattage}</Text>
  144. <Text style={ChargeStyle.infoTitle}>Power</Text>
  145. </View>
  146. <View style={ChargeStyle.infoGroup}>
  147. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorRate}</Text>
  148. <Text style={ChargeStyle.infoTitle}>Rates</Text>
  149. </View>
  150. </View>
  151. </View>
  152. <View style={styles.sections}>
  153. <Text style={styles.formTitle}>Breakdown</Text>
  154. <View style={styles.formRow}>
  155. <Text style={styles.label}>Reservation Fee:</Text>
  156. <Text style={styles.text}>{currency}{this.state.summaryInfo.reservationFee ?? 0}</Text>
  157. </View>
  158. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  159. <View style={styles.formRow}>
  160. <Text style={styles.label}>Idle Fee:</Text>
  161. <Text style={styles.text}>{currency}{this.state.summaryInfo.idleFee}</Text>
  162. </View>
  163. }
  164. <View style={styles.formRow}>
  165. <Text style={styles.label}>Charge Time:</Text>
  166. <Text style={styles.text}>{utils.hour2HHmm(this.state.summaryInfo.chargeTime)}</Text>
  167. </View>
  168. <View style={styles.formRow}>
  169. <Text style={styles.label}>Charge Delivered:</Text>
  170. <Text style={styles.text}>{this.state.summaryInfo.chargeDelivered ?? 0}kWh</Text>
  171. </View>
  172. <View style={styles.formRow}>
  173. <Text style={styles.label}>Charge Rates (GST Inclusive):</Text>
  174. <Text style={styles.text}>{currency}{this.state.summaryInfo.chargeRates ?? '0.0'}</Text>
  175. </View>
  176. </View>
  177. <View style={styles.sections}>
  178. <Text style={styles.formTitle}>Subtotal</Text>
  179. <View style={styles.formRow}>
  180. <Text style={styles.label}>Payment Made By:</Text>
  181. <Text style={styles.text}>{this.state.summaryInfo.paymentType}</Text>
  182. </View>
  183. <View style={styles.formRow}>
  184. <Text style={styles.label}>Previous Balance:</Text>
  185. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.previousBalance)}</Text>
  186. </View>
  187. <View style={styles.formRow}>
  188. <Text style={styles.label}>Payment (GST Inclusive):</Text>
  189. <Text style={styles.text}>{currency}{this.state.summaryInfo.payment ?? '0.0'}</Text>
  190. </View>
  191. <View style={styles.formRow}>
  192. <Text style={styles.label}>Resulting Balance:</Text>
  193. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.resultingBalance)}</Text>
  194. </View>
  195. </View>
  196. { this.state.isActully &&
  197. <View style={styles.bottomButton}>
  198. <Text
  199. style={styles.feedback}
  200. onPress={() => startPage(PageList.feedback)}>Submit Your Feedback</Text>
  201. <Text style={styles.tipText}>A Receipt Will Be Sent To Your Email</Text>
  202. <Button
  203. text='Done'
  204. elevation={1.5}
  205. onClick={() => this.toRating()}/>
  206. </View>
  207. }
  208. </ScrollView>
  209. );
  210. }
  211. }
  212. const styles = StyleSheet.create({
  213. container: {
  214. flex: 1,
  215. paddingLeft: 16,
  216. paddingRight: 16,
  217. backgroundColor: colorLight
  218. },
  219. sections: {
  220. borderRadius: 10,
  221. marginBottom: 16,
  222. backgroundColor: colorLight
  223. },
  224. sections2: {
  225. paddingTop: 0,
  226. paddingLeft: 0,
  227. paddingRight: 0,
  228. paddingBottom: 8,
  229. borderRadius: 10,
  230. marginBottom: 8,
  231. backgroundColor: colorLight
  232. },
  233. formTitle: {
  234. color: '#000',
  235. fontSize: 14,
  236. marginTop: -4,
  237. marginBottom: 6,
  238. paddingBottom: 6,
  239. fontWeight: 'bold',
  240. borderBottomWidth: 1,
  241. borderBottomColor: '#eee'
  242. },
  243. formRow: {
  244. paddingTop: 3,
  245. paddingBottom: 3,
  246. alignItems: 'center',
  247. flexDirection: 'row'
  248. },
  249. label: {
  250. flex: 1,
  251. color: textPrimary,
  252. fontSize: 13,
  253. },
  254. text: {
  255. color: textPrimary,
  256. fontSize: 13,
  257. },
  258. stationInfoView: {
  259. padding: 12,
  260. marginBottom: 0,
  261. alignItems: 'center',
  262. flexDirection: 'row',
  263. justifyContent: 'space-between'
  264. },
  265. stationInfoText: {
  266. color: '#999',
  267. fontSize: 11
  268. },
  269. connectorView: {
  270. alignItems: 'center',
  271. flexDirection: 'row'
  272. },
  273. typeIcon: {
  274. width: 36,
  275. height: 36
  276. },
  277. feedback: {
  278. color: '#12A5F9',
  279. fontSize: 14,
  280. textAlign: 'center',
  281. marginBottom: 16,
  282. ...ui.underline
  283. },
  284. bottomButton: {
  285. marginTop: 32,
  286. marginBottom: 16
  287. },
  288. tipText: {
  289. color: textPrimary,
  290. fontSize: 12,
  291. textAlign: 'center',
  292. marginBottom: 8
  293. }
  294. });