bookingConfirmationPage.tsx 9.0 KB

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