resultDetailPageComponent.tsx 11 KB

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