resultDetailPageComponent.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import {
  2. View,
  3. Text,
  4. ScrollView,
  5. Image,
  6. useWindowDimensions,
  7. StyleSheet,
  8. Pressable
  9. } from 'react-native';
  10. import React, { useEffect, useState } from 'react';
  11. import { SceneMap, TabBar, TabView } from 'react-native-tab-view';
  12. import NormalButton from '../global/normal_button';
  13. import { router, useLocalSearchParams } from 'expo-router';
  14. import {
  15. CheckMarkLogoSvg,
  16. DirectionLogoSvg,
  17. PreviousPageSvg
  18. } from '../global/SVG';
  19. import { SafeAreaView } from 'react-native-safe-area-context';
  20. import { chargeStationService } from '../../service/chargeStationService';
  21. interface ChargingStationTabViewProps {
  22. titles: string[];
  23. }
  24. const ChargingStationTabView: React.FC<ChargingStationTabViewProps> = ({
  25. titles
  26. }) => {
  27. const layout = useWindowDimensions();
  28. //tab 1
  29. const FirstRoute = () => (
  30. <ScrollView style={{ flex: 1, marginHorizontal: '5%' }}>
  31. <Text className="text-lg" style={styles.text}>
  32. 這是一段有關充電站的說明
  33. </Text>
  34. </ScrollView>
  35. );
  36. //tab 2
  37. const SecondRoute = () => (
  38. <ScrollView style={{ flex: 1, marginHorizontal: '5%' }}>
  39. <Text className="text-lg " style={styles.text}>
  40. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  41. eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
  42. enim ad minim veniam, quis nostrud exercitation ullamco laboris
  43. nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
  44. in reprehenderit in voluptate velit esse cillum dolore eu fugiat
  45. nulla pariatur. Excepteur sint occaecat cupidatat non proident
  46. </Text>
  47. </ScrollView>
  48. );
  49. const renderScene = SceneMap({
  50. firstRoute: FirstRoute,
  51. secondRoute: SecondRoute
  52. });
  53. const [routes] = React.useState([
  54. { key: 'firstRoute', title: titles[0] },
  55. { key: 'secondRoute', title: titles[1] }
  56. ]);
  57. const [index, setIndex] = React.useState(0);
  58. const renderTabBar = (props: any) => (
  59. <TabBar
  60. {...props}
  61. renderLabel={({ route, focused }) => (
  62. <Text
  63. style={{
  64. color: focused ? '#000000' : '#CCCCCC',
  65. fontWeight: focused ? '300' : 'thin',
  66. fontSize: 17
  67. }}
  68. >
  69. {route.title}
  70. </Text>
  71. )}
  72. indicatorStyle={{
  73. backgroundColor: '#000000',
  74. height: 1
  75. }}
  76. style={{
  77. backgroundColor: 'white',
  78. elevation: 0,
  79. marginHorizontal: 15,
  80. borderBottomWidth: 0.5
  81. }}
  82. />
  83. );
  84. return (
  85. <TabView
  86. navigationState={{ index, routes }}
  87. renderScene={renderScene}
  88. onIndexChange={setIndex}
  89. initialLayout={{ width: layout.width }}
  90. renderTabBar={renderTabBar}
  91. />
  92. );
  93. };
  94. const ResultDetailPageComponent = () => {
  95. const params = useLocalSearchParams();
  96. const chargeStationID = params.chargeStationID as string;
  97. const [price, setPrice] = useState('');
  98. useEffect(() => {
  99. const fetchPrice = async () => {
  100. try {
  101. const price =
  102. await chargeStationService.fetchChargeStationPrice(
  103. chargeStationID
  104. );
  105. setPrice(price);
  106. // Do something with the price, like setting it to state
  107. } catch (error) {
  108. console.error('Error fetching price:', error);
  109. }
  110. };
  111. fetchPrice();
  112. }, []);
  113. return (
  114. <SafeAreaView
  115. edges={['top', 'left', 'right']}
  116. className="flex-1 bg-white"
  117. >
  118. <ScrollView className="flex-1 ">
  119. <View className="relative">
  120. <Image
  121. source={require('../../assets/dummyStationPicture.png')}
  122. resizeMode="cover"
  123. style={{ flex: 1, width: '100%' }}
  124. />
  125. <View className="absolute top-8 left-7 ">
  126. <Pressable
  127. onPress={() => {
  128. if (router.canGoBack()) {
  129. router.back();
  130. } else {
  131. router.replace('./');
  132. }
  133. }}
  134. >
  135. <PreviousPageSvg />
  136. </Pressable>
  137. </View>
  138. </View>
  139. <View className="flex-column mx-[5%] mt-[5%]">
  140. <View>
  141. <Text className="text-3xl">
  142. {params.chargeStationName}
  143. </Text>
  144. </View>
  145. <View className="flex-row justify-between items-center">
  146. <Text
  147. className="text-base"
  148. style={{ color: '#888888' }}
  149. >
  150. {params.chargeStationAddress}
  151. </Text>
  152. <NormalButton
  153. title={
  154. <View className="flex-row items-center justify-center text-center space-x-1">
  155. <DirectionLogoSvg />
  156. <Text className="text-base ">路線</Text>
  157. </View>
  158. }
  159. onPress={() => console.log('路線')}
  160. extendedStyle={{
  161. backgroundColor: '#E3F2F8',
  162. borderRadius: 61,
  163. paddingHorizontal: 20,
  164. paddingVertical: 10
  165. }}
  166. />
  167. </View>
  168. <View className="flex-row space-x-2 items-center pb-3 ">
  169. <CheckMarkLogoSvg />
  170. <Text>Walk-In</Text>
  171. <Text>400m</Text>
  172. </View>
  173. <NormalButton
  174. title={
  175. <View className="pr-2">
  176. <Text
  177. style={{
  178. color: '#FFFFFF',
  179. fontWeight: 700,
  180. fontSize: 20
  181. }}
  182. >
  183. + 新增預約
  184. </Text>
  185. </View>
  186. }
  187. // onPress={() => console.log('ab')}
  188. onPress={() => router.push('makingBookingPage')}
  189. extendedStyle={{ flex: 0.5 }}
  190. />
  191. <View
  192. className="flex-1 flex-row min-h-[20px] border-slate-300 my-6 rounded-2xl"
  193. style={{ borderWidth: 1 }}
  194. >
  195. <View className="flex-1 m-4">
  196. <View className="flex-1 flex-row ">
  197. <View className=" flex-1 flex-column justify-between">
  198. <Text
  199. className="text-xl "
  200. style={styles.text}
  201. >
  202. 收費
  203. </Text>
  204. <View className="flex-row items-center space-x-2">
  205. <Text className="text-3xl text-[#02677D]">
  206. $20
  207. </Text>
  208. <Text style={styles.text}>
  209. 每15分鐘
  210. </Text>
  211. </View>
  212. </View>
  213. <View className="items-center justify-center">
  214. <View className="w-[1px] h-[60%] bg-[#CCCCCC]" />
  215. </View>
  216. <View className="flex-1 flex-column ">
  217. <View className="flex-1"></View>
  218. <View className="flex-row items-center ml-4 space-x-2 ">
  219. <Text className="text-3xl text-[#02677D]">
  220. ${price}
  221. </Text>
  222. <Text style={styles.text}>每度電</Text>
  223. </View>
  224. </View>
  225. </View>
  226. </View>
  227. </View>
  228. </View>
  229. <View className="min-h-[300px]">
  230. <Text className="text-xl pb-2 mx-[5%]" style={styles.text}>
  231. 充電站資訊
  232. </Text>
  233. <ChargingStationTabView titles={['充電插頭', '其他']} />
  234. </View>
  235. </ScrollView>
  236. </SafeAreaView>
  237. );
  238. };
  239. export default ResultDetailPageComponent;
  240. const styles = StyleSheet.create({
  241. text: {
  242. fontWeight: 300,
  243. color: '#000000'
  244. }
  245. });