futureReservationPageComponent.tsx 7.4 KB

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