StepAuth.js 6.1 KB

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