StepAuth.js 5.9 KB

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