penaltyPaymentPageComponent.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { View, Text, ScrollView, Pressable, StyleSheet, Alert } from 'react-native';
  2. import { SafeAreaView } from 'react-native-safe-area-context';
  3. import { router, useLocalSearchParams, useNavigation } 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. import { chargeStationService } from '../../service/chargeStationService';
  10. import useUserInfoStore from '../../providers/userinfo_store';
  11. const PenaltyPaymentPageComponent = () => {
  12. const params = useLocalSearchParams();
  13. const { userID } = useUserInfoStore();
  14. console.log('params in penaltyPaymentPageComponent', params);
  15. const navigation = useNavigation();
  16. useEffect(() => {
  17. navigation.setOptions({
  18. gestureEnabled: false
  19. });
  20. }, [navigation]);
  21. const convertBookingDateTime = (isoDateString: string): { date: string; time: string } => {
  22. const bookingDate = new Date(isoDateString);
  23. // Adjust to local time (+8 hours)
  24. bookingDate.setHours(bookingDate.getHours() + 8);
  25. // Format date as "MM-DD"
  26. const date = `${(bookingDate.getMonth() + 1).toString().padStart(2, '0')}-${bookingDate
  27. .getDate()
  28. .toString()
  29. .padStart(2, '0')}`;
  30. // Format time as "HH:mm"
  31. const time = `${bookingDate.getHours().toString().padStart(2, '0')}:${bookingDate
  32. .getMinutes()
  33. .toString()
  34. .padStart(2, '0')}`;
  35. return { date, time };
  36. };
  37. const { date, time } = convertBookingDateTime(params.book_time);
  38. const { date: end_date, time: end_time } = convertBookingDateTime(params.end_time as string);
  39. const { date: actual_end_date, time: actual_end_time } = convertBookingDateTime(params.actual_end_time as string);
  40. const payload = {
  41. userId: userID,
  42. amount: parseFloat(params.penalty_fee as string),
  43. reservationId: params.id
  44. };
  45. const handlePayment = async () => {
  46. try {
  47. const result = await chargeStationService.payPenalty(payload);
  48. if (result) {
  49. Alert.alert('支付成功', '罰款已成功支付', [{ text: '確認', onPress: () => router.replace('/') }]);
  50. } else {
  51. Alert.alert('支付失敗', '請稍後再試');
  52. }
  53. } catch (error) {
  54. console.error('Payment error:', error);
  55. Alert.alert('支付錯誤', '發生錯誤,請稍後再試');
  56. }
  57. };
  58. return (
  59. <SafeAreaView style={{ flex: 1, backgroundColor: 'white' }} edges={['top', 'left', 'right']}>
  60. <ScrollView className="flex-1" showsVerticalScrollIndicator={false}>
  61. <View className="flex-1">
  62. <View className="pl-8 pt-8">
  63. <Text className="text-3xl mt-8">尚未繳付罰款的充電記錄</Text>
  64. </View>
  65. <View className="flex-1 mt-4 mx-[5%]">
  66. <View className="flex-1 flex-row items-center pb-3">
  67. <View className="flex-1 flex-column">
  68. <Text style={styles.grayColor} className="text-base">
  69. 充電到期時間
  70. </Text>
  71. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  72. {end_time}
  73. </Text>
  74. </View>
  75. <View className="flex-1 flex-column">
  76. <Text style={styles.grayColor} className="text-base pl-7">
  77. 實際充電結束時間
  78. </Text>
  79. <Text style={styles.greenColor} className="text-4xl text-center pt-2">
  80. {actual_end_time}
  81. </Text>
  82. </View>
  83. </View>
  84. <View className="flex-1 flex-column justify-center space-y-1 pb-3">
  85. <Text style={styles.grayColor} className="text-base">
  86. 充電日期
  87. </Text>
  88. <Text style={styles.greenColor} className="text-base">
  89. {date}
  90. </Text>
  91. </View>
  92. <View className="flex-1 flex-column justify-center space-y-1 pb-3">
  93. <Text style={styles.grayColor} className="text-base">
  94. 充電地點
  95. </Text>
  96. <Text style={styles.greenColor} className="text-base ">
  97. Crazy Charge(偉業街)
  98. </Text>
  99. </View>
  100. <View className="flex-1 flex-column justify-center space-y-1 pb-3">
  101. <Text style={styles.grayColor} className="text-base">
  102. 罰款金額
  103. </Text>
  104. <Text style={styles.greenColor} className="text-lg ">
  105. {params.penalty_fee}
  106. </Text>
  107. </View>
  108. <View className="flex-1 flex-column justify-center space-y-1 pb-3">
  109. <Text style={styles.grayColor} className="text-base">
  110. 訂單編號
  111. </Text>
  112. <Text style={styles.greenColor} className=" ">
  113. {params.format_order_id}
  114. </Text>
  115. </View>
  116. </View>
  117. </View>
  118. <View className="border-t mx-4 border-[#CCCCCC]"></View>
  119. <View className="flex-1 mx-[5%] mt-4 space-y-1">
  120. <View className="mt-4">
  121. <NormalButton
  122. title={
  123. <Text
  124. style={{
  125. color: 'white',
  126. fontSize: 16,
  127. fontWeight: '800'
  128. }}
  129. >
  130. 支付罰款
  131. </Text>
  132. }
  133. onPress={handlePayment}
  134. extendedStyle={{ padding: 24, marginTop: 24 }}
  135. />
  136. </View>
  137. </View>
  138. </ScrollView>
  139. </SafeAreaView>
  140. );
  141. };
  142. export default PenaltyPaymentPageComponent;
  143. const styles = StyleSheet.create({
  144. grayColor: {
  145. color: '#888888'
  146. },
  147. greenColor: {
  148. color: '#02677D'
  149. }
  150. });