StepAuth.js 6.1 KB

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