Summary.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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.rating, this.state.stationInfo);
  90. }
  91. getSummaryText(data) {
  92. if (this.state.summaryInfo?.paymentType == 'Fleet Credit') {
  93. return '-';
  94. } else {
  95. return currency + '' + (data ?? '0');
  96. }
  97. }
  98. render() {
  99. return (
  100. <ScrollView
  101. style={styles.container}
  102. refreshControl={
  103. <RefreshControl
  104. {...MyRefreshProps}
  105. refreshing={this.state.refreshing}
  106. onRefresh={() => this.onRefresh()}
  107. />
  108. }>
  109. <View style={{height:16}}></View>
  110. <View style={styles.sections}>
  111. <View style={styles.formRow}>
  112. <Text style={styles.label}>Transation ID:</Text>
  113. <Text style={styles.text}>{this.state.summaryInfo.transactionPk}</Text>
  114. </View>
  115. <View style={styles.formRow}>
  116. <Text style={styles.label}>Reference ID:</Text>
  117. <Text style={styles.text}>{this.state.summaryInfo.chargingPk}</Text>
  118. </View>
  119. <View style={styles.formRow}>
  120. <Text style={styles.label}>Date Time:</Text>
  121. <Text style={styles.text}>{this.state.summaryInfo.dateTime}</Text>
  122. </View>
  123. </View>
  124. <View style={styles.sections}>
  125. <Text style={styles.formTitle}>Your Station</Text>
  126. <View style={styles.formRow}>
  127. <Text style={styles.label}>Station ID: {this.state.summaryInfo.chargeBoxPk}</Text>
  128. </View>
  129. <Text style={styles.stationInfoText}>{this.state.summaryInfo.boxAddress}</Text>
  130. </View>
  131. <View style={styles.sections2}>
  132. <Text style={styles.formTitle}>Your Connector</Text>
  133. <View style={styles.stationInfoView}>
  134. <Image
  135. style={ChargeStyle.infoIcon}
  136. source={this.state.summaryInfo.connectorType?.indexOf('AC') >= 0 ? TypeImage.AC : TypeImage.DC}/>
  137. <View style={ChargeStyle.infoGroup}>
  138. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorType}</Text>
  139. <Text style={ChargeStyle.infoTitle}>Type</Text>
  140. </View>
  141. <View style={ChargeStyle.infoGroup}>
  142. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorWattage}</Text>
  143. <Text style={ChargeStyle.infoTitle}>Power</Text>
  144. </View>
  145. <View style={ChargeStyle.infoGroup}>
  146. <Text style={ChargeStyle.infoText}>{this.state.summaryInfo.connectorRate}</Text>
  147. <Text style={ChargeStyle.infoTitle}>Rates</Text>
  148. </View>
  149. </View>
  150. </View>
  151. <View style={styles.sections}>
  152. <Text style={styles.formTitle}>Breakdown</Text>
  153. <View style={styles.formRow}>
  154. <Text style={styles.label}>Reservation Fee:</Text>
  155. <Text style={styles.text}>{currency}{this.state.summaryInfo.reservationFee ?? 0}</Text>
  156. </View>
  157. { utils.isNotEmpty(this.state.summaryInfo.idleFee) &&
  158. <View style={styles.formRow}>
  159. <Text style={styles.label}>Idle Fee:</Text>
  160. <Text style={styles.text}>{currency}{this.state.summaryInfo.idleFee}</Text>
  161. </View>
  162. }
  163. <View style={styles.formRow}>
  164. <Text style={styles.label}>Charge Time:</Text>
  165. <Text style={styles.text}>{utils.hour2HHmm(this.state.summaryInfo.chargeTime)}</Text>
  166. </View>
  167. <View style={styles.formRow}>
  168. <Text style={styles.label}>Charge Delivered:</Text>
  169. <Text style={styles.text}>{this.state.summaryInfo.chargeDelivered ?? 0}kWh</Text>
  170. </View>
  171. <View style={styles.formRow}>
  172. <Text style={styles.label}>Charge Rates (GST Inclusive):</Text>
  173. <Text style={styles.text}>{currency}{this.state.summaryInfo.chargeRates ?? '0.0'}</Text>
  174. </View>
  175. </View>
  176. <View style={styles.sections}>
  177. <Text style={styles.formTitle}>Subtotal</Text>
  178. <View style={styles.formRow}>
  179. <Text style={styles.label}>Payment Made By:</Text>
  180. <Text style={styles.text}>{this.state.summaryInfo.paymentType}</Text>
  181. </View>
  182. <View style={styles.formRow}>
  183. <Text style={styles.label}>Previous Balance:</Text>
  184. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.previousBalance)}</Text>
  185. </View>
  186. <View style={styles.formRow}>
  187. <Text style={styles.label}>Payment (GST Inclusive):</Text>
  188. <Text style={styles.text}>{currency}{this.state.summaryInfo.payment ?? '0.0'}</Text>
  189. </View>
  190. <View style={styles.formRow}>
  191. <Text style={styles.label}>Resulting Balance:</Text>
  192. <Text style={styles.text}>{this.getSummaryText(this.state.summaryInfo.resultingBalance)}</Text>
  193. </View>
  194. </View>
  195. { this.state.isActully &&
  196. <View style={styles.bottomButton}>
  197. <Text
  198. style={styles.feedback}
  199. onPress={() => startPage(PageList.feedback)}>Submit Your Feedback</Text>
  200. <Text style={styles.tipText}>A Receipt Will Be Sent To Your Email</Text>
  201. <Button
  202. text='Done'
  203. elevation={1.5}
  204. onClick={() => this.toRating()}/>
  205. </View>
  206. }
  207. </ScrollView>
  208. );
  209. }
  210. }
  211. const styles = StyleSheet.create({
  212. container: {
  213. flex: 1,
  214. paddingLeft: 16,
  215. paddingRight: 16,
  216. backgroundColor: colorLight
  217. },
  218. sections: {
  219. borderRadius: 10,
  220. marginBottom: 16,
  221. backgroundColor: colorLight
  222. },
  223. sections2: {
  224. paddingTop: 0,
  225. paddingLeft: 0,
  226. paddingRight: 0,
  227. paddingBottom: 8,
  228. borderRadius: 10,
  229. marginBottom: 8,
  230. backgroundColor: colorLight
  231. },
  232. formTitle: {
  233. color: '#000',
  234. fontSize: 14,
  235. marginTop: -4,
  236. marginBottom: 6,
  237. paddingBottom: 6,
  238. fontWeight: 'bold',
  239. borderBottomWidth: 1,
  240. borderBottomColor: '#eee'
  241. },
  242. formRow: {
  243. paddingTop: 3,
  244. paddingBottom: 3,
  245. alignItems: 'center',
  246. flexDirection: 'row'
  247. },
  248. label: {
  249. flex: 1,
  250. color: textPrimary,
  251. fontSize: 13,
  252. },
  253. text: {
  254. color: textPrimary,
  255. fontSize: 13,
  256. },
  257. stationInfoView: {
  258. padding: 12,
  259. marginBottom: 0,
  260. alignItems: 'center',
  261. flexDirection: 'row',
  262. justifyContent: 'space-between'
  263. },
  264. stationInfoText: {
  265. color: '#999',
  266. fontSize: 11
  267. },
  268. connectorView: {
  269. alignItems: 'center',
  270. flexDirection: 'row'
  271. },
  272. typeIcon: {
  273. width: 36,
  274. height: 36
  275. },
  276. feedback: {
  277. color: '#12A5F9',
  278. fontSize: 14,
  279. textAlign: 'center',
  280. marginBottom: 16,
  281. ...ui.underline
  282. },
  283. bottomButton: {
  284. marginTop: 32,
  285. marginBottom: 16
  286. },
  287. tipText: {
  288. color: textPrimary,
  289. fontSize: 12,
  290. textAlign: 'center',
  291. marginBottom: 8
  292. }
  293. });