bookingConfirmationPage.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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('paramsparamsparamsparamsparamsparamsparamsparams', params);
  12. const { setSelectedCouponName, setSelectedCouponRedeemCode } = useCouponStore();
  13. useEffect(() => {
  14. setSelectedCouponName('');
  15. setSelectedCouponRedeemCode('');
  16. }, []);
  17. const convertDate = (dateString: string) => {
  18. const [year, month, day] = dateString.split('-');
  19. const monthNumber = parseInt(month, 10);
  20. return `${monthNumber}月${parseInt(day, 10)}日`;
  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-4xl 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-4xl 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.connectorLabel}號充電座
  111. </Text>
  112. </View>
  113. </View>
  114. {/* <View className="flex-1 flex-row pb-3 ">
  115. <View className="flex-column flex-1">
  116. <Text style={styles.grayColor} className="text-base">
  117. 預約充電座號碼
  118. </Text>
  119. <Text style={styles.greenColor} className="text-lg">
  120. {params.connectorLabel}號充電座
  121. </Text>
  122. </View>
  123. </View> */}
  124. </View>
  125. </View>
  126. <View className="border-t mx-4 border-[#CCCCCC]"></View>
  127. <View className="flex-1 mx-[5%] mt-4 space-y-1">
  128. <Text className="text-xs text-[#888888]">
  129. **由於充電站車流眾多,敬請客戶務必於預約時間的十五分鐘內到達充電站。
  130. </Text>
  131. <Text className="text-xs text-[#888888]">
  132. **若客戶逾時超過15分鐘,系統將視作自動放棄預約,客戶需要重新預約一次。
  133. </Text>
  134. <Text className="text-xs text-[#888888]">**本公司有權保留全數費用,恕不退還。</Text>
  135. <View className="mt-4">
  136. <NormalButton
  137. title={
  138. <Text
  139. style={{
  140. color: 'white',
  141. fontSize: 16,
  142. fontWeight: '800'
  143. }}
  144. >
  145. 下一步
  146. </Text>
  147. }
  148. // onPress={() => router.push('bookingSuccessPage')}
  149. onPress={() => {
  150. setBookingInfo({
  151. bookDateForDisplay: convertDate(params.date),
  152. bookTimeForDisplay: params.bookTime,
  153. chargeStationAddressForDisplay: params.chargeStationAddress,
  154. chargeStationNameForDisplay: params.chargeStationName,
  155. carNameForDisplay: params.carName
  156. });
  157. router.push({
  158. pathname: 'paymentSummaryPage',
  159. params: {
  160. stationID: params.chargeStationID,
  161. connectorID: params.connectorID,
  162. userID: params.userID,
  163. date: params.date,
  164. bookTime: params.bookTime,
  165. endTime: params.endTime,
  166. price: params.price,
  167. chargingWatt: params.chargingWatt,
  168. carID: params.carID,
  169. paymentFee: paymentFee,
  170. car_Capacity: params.carCapacitance
  171. }
  172. });
  173. }}
  174. extendedStyle={{ padding: 24, marginTop: 24 }}
  175. />
  176. </View>
  177. </View>
  178. </ScrollView>
  179. </SafeAreaView>
  180. );
  181. };
  182. export default BookingConfirmationPageComponent;
  183. const styles = StyleSheet.create({
  184. grayColor: {
  185. color: '#888888'
  186. },
  187. greenColor: {
  188. color: '#02677D'
  189. }
  190. });