chargingFinishPageComponent.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import { View, Text, ScrollView, Image, StyleSheet, Pressable } from 'react-native';
  2. import React from 'react';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import Svg, { Path, Rect } from 'react-native-svg';
  5. import NormalButton from '../global/normal_button';
  6. import SlideInImage from '../global/slideInImage';
  7. import { router, useLocalSearchParams } from 'expo-router';
  8. const BatteryLogoSvg = () => (
  9. <Svg width="40" height="40" viewBox="0 0 40 40" fill="none">
  10. <Rect width="40" height="40" rx="20" fill="#02677D" />
  11. <Path
  12. d="M25.1202 32.2255V28.7039H22.5962L26.274 22.8746V26.3962H28.798L25.1202 32.2255ZM14.8798 31.925C14.5597 31.925 14.2914 31.8168 14.0748 31.6002C13.8583 31.3837 13.75 31.1153 13.75 30.7952V11.4804C13.75 11.1603 13.8583 10.8919 14.0748 10.6754C14.2914 10.4589 14.5597 10.3506 14.8798 10.3506H17.1394V8.17511H21.7547V10.3506H24.0168C24.3373 10.3506 24.6053 10.4589 24.8208 10.6754C25.0364 10.8919 25.1441 11.1603 25.1441 11.4804V20.1703C24.8108 20.1863 24.4899 20.2228 24.1814 20.2796C23.8729 20.3365 23.5689 20.4179 23.2692 20.5236V12.2135H15.6249V27.514H18.2452C18.2452 28.3441 18.3758 29.1342 18.637 29.8842C18.8982 30.6342 19.2708 31.3145 19.7547 31.925H14.8798Z"
  13. fill="#FAFAFA"
  14. />
  15. </Svg>
  16. );
  17. const DownArrowSvg = () => (
  18. <Svg width="12" height="7" viewBox="0 0 12 7" fill="none">
  19. <Path
  20. d="M6.00002 6.70762L0.346191 1.05383L1.40002 0L6.00002 4.6L10.6 0L11.6538 1.05383L6.00002 6.70762Z"
  21. fill="#222222"
  22. />
  23. </Svg>
  24. );
  25. const UpArrowSvg = () => (
  26. <Svg width="12" height="7" viewBox="0 0 12 7" fill="none">
  27. <Path
  28. d="M6.00002 0.29238L11.6538 5.94617L10.6 7L6.00002 2.4L1.40002 7L0.346191 5.94617L6.00002 0.29238Z"
  29. fill="#222222"
  30. />
  31. </Svg>
  32. );
  33. const TimeClockLogoSvg = () => (
  34. <Svg width="40" height="40" viewBox="0 0 40 40" fill="none">
  35. <Rect width="40" height="40" rx="20" fill="#02677D" />
  36. <Path
  37. d="M23.6559 24.7652L24.7652 23.6559L20.7894 19.6799V14.7368H19.2105V20.3198L23.6559 24.7652ZM20.0018 30C18.6187 30 17.3186 29.7375 16.1016 29.2126C14.8846 28.6877 13.826 27.9753 12.9258 27.0755C12.0255 26.1757 11.3129 25.1175 10.7877 23.9011C10.2626 22.6846 10 21.3849 10 20.0018C10 18.6187 10.2625 17.3186 10.7874 16.1016C11.3123 14.8846 12.0247 13.826 12.9245 12.9258C13.8243 12.0256 14.8825 11.3129 16.0989 10.7877C17.3154 10.2626 18.6151 10 19.9982 10C21.3813 10 22.6814 10.2625 23.8984 10.7874C25.1154 11.3123 26.174 12.0247 27.0742 12.9245C27.9744 13.8243 28.6871 14.8825 29.2123 16.0989C29.7374 17.3154 30 18.6151 30 19.9982C30 21.3813 29.7375 22.6814 29.2126 23.8984C28.6877 25.1154 27.9753 26.174 27.0755 27.0742C26.1757 27.9744 25.1175 28.6871 23.9011 29.2123C22.6846 29.7374 21.3849 30 20.0018 30ZM20 28.4211C22.3333 28.4211 24.3202 27.6009 25.9605 25.9605C27.6009 24.3202 28.4211 22.3333 28.4211 20C28.4211 17.6667 27.6009 15.6798 25.9605 14.0395C24.3202 12.3991 22.3333 11.5789 20 11.5789C17.6667 11.5789 15.6798 12.3991 14.0395 14.0395C12.3991 15.6798 11.5789 17.6667 11.5789 20C11.5789 22.3333 12.3991 24.3202 14.0395 25.9605C15.6798 27.6009 17.6667 28.4211 20 28.4211Z"
  38. fill="#FAFAFA"
  39. />
  40. </Svg>
  41. );
  42. const TickLogoSvg = () => (
  43. <Svg width="40" height="40" viewBox="0 0 40 40" fill="none">
  44. <Rect width="40" height="40" rx="20" fill="#02677D" />
  45. <Path
  46. d="M15.9168 30L6.41684 20.5L8.79184 18.125L15.9168 25.25L31.2085 9.95837L33.5835 12.3334L15.9168 30Z"
  47. fill="#FAFAFA"
  48. />
  49. </Svg>
  50. );
  51. const BatteryIconSvg = () => (
  52. <Svg width="20" height="31" viewBox="0 0 20 31" fill="none">
  53. <Path
  54. d="M15.1282 30.8013V26.4103H12.5641L16.5384 19.1987V23.5898H19.1026L15.1282 30.8013ZM1.98716 30C1.60574 30 1.28603 29.871 1.02803 29.613C0.770005 29.355 0.640991 29.0353 0.640991 28.6539V3.81408C0.640991 3.4327 0.770005 3.11299 1.02803 2.85496C1.28603 2.59696 1.60574 2.46796 1.98716 2.46796H4.67949V0H10.3205V2.46796H13.0194C13.4018 2.46796 13.7206 2.59696 13.9759 2.85496C14.2313 3.11299 14.359 3.4327 14.359 3.81408V15.3205C11.9872 15.6261 9.99466 16.68 8.38141 18.4824C6.76816 20.2847 5.96153 22.4252 5.96153 24.9038C5.96153 25.8398 6.0876 26.7383 6.33974 27.5994C6.59188 28.4605 6.96046 29.2607 7.44549 30H1.98716Z"
  55. fill="#02677D"
  56. />
  57. </Svg>
  58. );
  59. const LightingLogoSvg = () => (
  60. <Svg width="21" height="30" viewBox="0 0 21 30" fill="none">
  61. <Path
  62. d="M5.75631 29.8077L7.42297 18.3333H0.3396L12.8076 0.352539H13.5768L11.9422 13.3333H20.2756L6.52552 29.8077H5.75631Z"
  63. fill="#02677D"
  64. />
  65. </Svg>
  66. );
  67. const TemperatureIconSvg = () => (
  68. <Svg width="15" height="30" viewBox="0 0 15 30" fill="none">
  69. <Path
  70. d="M7.50004 30C5.64321 30 4.06789 29.3531 2.77408 28.0593C1.48028 26.7655 0.833374 25.1902 0.833374 23.3333C0.833374 22.1282 1.13037 21.0187 1.72437 20.0048C2.3184 18.9909 3.13251 18.1773 4.16671 17.5641V3.33333C4.16671 2.39317 4.48722 1.60257 5.12825 0.961543C5.76928 0.320515 6.55987 0 7.50004 0C8.44021 0 9.2308 0.320515 9.87183 0.961543C10.5129 1.60257 10.8334 2.39317 10.8334 3.33333V17.5641C11.8676 18.1773 12.6817 18.9909 13.2757 20.0048C13.8697 21.0187 14.1667 22.1282 14.1667 23.3333C14.1667 25.1902 13.5198 26.7655 12.226 28.0593C10.9322 29.3531 9.35687 30 7.50004 30ZM5.83337 13.9744H9.16671V11.4744H7.50004V10.1923H9.16671V6.47438H7.50004V5.19229H9.16671V3.33333C9.16671 2.86111 9.00698 2.46528 8.68754 2.14583C8.3681 1.82639 7.97226 1.66667 7.50004 1.66667C7.02782 1.66667 6.63198 1.82639 6.31254 2.14583C5.9931 2.46528 5.83337 2.86111 5.83337 3.33333V13.9744Z"
  71. fill="#02677D"
  72. />
  73. </Svg>
  74. );
  75. const ChargingFinishPageComponent = ({ data }: { data: any }) => {
  76. const chargingData = Array.isArray(data) ? data[0] : data;
  77. const [isMoreInfoButtonPressed, setIsMoreInfoButtonPressed] = React.useState<boolean>(true);
  78. function calculateDurationInMinutes(startTimeString: string, endTimeString: string): number {
  79. const startTime = new Date(startTimeString);
  80. const endTime = new Date(endTimeString);
  81. // Calculate the difference in milliseconds
  82. const durationMs = endTime.getTime() - startTime.getTime();
  83. // Convert milliseconds to minutes
  84. const durationMinutes = Math.round(durationMs / (1000 * 60));
  85. return durationMinutes;
  86. }
  87. const durationInMinutes = calculateDurationInMinutes(chargingData.actual_start_time, chargingData.actual_end_time);
  88. return (
  89. <SafeAreaView className="flex-1 bg-white">
  90. <ScrollView className="flex-1 mx-[5%]" showsVerticalScrollIndicator={false}>
  91. <View style={{ marginTop: 25, flex: 1 }}>
  92. <View className="flex-row items-center">
  93. <TickLogoSvg />
  94. <Text className="text-3xl pl-2">完成充電</Text>
  95. </View>
  96. <View className="items-center pt-4 justify-center">
  97. {/* <SlideInImage source={require('../../assets/car.png')} />
  98. <Text className="text-2xl font-light pb-4">
  99. {chargingData.car.car_brand.name} {chargingData.car.car_type.name}
  100. </Text> */}
  101. </View>
  102. <View style={{ borderWidth: 1 }} className="border-[#EEEEEE] rounded-2xl">
  103. <View className="mx-[5%] flex-column p-4 ">
  104. <View className="flex-row justify-evenly gap-6">
  105. <View className="flex-row items-center space-x-4">
  106. <BatteryLogoSvg />
  107. <View className="flex-column ">
  108. <Text className="text-sm" style={styles.grayColor}>
  109. 已充電
  110. </Text>
  111. <Text style={styles.greenColor} className="text-4xl font-light">
  112. {`${chargingData.Soc}%`}
  113. </Text>
  114. </View>
  115. </View>
  116. <View className="flex-row items-center space-x-4">
  117. <TimeClockLogoSvg />
  118. <View className="flex-column">
  119. {/* actualEnd_time - actual start time */}
  120. <Text className="text-sm" style={styles.grayColor}>
  121. 充電歷時
  122. </Text>
  123. <View className="flex-row items-end">
  124. <Text style={styles.greenColor} className="text-4xl font-light">
  125. {/* 39 */}
  126. {durationInMinutes}
  127. </Text>
  128. <Text style={styles.greenColor} className="text-sm font-light">
  129. mins
  130. </Text>
  131. </View>
  132. </View>
  133. </View>
  134. </View>
  135. <View className="h-0.5 w-full my-4 bg-[#EEEEEE]" />
  136. {/* {isMoreInfoButtonPressed ? (
  137. <>
  138. <View className="h-[100px] flex-row items-center">
  139. <View className="flex-1 flex-column items-center space-y-2">
  140. <LightingLogoSvg />
  141. <Text style={styles.grayColor} className="text-base">
  142. 充電功率
  143. </Text>
  144. <Text style={styles.greenColor} className="font-bold text-base">
  145. {chargingData.connector.Power / 1000}kW
  146. </Text>
  147. </View>
  148. <View className="flex-1 flex-column items-center space-y-2">
  149. <BatteryIconSvg />
  150. <Text style={styles.grayColor} className="text-base">
  151. 實際功率
  152. </Text>
  153. <Text style={styles.greenColor} className="font-bold text-base">
  154. {chargingData.connector.Power / 1000}kW
  155. </Text>
  156. </View>
  157. </View>
  158. <Pressable
  159. onPress={() => {
  160. setIsMoreInfoButtonPressed(!isMoreInfoButtonPressed);
  161. }}
  162. style={{ padding: 2 }}
  163. >
  164. <View className="flex-row pt-4 items-center justify-center">
  165. <Text className="text-sm">收起 </Text>
  166. <UpArrowSvg />
  167. </View>
  168. </Pressable>
  169. </>
  170. ) : (
  171. <Pressable
  172. onPress={() => {
  173. setIsMoreInfoButtonPressed(!isMoreInfoButtonPressed);
  174. }}
  175. style={{ padding: 2 }}
  176. >
  177. <View className="flex-row items-center justify-center">
  178. <Text className="text-sm">更多資訊 </Text>
  179. <DownArrowSvg />
  180. </View>
  181. </Pressable>
  182. )} */}
  183. </View>
  184. </View>
  185. <View>
  186. <Text className="text-xl py-4">收費概要</Text>
  187. <View className="flex-row justify-between">
  188. <Text className="text-base">充電費用</Text>
  189. <Text className="text-base">HK$ {chargingData.total_fee}</Text>
  190. </View>
  191. <Text style={styles.grayColor} className="text-base">
  192. {chargingData.total_power === null
  193. ? '充滿停機'
  194. : `按每度電結算: ${Math.floor(chargingData.total_power)} kWh`}
  195. </Text>
  196. <View className="h-0.5 my-3 bg-[#f4f4f4]" />
  197. {chargingData.withdraw_fee === 0 ? (
  198. ''
  199. ) : (
  200. <View className="flex-row justify-between">
  201. <Text className="text-base" style={styles.grayColor}>
  202. 退還充電按金
  203. </Text>
  204. <Text className="text-base">HK$ ${chargingData.withdraw}</Text>
  205. </View>
  206. )}
  207. <View className="h-0.5 my-3 bg-[#f4f4f4]" />
  208. <View className="flex-row justify-between ">
  209. <Text className="text-xl">總計</Text>
  210. <Text className="text-xl">HK$ ${chargingData.total_fee - chargingData.withdraw_fee}</Text>
  211. </View>
  212. <View className="mt-4"></View>
  213. </View>
  214. <View className="w-full h-1 bg-[#DBE4E8]" />
  215. <View className="space-y-4 my-4">
  216. <Text className="text-xl ">付款資訊</Text>
  217. <View>
  218. <Text className="text-base" style={styles.grayColor}>
  219. 訂單編號
  220. </Text>
  221. <Text className="text-base">CXZ-16336958</Text>
  222. </View>
  223. <View>
  224. <Text className="text-base" style={styles.grayColor}>
  225. 付款方式
  226. </Text>
  227. <Text className="text-base">預付銀包</Text>
  228. </View>
  229. </View>
  230. <NormalButton
  231. title={<Text style={{ color: '#fff', fontSize: 18 }}>返回主頁</Text>}
  232. onPress={() => {
  233. router.push('mainPage');
  234. }}
  235. />
  236. </View>
  237. </ScrollView>
  238. </SafeAreaView>
  239. );
  240. };
  241. export default ChargingFinishPageComponent;
  242. const styles = StyleSheet.create({
  243. grayColor: {
  244. color: '#888888'
  245. },
  246. greenColor: {
  247. color: '#02677D'
  248. }
  249. });