StepCharging.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. chargeBoxId={connectorInfo.chargeBoxId}
  73. style={styles.paymentView}/>
  74. : <PaymentList
  75. isSelect={false}
  76. payType={currentPayment}/>
  77. }
  78. { utils.isNotEmpty(selectedVoucher.userVoucherId) && <>
  79. <TextView style={styles.label}>{$t('voucher.vouchers')}</TextView>
  80. <View
  81. style={styles.paymentView}>
  82. <MaterialCommunityIcons
  83. name="ticket-percent-outline"
  84. size={32}
  85. color={textPrimary}/>
  86. <View style={styles.vouchersView}>
  87. <TextView
  88. style={styles.voucherName}
  89. numberOfLines={1}>
  90. {selectedVoucher.voucherName}
  91. </TextView>
  92. <TextView
  93. style={styles.voucherDesc}
  94. numberOfLines={1}>
  95. {selectedVoucher.voucherDesc}
  96. </TextView>
  97. </View>
  98. </View>
  99. </> }
  100. <View style={{height: 56}}></View>
  101. </View>
  102. </ScrollView>
  103. <Button
  104. style={styles.buttonView}
  105. text={$t('charging.btnStopCharging')}
  106. elevation={1.5}
  107. borderRadius={6}
  108. onClick={onStopCharge}/>
  109. </View>
  110. : <View style={ui.flex1}>
  111. <View style={styles.content}>
  112. <StatusImage
  113. isInitial={true}
  114. isLoading={true}/>
  115. <View style={ui.flexcc}>
  116. <TextView style={styles.stepTitle}>{$t('charging.stepInitializing')}</TextView>
  117. <TextView style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</TextView>
  118. </View>
  119. <TextView style={styles.stepDesc}>{$t('charging.stepInitializingDesc')}</TextView>
  120. </View>
  121. {/* <View style={styles.bottomView}>
  122. <TextView style={styles.label}>{$t('charging.paymentMethod')}</TextView>
  123. { app.charge.paymentMethod
  124. ? <PaymentListV2
  125. isSelect={false}
  126. payType={currentPayment}/>
  127. : <PaymentList
  128. isSelect={false}
  129. payType={currentPayment}/>
  130. }
  131. <View style={styles.buttonView}></View>
  132. </View> */}
  133. </View>
  134. );
  135. }
  136. export default StepCharging;
  137. const styles = StyleSheet.create({
  138. content: {
  139. flex: 1,
  140. padding: 16,
  141. alignItems: 'center'
  142. },
  143. stepTitle: {
  144. fontSize: 24,
  145. fontWeight: 'bold',
  146. color: colorAccent
  147. },
  148. stepDesc: {
  149. color: textPrimary,
  150. fontSize: 16,
  151. textAlign: 'center',
  152. ...$padding(0, 32, 32)
  153. },
  154. infoCarded: {
  155. flex: 1,
  156. paddingTop: 12,
  157. paddingBottom: 12,
  158. borderRadius: 10,
  159. marginRight: 16,
  160. overflow: 'hidden',
  161. alignItems: 'center',
  162. ...ElevationObject(5),
  163. backgroundColor: colorLight
  164. },
  165. label: {
  166. color: '#000',
  167. fontSize: 14,
  168. fontWeight: 'bold',
  169. paddingTop: 16,
  170. paddingBottom: 8
  171. },
  172. bottomSelectView: {
  173. paddingLeft: 16,
  174. paddingRight: 16,
  175. paddingBottom: 16
  176. },
  177. bottomView: {
  178. left: 0,
  179. right: 0,
  180. bottom: 32,
  181. padding: 16,
  182. position: 'absolute'
  183. },
  184. paymentView: {
  185. ...$padding(10, 12),
  186. borderWidth: 1,
  187. borderRadius: 10,
  188. borderColor: textCancel,
  189. marginBottom: 12,
  190. alignItems: 'center',
  191. flexDirection: 'row',
  192. backgroundColor: colorLight,
  193. justifyContent: 'space-between'
  194. },
  195. buttonView: {
  196. left: 16,
  197. right: 16,
  198. bottom: 24,
  199. position: 'absolute'
  200. },
  201. vouchersView: {
  202. flex: 1,
  203. paddingLeft: 8,
  204. alignItems: 'center',
  205. flexDirection: 'row',
  206. justifyContent: 'space-around'
  207. },
  208. selectText: {
  209. flex: 1,
  210. color: textSecondary,
  211. fontSize: 15,
  212. fontWeight: 'bold'
  213. },
  214. voucherName: {
  215. flex: 1,
  216. color: textPrimary,
  217. fontSize: 15,
  218. paddingLeft: 8,
  219. fontWeight: 'bold'
  220. },
  221. voucherDesc: {
  222. flex: 1,
  223. color: textSecondary,
  224. fontSize: 12,
  225. paddingLeft: 8,
  226. paddingRight: 16
  227. }
  228. })