Summary.js 8.8 KB

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