bookingConfirmationPage.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import { View, Text, ScrollView, Pressable, StyleSheet } from 'react-native';
  2. import { SafeAreaView } from 'react-native-safe-area-context';
  3. import { router, useLocalSearchParams } from 'expo-router';
  4. import NormalButton from '../global/normal_button';
  5. import { PreviousPageBlackSvg } from '../global/SVG';
  6. import useCouponStore from '../../providers/coupon_store';
  7. import { useEffect } from 'react';
  8. import useBookingStore from '../../providers/booking_store';
  9. const BookingConfirmationPageComponent = () => {
  10. const params = useLocalSearchParams();
  11. const { setSelectedCouponName, setSelectedCouponRedeemCode } = useCouponStore();
  12. useEffect(() => {
  13. setSelectedCouponName('');
  14. setSelectedCouponRedeemCode('');
  15. }, []);
  16. const convertDate = (dateString: string) => {
  17. const [year, month, day] = dateString.split('-');
  18. const monthNumber = parseInt(month, 10);
  19. return `${monthNumber}月${parseInt(day, 10)}日`;
  20. };
  21. const price = params.price;
  22. const calculatePaymentFee = () => {
  23. const chargingMethod = params.chargingMethod;
  24. const price = parseFloat(params.price);
  25. if (chargingMethod === 'stopChargingUponBatteryFull') {
  26. const carCapacitance = parseFloat(params.carCapacitance);
  27. return (carCapacitance * price).toFixed(2);
  28. } else {
  29. const chargingWatt = parseFloat(params.chargingWatt);
  30. return (price * chargingWatt).toFixed(2);
  31. }
  32. };
  33. const paymentFee = calculatePaymentFee();
  34. const setBookingInfo = useBookingStore((state) => state.setBookingInfo);
  35. return (
  36. <SafeAreaView style={{ flex: 1, backgroundColor: 'white' }} edges={['top', 'left', 'right']}>
  37. <ScrollView className="flex-1" showsVerticalScrollIndicator={false}>
  38. <View className="flex-1">
  39. <View className="pl-8 pt-8">
  40. <Pressable
  41. style={{ alignSelf: 'flex-start' }}
  42. onPress={() => {
  43. if (router.canGoBack()) {
  44. router.back();
  45. } else {
  46. router.replace('./');
  47. }
  48. }}
  49. >
  50. <PreviousPageBlackSvg />
  51. </Pressable>
  52. <Text className="text-3xl mt-8">確認您的預約</Text>
  53. </View>
  54. <View className="flex-1 mt-4 mx-[5%]">
  55. <View className="flex-1 flex-row items-center pb-3">
  56. <View className="flex-1 flex-column">
  57. <Text style={styles.grayColor} className="text-base">
  58. 日期
  59. </Text>
  60. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  61. {convertDate(params.date)}
  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. {params.bookTime}
  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-3xl ">
  78. {params.chargeStationName}
  79. </Text>
  80. <Text style={styles.grayColor} className="text-sm">
  81. {params.chargeStationAddress}
  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. {params.chargingMethod === 'chargingBasedOnWatt' ? (
  90. <>
  91. <Text style={styles.greenColor} className="text-lg">
  92. 按每度電結算
  93. </Text>
  94. <Text style={styles.grayColor} className="text-sm">
  95. {params.chargingWatt?.split('~')[0]}
  96. </Text>
  97. </>
  98. ) : (
  99. <Text style={styles.greenColor} className="text-lg">
  100. 充滿停機
  101. </Text>
  102. )}
  103. </View>
  104. <View className="flex-column flex-1">
  105. <Text style={styles.grayColor} className="text-base">
  106. 預約充電座號碼
  107. </Text>
  108. <Text style={styles.greenColor} className="text-lg">
  109. {params.connectorLabel}號充電座
  110. </Text>
  111. </View>
  112. </View>
  113. {/* <View className="flex-1 flex-row pb-3 ">
  114. <View className="flex-column flex-1">
  115. <Text style={styles.grayColor} className="text-base">
  116. 預約充電座號碼
  117. </Text>
  118. <Text style={styles.greenColor} className="text-lg">
  119. {params.connectorLabel}號充電座
  120. </Text>
  121. </View>
  122. </View> */}
  123. </View>
  124. </View>
  125. <View className="border-t mx-4 border-[#CCCCCC]"></View>
  126. <View className="flex-1 mx-[5%] mt-4 space-y-1">
  127. <Text className="text-xs text-[#888888]">
  128. **由於充電站車流眾多,敬請客戶務必於預約時間的十五分鐘內到達充電站。
  129. </Text>
  130. <Text className="text-xs text-[#888888]">
  131. **若客戶逾時超過15分鐘,系統將視作自動放棄預約,客戶需要重新預約一次。
  132. </Text>
  133. <Text className="text-xs text-[#888888]">**本公司有權保留全數費用,恕不退還。</Text>
  134. <View className="mt-4">
  135. <NormalButton
  136. title={
  137. <Text
  138. style={{
  139. color: 'white',
  140. fontSize: 16,
  141. fontWeight: '800'
  142. }}
  143. >
  144. 下一步
  145. </Text>
  146. }
  147. // onPress={() => router.push('bookingSuccessPage')}
  148. onPress={() => {
  149. setBookingInfo({
  150. bookDateForDisplay: convertDate(params.date),
  151. bookTimeForDisplay: params.bookTime,
  152. chargeStationAddressForDisplay: params.chargeStationAddress,
  153. chargeStationNameForDisplay: params.chargeStationName,
  154. carNameForDisplay: params.carName
  155. });
  156. router.push({
  157. pathname: 'paymentSummaryPage',
  158. params: {
  159. stationID: params.chargeStationID,
  160. connectorID: params.connectorID,
  161. userID: params.userID,
  162. date: params.date,
  163. bookTime: params.bookTime,
  164. endTime: params.endTime,
  165. price: params.price,
  166. chargingWatt: params.chargingWatt,
  167. carID: params.carID,
  168. paymentFee: paymentFee,
  169. car_Capacity: params.carCapacitance
  170. }
  171. });
  172. }}
  173. extendedStyle={{ padding: 24, marginTop: 24 }}
  174. />
  175. </View>
  176. </View>
  177. </ScrollView>
  178. </SafeAreaView>
  179. );
  180. };
  181. export default BookingConfirmationPageComponent;
  182. const styles = StyleSheet.create({
  183. grayColor: {
  184. color: '#888888'
  185. },
  186. greenColor: {
  187. color: '#02677D'
  188. }
  189. });