StepCharging.js 11 KB

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