StepCharging.js 8.4 KB

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