Browse Source

fix: 罚款时间修复

kuns 1 month ago
parent
commit
580b981a96

+ 1 - 1
.env.development

@@ -1,2 +1,2 @@
 EXPO_PUBLIC_NODE_ENV=development
-EXPO_PUBLIC_API_URL=http://192.168.1.42:12000/api/v1
+EXPO_PUBLIC_API_URL=http://47.115.173.98:12000/api/v1

+ 5 - 10
component/accountPages/walletPageComponent.tsx

@@ -21,12 +21,7 @@ import { CrossLogoSvg } from '../global/SVG';
 import { useEffect, useRef, useState } from 'react';
 import { walletService } from '../../service/walletService';
 import NormalButton from '../global/normal_button';
-import { formatCouponDate, formatDate } from '../../util/lib';
-import { set } from 'date-fns';
-import { reloadAppAsync } from 'expo';
 import sha256 from 'crypto-js/sha256';
-import { useCallback } from 'react';
-
 import { useChargingStore } from '../../providers/scan_qr_payload_store';
 
 const AmountInputModal = ({ visible, onClose, onConfirm }) => {
@@ -164,9 +159,9 @@ export const IndividualCouponComponent = ({
                                     justifyContent: 'center',
                                     alignItems: 'center'
                                 }}
-                                className={`${promotion_code?.includes(redeem_code) ? 'bg-[#02677D]' : 'bg-white'}`}
+                                className={`${promotion_code?.includes(redeem_code as string) ? 'bg-[#02677D]' : 'bg-white'}`}
                             >
-                                <Text className="text-white">{promotion_code?.indexOf(redeem_code) + 1}</Text>
+                                <Text className="text-white">{promotion_code?.indexOf(redeem_code as string) + 1}</Text>
                             </View>
                         )}
                     </View>
@@ -199,7 +194,7 @@ const WalletPageComponent = () => {
     const [paymentStatus, setPaymentStatus] = useState(null);
     const [isExpectingPayment, setIsExpectingPayment] = useState(false);
     const appState = useRef(AppState.currentState);
-    const paymentInitiatedTime = useRef(null);
+    const paymentInitiatedTime = useRef<number>(null);
     // 优惠券注释
     useEffect(() => {
         const fetchData = async () => {
@@ -261,7 +256,7 @@ const WalletPageComponent = () => {
             const result = await walletService.checkPaymentStatus(outTradeNo);
             setPaymentStatus(result);
 
-            if (result && !result.some((item) => item.errmsg?.includes('處理中'))) {
+            if (result && !result.some((item: any) => item.errmsg?.includes('處理中'))) {
                 // Payment successful
 
                 Alert.alert('Success', 'Payment was successful!', [
@@ -356,7 +351,7 @@ const WalletPageComponent = () => {
         fetchPaymentType();
     }, []);
 
-    const handleAmountConfirm = async (inputAmount) => {
+    const handleAmountConfirm = async (inputAmount: number) => {
         setAmountModalVisible(false);
         try {
             const response = await walletService.getOutTradeNo();

+ 13 - 10
component/chargingPage/penaltyPaymentPageComponent.tsx

@@ -2,7 +2,7 @@ import { View, Text, ScrollView, Pressable, StyleSheet, Alert } from 'react-nati
 import { SafeAreaView } from 'react-native-safe-area-context';
 import { router, useLocalSearchParams, useNavigation } from 'expo-router';
 import NormalButton from '../global/normal_button';
-import { useEffect } from 'react';
+import { useEffect, useState } from 'react';
 import { chargeStationService } from '../../service/chargeStationService';
 import useUserInfoStore from '../../providers/userinfo_store';
 import { PreviousPageBlackSvg } from '../global/SVG';
@@ -10,14 +10,21 @@ import { PreviousPageBlackSvg } from '../global/SVG';
 const PenaltyPaymentPageComponent = () => {
     const params = useLocalSearchParams();
     const { userID } = useUserInfoStore();
-    console.log('params in penaltyPaymentPageComponent', params);
     const navigation = useNavigation();
-
+    const [leaving_time, setLeavingTime] = useState<string | null>(null)
     useEffect(() => {
         navigation.setOptions({
             gestureEnabled: false
         });
     }, [navigation]);
+    useEffect(() => {
+        chargeStationService.fetchChargingDetails(params.id.toString()).then(res => {
+          if (res && res[0].charging.length > 0) {
+            const { date, time } = convertBookingDateTime(res[0].charging[0].leaving_time as string);
+            setLeavingTime(time);
+          }
+        })
+    }, [params]);
     const convertBookingDateTime = (isoDateString: string): { date: string; time: string } => {
         const bookingDate = new Date(isoDateString);
 
@@ -41,14 +48,13 @@ const PenaltyPaymentPageComponent = () => {
 
     const calculateUserEndTime = (actualEndTimeStr: string, penaltyFee: string): string => {
         const actualEndTime = new Date(actualEndTimeStr);
-        const penaltyMinutes = Math.floor(parseFloat(penaltyFee) / 3); // $3 per minute
+        const penaltyMinutes = Math.floor(parseFloat(penaltyFee) / 3) + 15 // $3 per minute
         const userEndTime = new Date(actualEndTime.getTime() + penaltyMinutes * 60000); // add minutes
 
         return userEndTime.toISOString();
     };
 
-    const { date, time } = convertBookingDateTime(params.book_time);
-    const { date: end_date, time: end_time } = convertBookingDateTime(params.end_time as string);
+    const { date, time } = convertBookingDateTime(params.book_time as string);
     const { date: actual_end_date, time: actual_end_time } = convertBookingDateTime(params.actual_end_time as string);
     const { time: user_end_time } = convertBookingDateTime(
         calculateUserEndTime(params.actual_end_time as string, params.penalty_fee as string)
@@ -96,9 +102,6 @@ const PenaltyPaymentPageComponent = () => {
                     </Pressable>
                     <Text className="text-3xl my-8 text-center">尚未繳付罰款的充電記錄</Text>
                 </View>
-                {/* <View className="pl-8 pt-8">
-                    <Text className="text-3xl mt-8">尚未繳付罰款的充電記錄</Text>
-                </View> */}
 
                 <View className="flex-1 mt-4 mx-[5%]">
                     <View className="flex-1 flex-row items-center pb-3">
@@ -115,7 +118,7 @@ const PenaltyPaymentPageComponent = () => {
                                 實際充電結束時間
                             </Text>
                             <Text style={styles.greenColor} className="text-4xl text-center pt-2">
-                                {user_end_time}
+                                {leaving_time || user_end_time}
                             </Text>
                         </View>
                     </View>

+ 1 - 1
component/homePage/homePage.tsx

@@ -195,7 +195,7 @@ const HomePage: React.FC<HomePageProps> = () => {
                         const mostRecentUnpaidReservation = unpaidPenalties.reduce((mostRecent: any, current: any) => {
                             return new Date(mostRecent.created_at) > new Date(current.created_at) ? mostRecent : current;
                         }, unpaidPenalties[0]);
-
+                        console.log('mostRecentUnpaidReservation', mostRecentUnpaidReservation);
                         if (unpaidPenalties.length > 0) {
                             Alert.alert(
                                 '未付罰款',

+ 9 - 1
service/type/chargeStationType.ts

@@ -99,7 +99,14 @@ export interface Car {
 	car_brand: Car_brand;
 	car_type: Car_type;
 }
-
+export interface Charging {
+	createdAt: string;
+	updatedAt: string;
+	id: string;
+	penaltyTotalTime: string;
+	penaltyFee: string;
+	leaving_time: string;
+}
 export interface ChargingDetails {
 	createdAt: string;
 	updatedAt: string;
@@ -126,6 +133,7 @@ export interface ChargingDetails {
 	user: User;
 	status: Statu;
 	car: Car;
+	charging: Charging [];
 }
 export interface Remark {
   EndTime: string;