StepCharging.js 8.2 KB

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