StepCharging.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. style={styles.infoText}>{connectorInfo.rates || "S$0.00/kWh"}</Text>
  124. <Text
  125. style={styles.infoDesc}>({connectorInfo.userRates || "S$0.00/kWh"})</Text>
  126. </View>
  127. <View style={skipAnim ? styles.infoCarded : styles.infoCard}>
  128. <Text style={styles.infoTitle}>{$t('charging.labelTotalCharges')}</Text>
  129. <Text
  130. numberOfLines={1}
  131. ellipsizeMode="tail"
  132. style={styles.infoText}>{connectorInfo.totalCharges || "S$ 0.0"}</Text>
  133. <Text
  134. numberOfLines={1}
  135. ellipsizeMode="tail"
  136. style={styles.infoDesc}>({connectorInfo.userTotalCharges || "S$ 0.0"})</Text>
  137. </View>
  138. </View>
  139. </Animated.View>
  140. <EndView/>
  141. <Text style={styles.label}>{$t('charging.paymentMethod')}</Text>
  142. <PaymentList
  143. payType={currentPayment}
  144. payPerUse={curerntPerUse}
  145. />
  146. <Button
  147. style={styles.buttonView}
  148. text={$t('charging.btnStopCharging')}
  149. elevation={1.5}
  150. borderRadius={6}
  151. onClick={onStopCharge}/>
  152. </ScrollView>
  153. : <View style={ui.flex1}>
  154. <Animated.View style={[
  155. styles.content, {
  156. marginTop: topAnim
  157. }
  158. ]}>
  159. <Image
  160. style={styles.stepImage}
  161. resizeMode="contain"
  162. source={require('../../images/site/charging-status-ready.png')}/>
  163. <View style={ui.flexcc}>
  164. <Text style={styles.stepTitle}>{$t('charging.stepInitializing')}</Text>
  165. <Text style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</Text>
  166. </View>
  167. <Text style={styles.stepDesc}>{$t('charging.stepInitializingDesc')}</Text>
  168. </Animated.View>
  169. <View style={styles.bottomView}>
  170. <Text style={styles.label}>{$t('charging.paymentMethod')}</Text>
  171. <PaymentList
  172. payType={currentPayment}
  173. payPerUse={curerntPerUse}
  174. />
  175. <View style={styles.buttonView}></View>
  176. </View>
  177. </View>
  178. );
  179. }
  180. export default StepCharging;
  181. const styles = StyleSheet.create({
  182. content: {
  183. flex: 1,
  184. alignItems: 'center',
  185. justifyContent: 'center'
  186. },
  187. stepImage: {
  188. width: $vw(70),
  189. height: $vw(16),
  190. margin: 16
  191. },
  192. stepTitle: {
  193. fontSize: 24,
  194. fontWeight: 'bold',
  195. color: colorAccent
  196. },
  197. stepDesc: {
  198. color: textPrimary,
  199. fontSize: 16,
  200. textAlign: 'center',
  201. ...$padding(0, 32, 48)
  202. },
  203. socText: {
  204. right: $vw(15),
  205. color: colorAccent,
  206. width: 60,
  207. marginRight: -8,
  208. fontSize: 24,
  209. fontWeight: 'bold',
  210. position: 'absolute',
  211. textAlign: 'center',
  212. },
  213. infoRow: {
  214. marginLeft: 16,
  215. marginBottom: 16,
  216. flexDirection: 'row'
  217. },
  218. infoCard: {
  219. flex: 1,
  220. padding: 12,
  221. borderRadius: 10,
  222. marginRight: 16,
  223. alignItems: 'center',
  224. //...ElevationObject(5),
  225. backgroundColor: colorLight
  226. },
  227. infoCarded: {
  228. flex: 1,
  229. padding: 12,
  230. borderRadius: 10,
  231. marginRight: 16,
  232. alignItems: 'center',
  233. ...ElevationObject(5),
  234. backgroundColor: colorLight
  235. },
  236. infoTitle: {
  237. color: textPrimary,
  238. fontSize: 12,
  239. paddingTop: 1
  240. },
  241. infoText: {
  242. color: textPrimary,
  243. fontSize: 16,
  244. fontWeight: 'bold',
  245. ...$padding(16)
  246. },
  247. infoDesc: {
  248. color: textPrimary,
  249. fontSize: 12,
  250. marginTop: -16,
  251. paddingBottom: 8
  252. },
  253. infoStatus: {
  254. fontSize: 16,
  255. fontWeight: 'bold',
  256. ...$padding(16, 8)
  257. },label: {
  258. color: '#000',
  259. fontSize: 14,
  260. fontWeight: 'bold',
  261. paddingTop: 16,
  262. paddingBottom: 8
  263. },
  264. bottomView: {
  265. left: 0,
  266. right: 0,
  267. bottom: 32,
  268. padding: 16,
  269. position: 'absolute'
  270. },
  271. buttonView: {
  272. marginTop: 16,
  273. marginBottom: 16
  274. }
  275. })