StepAuth.js 2.9 KB

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