StepCharging.js 8.4 KB

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