futureReservationPageComponent.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { View, Text, ScrollView, StyleSheet, ActivityIndicator } from 'react-native';
  2. import { useEffect, useState } from 'react';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import NormalButton from '../global/normal_button';
  5. import { router } from 'expo-router';
  6. import { convertToHKTime } from '../../util/lib';
  7. const FutureReservationPageComponent = ({ data }) => {
  8. const [loading, setLoading] = useState(false);
  9. const [stationInfo, setStationInfo] = useState(null);
  10. const plan = data.book_time === data.end_time ? '充滿停機' : '按每度電結算';
  11. const kwh = data.total_power === null ? '' : `${data.total_power} kWh`;
  12. ///如果充電停機 應該show 充電停機 not 80 kWh
  13. ///如果充電停機 應該show 充電停機 not 80 kWh
  14. ///如果充電停機 應該show 充電停機 not 80 kWh
  15. ///如果充電停機 應該show 充電停機 not 80 kWh
  16. ///如果充電停機 應該show 充電停機 not 80 kWh
  17. ///如果充電停機 應該show 充電停機 not 80 kWh
  18. ///如果充電停機 應該show 充電停機 not 80 kWh
  19. ///如果充電停機 應該show 充電停機 not 80 kWh
  20. ///如果充電停機 應該show 充電停機 not 80 kWh
  21. ///如果充電停機 應該show 充電停機 not 80 kWh
  22. ///如果充電停機 應該show 充電停機 not 80 kWh
  23. ///如果充電停機 應該show 充電停機 not 80 kWh
  24. ///如果充電停機 應該show 充電停機 not 80 kWh
  25. ///如果充電停機 應該show 充電停機 not 80 kWh
  26. useEffect(() => {
  27. if (data && data.connector && data.connector.EquipmentID && data.connector.EquipmentID.StationID) {
  28. try {
  29. const parsedSnapshot = JSON.parse(data.connector.EquipmentID.StationID.snapshot);
  30. setStationInfo(parsedSnapshot);
  31. } catch (error) {
  32. console.error('Error parsing station snapshot:', error);
  33. }
  34. }
  35. }, [data]);
  36. return (
  37. <SafeAreaView edges={['top', 'left', 'right']} className="flex-1 bg-white">
  38. <ScrollView className="flex-1 mt-8 " nestedScrollEnabled={true} showsVerticalScrollIndicator={false}>
  39. <View className="mx-[5%]">
  40. <View className="">
  41. <Text className="text-5xl pt-1 pb-6">暫無充電車輛</Text>
  42. {loading ? (
  43. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  44. <ActivityIndicator color="#34657b" />
  45. </View>
  46. ) : (
  47. <>
  48. <Text className="text-2xl pb-2 ">你的下一次預約為:</Text>
  49. <View className="border-gray-200 border rounded-md">
  50. <View className="flex-1 mt-4 mx-[5%] ">
  51. <View className="flex-1 flex-row items-center pb-3">
  52. <View className="flex-1 flex-column">
  53. <Text style={styles.grayColor} className="text-base">
  54. 日期
  55. </Text>
  56. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  57. {convertToHKTime(data.book_time)
  58. .hkDate.split('/')
  59. .reverse()
  60. .slice(1)
  61. .join('月')}
  62. </Text>
  63. </View>
  64. <View className="flex-1 flex-column">
  65. <Text style={styles.grayColor} className="text-base pl-7">
  66. 時間
  67. </Text>
  68. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  69. {convertToHKTime(data.book_time).hkTime.slice(0, 5)}
  70. </Text>
  71. </View>
  72. </View>
  73. <View className="flex-1 flex-column justify-center space-y-1 pb-3">
  74. <Text style={styles.grayColor} className="text-base">
  75. 充電地點
  76. </Text>
  77. <Text style={styles.greenColor} className="text-2xl ">
  78. {stationInfo?.StationName || 'N/A'}
  79. </Text>
  80. <Text style={styles.grayColor} className="text-sm">
  81. {stationInfo?.Address || 'N/A'}
  82. </Text>
  83. </View>
  84. <View className="flex-1 flex-row pb-3 ">
  85. <View className="flex-column flex-1">
  86. <Text style={styles.grayColor} className="text-base">
  87. 方案
  88. </Text>
  89. <Text style={styles.greenColor} className="text-lg">
  90. {plan}
  91. </Text>
  92. <Text style={styles.grayColor} className="text-sm">
  93. {kwh}
  94. </Text>
  95. </View>
  96. {/* <View className="flex-column flex-1">
  97. <Text style={styles.grayColor} className="text-base">
  98. 車輛
  99. </Text>
  100. <Text style={styles.greenColor} className="text-lg">
  101. {data.car.car_brand.name}
  102. </Text>
  103. <Text style={styles.greenColor} className="text-lg">
  104. {data.car.car_type.name}
  105. </Text>
  106. </View> */}
  107. </View>
  108. </View>
  109. </View>
  110. <View className="pt-6">
  111. <NormalButton
  112. title={<Text className="text-white text-lg">返回主頁</Text>}
  113. onPress={() => router.push('mainPage')}
  114. />
  115. </View>
  116. </>
  117. )}
  118. </View>
  119. </View>
  120. </ScrollView>
  121. </SafeAreaView>
  122. );
  123. };
  124. const styles = StyleSheet.create({
  125. grayColor: {
  126. color: '#888888'
  127. },
  128. greenColor: {
  129. color: '#02677D'
  130. }
  131. });
  132. export default FutureReservationPageComponent;