StepCharging.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /**
  2. * 新充电流程:正在充电模块
  3. * @邠心vbe on 2023/06/20
  4. */
  5. import React, { useEffect, useState } from 'react';
  6. import { 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 PaymentListV2 from '../chargeV2/PaymentListV2';
  13. import StatusImage from './StatusImage';
  14. import ConnectorInfo from './ConnectorInfo';
  15. const StepCharging = ({
  16. connectorInfo={},
  17. currentPayment,
  18. onStopCharge,
  19. selectedVoucher={}
  20. }) => {
  21. const [isCharging, setCharging] = useState(false);
  22. const [loadingEmps, setEmps] = useState("");
  23. useEffect(() => {
  24. const isCharge = (connectorInfo.status == "Charging");
  25. setCharging(isCharge);
  26. if (!isCharge) {
  27. changeEmps();
  28. }
  29. }, [])
  30. useEffect(() => {
  31. const isCharge = (connectorInfo.status == "Charging");
  32. setCharging(isCharge);
  33. if (!isCharge) {
  34. setTimeout(() => {
  35. changeEmps();
  36. }, 500);
  37. }
  38. }, [connectorInfo,loadingEmps])
  39. const changeEmps = () => {
  40. let emp = loadingEmps;
  41. if (loadingEmps.length == 3) {
  42. emp = "";
  43. } else {
  44. emp += ".";
  45. }
  46. setEmps(emp);
  47. }
  48. return (
  49. isCharging
  50. ? <View style={ui.flex1}>
  51. <ScrollView
  52. style={ui.flex1}
  53. contentContainerStyle={$padding(16)}>
  54. <View style={ui.center}>
  55. <StatusImage
  56. isCharging={true}
  57. isLoading={true}
  58. soc={connectorInfo.batteryPercent}/>
  59. <TextView style={styles.stepTitle}>{$t('charging.statusCharging')}</TextView>
  60. <TextView style={styles.stepDesc}>{$t('charging.stepChargingDesc')}</TextView>
  61. </View>
  62. <ConnectorInfo
  63. isCharging={true}
  64. connectorInfo={connectorInfo}/>
  65. <View style={styles.bottomSelectView}>
  66. <TextView style={styles.label}>{$t('charging.paymentMethod')}</TextView>
  67. { app.charge.paymentMethod
  68. ? <PaymentListV2
  69. isSelect={false}
  70. payType={currentPayment}
  71. borderColor={textCancel}
  72. style={styles.paymentView}/>
  73. : <PaymentList
  74. isSelect={false}
  75. payType={currentPayment}/>
  76. }
  77. { utils.isNotEmpty(selectedVoucher.userVoucherId) && <>
  78. <TextView style={styles.label}>{$t('voucher.vouchers')}</TextView>
  79. <View
  80. style={styles.paymentView}>
  81. <MaterialCommunityIcons
  82. name="ticket-percent-outline"
  83. size={32}
  84. color={textPrimary}/>
  85. <View style={styles.vouchersView}>
  86. <TextView
  87. style={styles.voucherName}
  88. numberOfLines={1}>
  89. {selectedVoucher.voucherName}
  90. </TextView>
  91. <TextView
  92. style={styles.voucherDesc}
  93. numberOfLines={1}>
  94. {selectedVoucher.voucherDesc}
  95. </TextView>
  96. </View>
  97. </View>
  98. </> }
  99. <View style={{height: 56}}></View>
  100. </View>
  101. </ScrollView>
  102. <Button
  103. style={styles.buttonView}
  104. text={$t('charging.btnStopCharging')}
  105. elevation={1.5}
  106. borderRadius={6}
  107. onClick={onStopCharge}/>
  108. </View>
  109. : <View style={ui.flex1}>
  110. <View style={styles.content}>
  111. <StatusImage
  112. isInitial={true}
  113. isLoading={true}/>
  114. <View style={ui.flexcc}>
  115. <TextView style={styles.stepTitle}>{$t('charging.stepInitializing')}</TextView>
  116. <TextView style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</TextView>
  117. </View>
  118. <TextView style={styles.stepDesc}>{$t('charging.stepInitializingDesc')}</TextView>
  119. </View>
  120. {/* <View style={styles.bottomView}>
  121. <TextView style={styles.label}>{$t('charging.paymentMethod')}</TextView>
  122. { app.charge.paymentMethod
  123. ? <PaymentListV2
  124. isSelect={false}
  125. payType={currentPayment}/>
  126. : <PaymentList
  127. isSelect={false}
  128. payType={currentPayment}/>
  129. }
  130. <View style={styles.buttonView}></View>
  131. </View> */}
  132. </View>
  133. );
  134. }
  135. export default StepCharging;
  136. const styles = StyleSheet.create({
  137. content: {
  138. flex: 1,
  139. padding: 16,
  140. alignItems: 'center'
  141. },
  142. stepTitle: {
  143. fontSize: 24,
  144. fontWeight: 'bold',
  145. color: colorAccent
  146. },
  147. stepDesc: {
  148. color: textPrimary,
  149. fontSize: 16,
  150. textAlign: 'center',
  151. ...$padding(0, 32, 32)
  152. },
  153. infoCarded: {
  154. flex: 1,
  155. paddingTop: 12,
  156. paddingBottom: 12,
  157. borderRadius: 10,
  158. marginRight: 16,
  159. overflow: 'hidden',
  160. alignItems: 'center',
  161. ...ElevationObject(5),
  162. backgroundColor: colorLight
  163. },
  164. label: {
  165. color: '#000',
  166. fontSize: 14,
  167. fontWeight: 'bold',
  168. paddingTop: 16,
  169. paddingBottom: 8
  170. },
  171. bottomSelectView: {
  172. paddingLeft: 16,
  173. paddingRight: 16,
  174. paddingBottom: 16
  175. },
  176. bottomView: {
  177. left: 0,
  178. right: 0,
  179. bottom: 32,
  180. padding: 16,
  181. position: 'absolute'
  182. },
  183. paymentView: {
  184. ...$padding(10, 12),
  185. borderWidth: 1,
  186. borderRadius: 10,
  187. borderColor: textCancel,
  188. marginBottom: 12,
  189. alignItems: 'center',
  190. flexDirection: 'row',
  191. backgroundColor: colorLight,
  192. justifyContent: 'space-between'
  193. },
  194. buttonView: {
  195. left: 16,
  196. right: 16,
  197. bottom: 24,
  198. position: 'absolute'
  199. },
  200. vouchersView: {
  201. flex: 1,
  202. paddingLeft: 8,
  203. alignItems: 'center',
  204. flexDirection: 'row',
  205. justifyContent: 'space-around'
  206. },
  207. selectText: {
  208. flex: 1,
  209. color: textSecondary,
  210. fontSize: 15,
  211. fontWeight: 'bold'
  212. },
  213. voucherName: {
  214. flex: 1,
  215. color: textPrimary,
  216. fontSize: 15,
  217. paddingLeft: 8,
  218. fontWeight: 'bold'
  219. },
  220. voucherDesc: {
  221. flex: 1,
  222. color: textSecondary,
  223. fontSize: 12,
  224. paddingLeft: 8,
  225. paddingRight: 16
  226. }
  227. })