StepAuth.js 5.9 KB

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