Browse Source

perf: 优惠劵展示

lwxzks 4 months ago
parent
commit
f3c66cd05d

+ 20 - 20
app/(auth)/(tabs)/(home)/optionPage.tsx

@@ -70,25 +70,25 @@ const optionPage = () => {
 
     // 优惠券注释
 
-    // useEffect(() => {
-    //     const fetchData = async () => {
-    //         try {
-    //             const info = await walletService.getCustomerInfo();
-    //             const coupon = await walletService.getCouponForSpecificUser(info.id);
-    //             //filter by expire date is not past today.and is_consumed is fa.se.
-    //             const useableConpon = coupon.filter((couponObj: any) => {
-    //                 const today = new Date();
-    //                 if (couponObj.expire_date === null) {
-    //                     return couponObj.is_consumed === false;
-    //                 }
-    //                 const expireDate = new Date(couponObj.expire_date);
-    //                 return expireDate > today && couponObj.is_consumed === false;
-    //             });
-    //             setUseableCoupon(useableConpon);
-    //         } catch (error) {}
-    //     };
-    //     fetchData();
-    // }, []);
+    useEffect(() => {
+        const fetchData = async () => {
+            try {
+                const info = await walletService.getCustomerInfo();
+                const coupon = await walletService.getCouponForSpecificUser(info.id);
+                //filter by expire date is not past today.and is_consumed is fa.se.
+                const useableConpon = coupon.filter((couponObj: any) => {
+                    const today = new Date();
+                    if (couponObj.expire_date === null) {
+                        return couponObj.is_consumed === false;
+                    }
+                    const expireDate = new Date(couponObj.expire_date);
+                    return expireDate > today && couponObj.is_consumed === false;
+                });
+                setUseableCoupon(useableConpon);
+            } catch (error) {}
+        };
+        fetchData();
+    }, []);
     const cleanupData = () => {
         setTotalPower(null);
         setSumOfCoupon(0);
@@ -112,7 +112,7 @@ const optionPage = () => {
 
             const subscription = BackHandler.addEventListener('hardwareBackPress', onBackPress);
 
-            return () => subscription.remove()
+            return () => subscription.remove();
         }, [])
     );
 

+ 25 - 25
component/accountPages/walletPageComponent.tsx

@@ -200,29 +200,29 @@ const WalletPageComponent = () => {
     const appState = useRef(AppState.currentState);
     const paymentInitiatedTime = useRef(null);
     // 优惠券注释
-    // useEffect(() => {
-    //     const fetchData = async () => {
-    //         try {
-    //             setLoading(true);
-    //             const info = await walletService.getCustomerInfo();
-    //             const coupon = await walletService.getCouponForSpecificUser(info.id);
-    //             const useableConpon = coupon.filter((couponObj: any) => {
-    //                 const today = new Date();
-    //                 if (couponObj.expire_date === null) {
-    //                     return couponObj.is_consumed === false;
-    //                 }
-    //                 const expireDate = new Date(couponObj.expire_date);
-    //                 return expireDate > today && couponObj.is_consumed === false;
-    //             });
-
-    //             setCoupons(useableConpon);
-    //         } catch (error) {
-    //         } finally {
-    //             setLoading(false);
-    //         }
-    //     };
-    //     fetchData();
-    // }, []);
+    useEffect(() => {
+        const fetchData = async () => {
+            try {
+                setLoading(true);
+                const info = await walletService.getCustomerInfo();
+                const coupon = await walletService.getCouponForSpecificUser(info.id);
+                const useableConpon = coupon.filter((couponObj: any) => {
+                    const today = new Date();
+                    if (couponObj.expire_date === null) {
+                        return couponObj.is_consumed === false;
+                    }
+                    const expireDate = new Date(couponObj.expire_date);
+                    return expireDate > today && couponObj.is_consumed === false;
+                });
+
+                setCoupons(useableConpon);
+            } catch (error) {
+            } finally {
+                setLoading(false);
+            }
+        };
+        fetchData();
+    }, []);
     //monitor app state
     useEffect(() => {
         const subscription = AppState.addEventListener('change', (nextAppState) => {
@@ -520,9 +520,9 @@ const WalletPageComponent = () => {
 
                 <View className="flex-row justify-between mx-[5%] pt-6 pb-3">
                     <Text className="text-xl">優惠券</Text>
-                    {/* <Pressable onPress={() => router.push('couponPage')}>
+                    <Pressable onPress={() => router.push('couponPage')}>
                         <Text className="text-xl text-[#888888]">顯示所有</Text>
-                    </Pressable> */}
+                    </Pressable>
                 </View>
 
                 <View className="flex-1 flex-col mx-[5%]">

+ 3 - 5
service/chargeStationService.tsx

@@ -203,14 +203,12 @@ class ChargeStationService {
 
     async NewfetchAvailableConnectors() {
         try {
-            const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/info`, {
+            const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/local/info`, {
                 headers: {
                     Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
                 }
             });
             if (response.status === 200 && response.data.code === 200) {
-                console.log('sssssss', response.data);
-                console.log('sssssss1', SecureStore.getItemAsync('accessToken'));
                 return response.data.data.map((station: any) => {
                     // const snapshotData = JSON.parse(station.snapshot);
                     const snapshotData = station.snapshot;
@@ -221,7 +219,7 @@ class ChargeStationService {
                             equipment.ConnectorInfos.filter((connector: any) => connector.Status === '待机').length
                         );
                     }, 0);
-                    let imgUrl = station.image? EXPO_PUBLIC_API_IMG_URL + station.image : null
+                    let imgUrl = station.image ? EXPO_PUBLIC_API_IMG_URL + station.image : null;
                     return {
                         stationID: snapshotData.StationID,
                         stationName: snapshotData.StationName,
@@ -329,7 +327,7 @@ class ChargeStationService {
 
     async noImagefetchChargeStationIdByScannedConnectorId(scannedConnectorId: string) {
         try {
-            const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/simple/info`, {
+            const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/local/simple/info`, {
                 headers: {
                     Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
                 }