StepCharging.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. import PaymentListV2 from '../chargeV2/PaymentListV2';
  14. const StepCharging = ({
  15. connectorInfo={},
  16. currentPayment,
  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. { app.v3.paymentMethod
  155. ? <PaymentListV2
  156. isSelect={false}
  157. payType={currentPayment}/>
  158. : <PaymentList
  159. isSelect={false}
  160. payType={currentPayment}/>
  161. }
  162. <Button
  163. style={styles.buttonView}
  164. text={$t('charging.btnStopCharging')}
  165. elevation={1.5}
  166. borderRadius={6}
  167. onClick={onStopCharge}/>
  168. </ScrollView>
  169. : <View style={ui.flex1}>
  170. <Animated.View style={[
  171. styles.content, {
  172. marginTop: topAnim
  173. }
  174. ]}>
  175. <Image
  176. style={styles.stepImage}
  177. resizeMode="contain"
  178. source={require('../../images/site/charging-status-ready.png')}/>
  179. <View style={ui.flexcc}>
  180. <TextView style={styles.stepTitle}>{$t('charging.stepInitializing')}</TextView>
  181. <TextView style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</TextView>
  182. </View>
  183. <TextView style={styles.stepDesc}>{$t('charging.stepInitializingDesc')}</TextView>
  184. </Animated.View>
  185. <View style={styles.bottomView}>
  186. <TextView style={styles.label}>{$t('charging.paymentMethod')}</TextView>
  187. { app.v3.paymentMethod
  188. ? <PaymentListV2
  189. isSelect={false}
  190. payType={currentPayment}/>
  191. : <PaymentList
  192. isSelect={false}
  193. payType={currentPayment}/>
  194. }
  195. <View style={styles.buttonView}></View>
  196. </View>
  197. </View>
  198. );
  199. }
  200. export default StepCharging;
  201. const styles = StyleSheet.create({
  202. content: {
  203. flex: 1,
  204. alignItems: 'center',
  205. justifyContent: 'center'
  206. },
  207. stepImage: {
  208. width: $vw(70),
  209. height: $vw(16),
  210. margin: 16
  211. },
  212. stepTitle: {
  213. fontSize: 24,
  214. fontWeight: 'bold',
  215. color: colorAccent
  216. },
  217. stepDesc: {
  218. color: textPrimary,
  219. fontSize: 16,
  220. textAlign: 'center',
  221. ...$padding(0, 32, 48)
  222. },
  223. socText: {
  224. right: $vw(15),
  225. color: colorAccent,
  226. width: 60,
  227. marginRight: -8,
  228. fontSize: 24,
  229. fontWeight: 'bold',
  230. position: 'absolute',
  231. textAlign: 'center',
  232. },
  233. infoRow: {
  234. marginLeft: 16,
  235. marginBottom: 16,
  236. flexDirection: 'row'
  237. },
  238. infoCard: {
  239. flex: 1,
  240. paddingTop: 12,
  241. paddingBottom: 12,
  242. borderRadius: 10,
  243. marginRight: 16,
  244. overflow: 'hidden',
  245. alignItems: 'center',
  246. //...ElevationObject(5),
  247. backgroundColor: colorLight
  248. },
  249. infoCarded: {
  250. flex: 1,
  251. paddingTop: 12,
  252. paddingBottom: 12,
  253. borderRadius: 10,
  254. marginRight: 16,
  255. overflow: 'hidden',
  256. alignItems: 'center',
  257. ...ElevationObject(5),
  258. backgroundColor: colorLight
  259. },
  260. infoTitle: {
  261. color: textPrimary,
  262. fontSize: 12
  263. },
  264. infoText: {
  265. color: textPrimary,
  266. fontSize: 15,
  267. fontWeight: 'bold',
  268. textAlign: 'center',
  269. ...$padding(12, 6)
  270. },
  271. infoDesc: {
  272. color: textPrimary,
  273. fontSize: 12,
  274. marginTop: -12,
  275. paddingBottom: 8
  276. },
  277. infoStatus: {
  278. fontSize: 16,
  279. fontWeight: 'bold',
  280. ...$padding(16, 8)
  281. },label: {
  282. color: '#000',
  283. fontSize: 14,
  284. fontWeight: 'bold',
  285. paddingTop: 16,
  286. paddingBottom: 8
  287. },
  288. bottomView: {
  289. left: 0,
  290. right: 0,
  291. bottom: 32,
  292. padding: 16,
  293. position: 'absolute'
  294. },
  295. buttonView: {
  296. marginTop: 16,
  297. marginBottom: 16
  298. }
  299. })