StepCharging.js 8.0 KB

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