StepAuth.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * 新充电流程:验证插头模块
  3. * @邠心vbe on 2023/06/20
  4. */
  5. import React, { useEffect, useState } from 'react';
  6. import { View, Text, Image, StyleSheet } from 'react-native';
  7. import Button from '../../components/Button';
  8. import TextView from '../../components/TextView';
  9. import { PaymentList } from '../chargeV2/Payment';
  10. export default StepAuth = ({
  11. status="",
  12. currentPayment,
  13. onStartCharge,
  14. onPaymentMethodChanged
  15. }) => {
  16. const [loadingEmps, setEmps] = useState("");
  17. const [isAuthentic, setAuthentic] = useState(false)
  18. useEffect(() => {
  19. if (status == "Preparing") {
  20. setAuthentic(true);
  21. } else {
  22. changeEmps();
  23. }
  24. }, []);
  25. useEffect(() => {
  26. if (status == "Preparing") {
  27. setAuthentic(true);
  28. } else {
  29. setTimeout(() => {
  30. changeEmps();
  31. }, 500);
  32. }
  33. }, [loadingEmps, status]);
  34. const changeEmps = () => {
  35. let emp = loadingEmps;
  36. if (loadingEmps.length == 3) {
  37. emp = "";
  38. } else {
  39. emp += ".";
  40. }
  41. setEmps(emp);
  42. }
  43. return (
  44. <View style={styles.container}>
  45. <View style={styles.content}>
  46. <Image
  47. style={styles.stepImage}
  48. resizeMode="contain"
  49. source={
  50. isAuthentic
  51. ? require('../../images/site/charging-status-auth.png')
  52. : require('../../images/site/charging-status-ready.png')
  53. }/>
  54. { isAuthentic
  55. ? <TextView style={styles.stepTitle}>{$t('charging.stepAuthenticated')}</TextView>
  56. : <View style={ui.flexcc}>
  57. <TextView style={styles.stepTitle}>{$t('charging.stepAuthenticating')}</TextView>
  58. <TextView style={[styles.stepTitle, {width: 30, marginRight: -10}]}>{loadingEmps}</TextView>
  59. </View>
  60. }
  61. <TextView style={styles.stepDesc}>{$t(isAuthentic ? 'charging.stepAuthenticatedDesc' : 'charging.stepAuthenticatingDesc')}</TextView>
  62. </View>
  63. <View style={styles.bottomView}>
  64. <TextView style={styles.label}>{$t('charging.paymentMethod')}</TextView>
  65. <PaymentList
  66. payType={currentPayment}
  67. onMethodChange={onPaymentMethodChanged}
  68. />
  69. { isAuthentic
  70. ? <Button
  71. style={styles.buttonView}
  72. text={$t('charging.btnStartCharging')}
  73. elevation={1.5}
  74. borderRadius={6}
  75. onClick={onStartCharge}/>
  76. : <View style={{height: 56}}/>
  77. }
  78. </View>
  79. </View>
  80. );
  81. }
  82. const styles = StyleSheet.create({
  83. container: {
  84. flex: 1,
  85. padding: 16
  86. },
  87. content: {
  88. flex: 1,
  89. alignItems: 'center',
  90. justifyContent: 'center'
  91. },
  92. stepImage: {
  93. width: $vw(70),
  94. height: $vw(16),
  95. margin: 16
  96. },
  97. stepTitle: {
  98. fontSize: 24,
  99. fontWeight: 'bold',
  100. color: colorAccent
  101. },
  102. stepDesc: {
  103. color: textPrimary,
  104. fontSize: 16,
  105. textAlign: 'center',
  106. ...$padding(0, 32, 48)
  107. },
  108. label: {
  109. color: '#000',
  110. fontSize: 14,
  111. fontWeight: 'bold',
  112. paddingTop: 16,
  113. paddingBottom: 8
  114. },
  115. bottomView: {
  116. paddingBottom: 16
  117. },
  118. buttonView: {
  119. marginTop: 8
  120. }
  121. })