StepCharging.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. * 新充电流程:正在充电模块
  3. * @邠心vbe on 2023/06/20
  4. */
  5. import React, { useEffect, useRef, useState } from 'react';
  6. import { Animated, Easing, Image, ScrollView, StyleSheet, Text, View } from 'react-native';
  7. import Button, { ElevationObject } from '../../components/Button';
  8. import utils from '../../utils/utils';
  9. import { PaymentList } from '../chargeV2/Payment';
  10. const StepCharging = ({
  11. connectorInfo={},
  12. currentPayment,
  13. curerntPerUse,
  14. onStopCharge
  15. }) => {
  16. const [isCharging, setCharging] = useState(false);
  17. const [loadingEmps, setEmps] = useState("");
  18. const [skipAnim, setAnimSkip] = useState(false);
  19. const topAnim = useRef(new Animated.Value($vw(16)*-2)).current;
  20. const fadeAnim = useRef(new Animated.Value(0)).current;
  21. const moveTop = () => {
  22. fadeAnim.setValue(0);
  23. Animated.timing(topAnim, {
  24. toValue: ($vh(50) * -1 - $vw(16) - 32),
  25. duration: 1000,
  26. easing: Easing.linear,
  27. useNativeDriver: false
  28. }).start();
  29. setTimeout(() => {
  30. setCharging(true);
  31. showFade();
  32. }, 1100);
  33. }
  34. const showFade = () => {
  35. Animated.timing(fadeAnim, {
  36. toValue: 1,
  37. duration: 1000,
  38. useNativeDriver: false
  39. }).start();
  40. setTimeout(() => {
  41. setAnimSkip(true);
  42. }, 1100);
  43. }
  44. useEffect(() => {
  45. const isCharge = (connectorInfo.status == "Charging");
  46. console.log("[useEffect]:start", isCharge, fadeAnim);
  47. setCharging(isCharge);
  48. setAnimSkip(isCharge);
  49. if (!isCharge) {
  50. changeEmps();
  51. }
  52. }, [])
  53. useEffect(() => {
  54. //console.log("[useEffect]:connectorInfo", connectorInfo.status);
  55. if (connectorInfo.status == "Charging") {
  56. if (!isCharging) {
  57. moveTop();
  58. }
  59. } else {
  60. setCharging(false)
  61. }
  62. }, [connectorInfo])
  63. useEffect(() => {
  64. //console.log("[useEffect]:loadingEmps", loadingEmps);
  65. if (connectorInfo.status == "Charging") {
  66. moveTop();
  67. } else {
  68. setTimeout(() => {
  69. changeEmps();
  70. }, 500);
  71. }
  72. }, [loadingEmps])
  73. const changeEmps = () => {
  74. let emp = loadingEmps;
  75. if (loadingEmps.length == 3) {
  76. emp = "";
  77. } else {
  78. emp += ".";
  79. }
  80. setEmps(emp);
  81. }
  82. return (
  83. isCharging
  84. ? <ScrollView
  85. style={ui.flex1}
  86. contentContainerStyle={$padding(16)}>
  87. <Animated.View style={{opacity: skipAnim ? 1 : fadeAnim}}>
  88. <View style={ui.center}>
  89. <Image
  90. style={styles.stepImage}
  91. resizeMode="contain"
  92. source={require('../../images/site/charging-status-charge.png')}/>
  93. <Text style={styles.stepTitle}>{$t('charging.statusCharging')}</Text>
  94. <Text style={styles.stepDesc}>{$t('charging.stepChargingDesc')}</Text>
  95. { connectorInfo.batteryPercent >= 0 &&
  96. <Text
  97. style={styles.socText}
  98. numberOfLines={1}>{connectorInfo.batteryPercent || "0"}%</Text>
  99. }
  100. </View>
  101. <View style={styles.infoRow}>
  102. <View style={skipAnim ? styles.infoCarded : styles.infoCard}>
  103. <Text style={styles.infoTitle}>{$t('charging.labelTimeElapsed')}</Text>
  104. <Text
  105. numberOfLines={1}
  106. ellipsizeMode="tail"
  107. style={styles.infoText}>{utils.minutes2HHMM(connectorInfo?.timeElapsed ?? 0)}</Text>
  108. <Text style={styles.infoDesc}></Text>
  109. </View>
  110. <View style={skipAnim ? styles.infoCarded : styles.infoCard}>
  111. <Text style={styles.infoTitle}>{$t('charging.labelTotalkWh')}</Text>
  112. <Text
  113. numberOfLines={1}
  114. ellipsizeMode="tail"
  115. style={styles.infoText}>{connectorInfo.totalKWhDelivered || "0"} kWh</Text>
  116. <Text style={styles.infoDesc}></Text>
  117. </View>
  118. </View>
  119. <View style={styles.infoRow}>
  120. <View style={skipAnim ? styles.infoCarded : styles.infoCard}>
  121. <Text style={styles.infoTitle}>{$t('charging.labelRate')}</Text>
  122. <Text
  123. numberOfLines={2}
  124. ellipsizeMode="tail"
  125. style={styles.infoText}>{connectorInfo.rates || "S$0.00/kWh"}</Text>
  126. <Text
  127. numberOfLines={1}
  128. ellipsizeMode="tail"
  129. style={styles.infoDesc}>({connectorInfo.userRates || "S$0.00/kWh"})</Text>
  130. </View>
  131. <View style={skipAnim ? styles.infoCarded : styles.infoCard}>
  132. <Text style={styles.infoTitle}>{$t('charging.labelTotalCharges')}</Text>
  133. <Text
  134. numberOfLines={2}
  135. ellipsizeMode="tail"
  136. style={styles.infoText}>{connectorInfo.totalCharges || "S$ 0.0"}</Text>
  137. <Text
  138. numberOfLines={1}
  139. ellipsizeMode="tail"
  140. style={styles.infoDesc}>({connectorInfo.userTotalCharges || "S$ 0.0"})</Text>
  141. </View>
  142. </View>
  143. </Animated.View>
  144. <EndView/>
  145. <Text style={styles.label}>{$t('charging.paymentMethod')}</Text>
  146. <PaymentList
  147. payType={currentPayment}
  148. payPerUse={curerntPerUse}
  149. />
  150. <Button
  151. style={styles.buttonView}
  152. text={$t('charging.btnStopCharging')}
  153. elevation={1.5}
  154. borderRadius={6}
  155. onClick={onStopCharge}/>
  156. </ScrollView>
  157. : <View style={ui.flex1}>
  158. <Animated.View style={[
  159. styles.content, {
  160. marginTop: topAnim
  161. }
  162. ]}>
  163. <Image
  164. style={styles.stepImage}
  165. resizeMode="contain"
  166. source={require('../../images/site/charging-status-ready.png')}/>
  167. <View style={ui.flexcc}>
  168. <Text style={styles.stepTitle}>{$t('charging.stepInitializing')}</Text>
  169. <Text style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</Text>
  170. </View>
  171. <Text style={styles.stepDesc}>{$t('charging.stepInitializingDesc')}</Text>
  172. </Animated.View>
  173. <View style={styles.bottomView}>
  174. <Text style={styles.label}>{$t('charging.paymentMethod')}</Text>
  175. <PaymentList
  176. payType={currentPayment}
  177. payPerUse={curerntPerUse}
  178. />
  179. <View style={styles.buttonView}></View>
  180. </View>
  181. </View>
  182. );
  183. }
  184. export default StepCharging;
  185. const styles = StyleSheet.create({
  186. content: {
  187. flex: 1,
  188. alignItems: 'center',
  189. justifyContent: 'center'
  190. },
  191. stepImage: {
  192. width: $vw(70),
  193. height: $vw(16),
  194. margin: 16
  195. },
  196. stepTitle: {
  197. fontSize: 24,
  198. fontWeight: 'bold',
  199. color: colorAccent
  200. },
  201. stepDesc: {
  202. color: textPrimary,
  203. fontSize: 16,
  204. textAlign: 'center',
  205. ...$padding(0, 32, 48)
  206. },
  207. socText: {
  208. right: $vw(15),
  209. color: colorAccent,
  210. width: 60,
  211. marginRight: -8,
  212. fontSize: 24,
  213. fontWeight: 'bold',
  214. position: 'absolute',
  215. textAlign: 'center',
  216. },
  217. infoRow: {
  218. marginLeft: 16,
  219. marginBottom: 16,
  220. flexDirection: 'row'
  221. },
  222. infoCard: {
  223. flex: 1,
  224. paddingTop: 12,
  225. paddingBottom: 12,
  226. borderRadius: 10,
  227. marginRight: 16,
  228. alignItems: 'center',
  229. //...ElevationObject(5),
  230. backgroundColor: colorLight
  231. },
  232. infoCarded: {
  233. flex: 1,
  234. paddingTop: 12,
  235. paddingBottom: 12,
  236. borderRadius: 10,
  237. marginRight: 16,
  238. alignItems: 'center',
  239. ...ElevationObject(5),
  240. backgroundColor: colorLight
  241. },
  242. infoTitle: {
  243. color: textPrimary,
  244. fontSize: 12
  245. },
  246. infoText: {
  247. color: textPrimary,
  248. fontSize: 15,
  249. fontWeight: 'bold',
  250. textAlign: 'center',
  251. ...$padding(12, 6)
  252. },
  253. infoDesc: {
  254. color: textPrimary,
  255. fontSize: 12,
  256. marginTop: -12,
  257. paddingBottom: 8
  258. },
  259. infoStatus: {
  260. fontSize: 16,
  261. fontWeight: 'bold',
  262. ...$padding(16, 8)
  263. },label: {
  264. color: '#000',
  265. fontSize: 14,
  266. fontWeight: 'bold',
  267. paddingTop: 16,
  268. paddingBottom: 8
  269. },
  270. bottomView: {
  271. left: 0,
  272. right: 0,
  273. bottom: 32,
  274. padding: 16,
  275. position: 'absolute'
  276. },
  277. buttonView: {
  278. marginTop: 16,
  279. marginBottom: 16
  280. }
  281. })