Bläddra i källkod

feat: 修改deposite

year 2 månader sedan
förälder
incheckning
dd2413605a
1 ändrade filer med 56 tillägg och 95 borttagningar
  1. 56 95
      src/app/[locale]/(TabBar)/deposit/DepositData.tsx

+ 56 - 95
src/app/[locale]/(TabBar)/deposit/DepositData.tsx

@@ -1,19 +1,22 @@
 "use client";
 import { DepositsTypes, PayChannel, ShopInfo } from "@/api/depositsApi";
+import { getUserMoneyApi, getUserRechargeApi } from "@/api/user";
 import Box from "@/components/Box";
 import ButtonOwn from "@/components/ButtonOwn";
 import TipsModal, { ModalProps } from "@/components/TipsModal";
+import { useEventPoint } from "@/hooks/useEventPoint";
 import { useSystemStore } from "@/stores/useSystemStore";
 import { useUserInfoStore } from "@/stores/useUserInfoStore";
 import "@/styles/deposit.scss";
 import { server } from "@/utils/client";
 import { neReg } from "@/utils/index";
-import { Button, Form, Input } from "antd-mobile";
+import { Button, Form, Input, Toast } from "antd-mobile";
 import { FormInstance } from "antd-mobile/es/components/form";
 import clsx from "clsx";
 import { useTranslations } from "next-intl";
 import { FC, useMemo, useRef, useState } from "react";
 import { Swiper, SwiperSlide } from "swiper/react";
+import actions from "./actions";
 import Reward from "./Reward";
 
 interface Props {
@@ -24,50 +27,6 @@ interface Props {
     setChannel?: (data: PayChannel) => void;
 }
 
-// interface RewardsProps {
-//     rewards: any;
-// }
-// const RewardsText: FC<RewardsProps> = (props) => {
-//     const { rewards } = props;
-//     // {/*1现金2彩金3免费币4重玩币*/}
-//     const t = useTranslations();
-//     const calcRewards = rewards
-//         .map((item) => {
-//             // let text = item.ratio > 0 ? `${item.ratio}%` : `${item.reward}`;
-//             // 根据coin_type添加后缀
-//             const suffixes = {
-//                 1: t("ProfilePage.balance"),
-//                 2: t("ProfilePage.bonus"),
-//                 3: t("ProfilePage.free"),
-//                 4: t("ProfilePage.replay"),
-//             };
-//             let text = "";
-//             // 设置基础奖励文本
-//             if (item.ratio > 0) {
-//                 text = `${item.ratio}%`;
-//             } else {
-//                 text = `${item.reward}`;
-//             }
-//             if (item.ratio > 0 && item.reward > 0) {
-//                 text = `${item.ratio}%${suffixes[item.coin_type]}, ${item.reward}`;
-//             }
-
-//             // 如果coin_type在suffixes中存在,则添加相应的后缀
-//             if (suffixes.hasOwnProperty(item.coin_type)) {
-//                 text += suffixes[item.coin_type];
-//             }
-
-//             return text;
-//         })
-//         .join(",");
-
-//     return (
-//         <div className={"flex flex-1 flex-wrap break-all"}>
-//             <span className="amountTips">+ {calcRewards} </span>
-//         </div>
-//     );
-// };
-
 const getDepositApi = async () => {
     return server
         .request<DepositsTypes[]>({
@@ -85,14 +44,10 @@ const DepositData: FC<Props> = (props) => {
     const t = useTranslations();
     // const router = useRouter();
     const userInfo = useUserInfoStore((state) => state.userInfo);
-    // const { eventInitiate } = useEventPoint();
+    const { eventInitiate } = useEventPoint();
 
     const isStrictMode = useSystemStore((state) => state.identity_verify.deposit === 1);
 
-    // const [depositState, setDepositState] = useState<DepositsTypes[]>([]);
-
-    // const [activeType, setActiveType] = useState<Partial<DepositsTypes>>({});
-
     const formInstanceRef = useRef<FormInstance>(null);
     let [amount, setAmount] = useState<number | undefined>(undefined);
 
@@ -108,54 +63,60 @@ const DepositData: FC<Props> = (props) => {
         formInstanceRef.current?.resetFields();
     };
 
-    const customProduct = useMemo(() => {
+    const currentProduct = useMemo(() => {
         if (!shopInfo?.products?.length) return null;
-        return shopInfo?.products?.find((item) => item.pay === 0);
-    }, [shopInfo?.products]);
-
-    console.log("customProduct", customProduct);
+        console.log("currentProduct", amount);
+        let result = shopInfo?.products?.find((item) => item.pay / 100 === amount);
+        if (!result) {
+            result = shopInfo?.products?.find((item) => item.pay === 0);
+        }
+        return result;
+    }, [shopInfo?.products, amount]);
 
     const tipModelRef = useRef<ModalProps>(null); // 充值清空打码量弹窗
-    // const [formData, setFormData] = useState<any>({}); // 存放表单数据
-    // const onFinish = async (values: any) => {
-    //     const params = { ...values, channel_id: activeType.id, amount: +values.amount };
-    //     const res = await getUserMoneyApi();
-    //     if (res.data?.tips_reset_rollover) {
-    //         tipModelRef.current?.onOpen();
-    //         setFormData(params);
-    //         return;
-    //     }
-    //     handleUserRecharge(false, params);
-    // };
-    const handleUserRecharge = (type: boolean) => {};
-    // const handleUserRecharge = (is_reset_rollover: boolean, data?: any) => {
-    //     let params = data || formData;
-    //     getUserRechargeApi({ is_reset_rollover, ...params })
-    //         .then(async (res) => {
-    //             formInstanceRef.current?.resetFields();
-    //             tipModelRef.current?.onClose();
-    //             setAmount(undefined);
-    //             // const url =
-    //             //     "https://caixa.pay4z.com/brl/qrcode.html?tradeNo=T2501180056ijk21kJ&amount=20&payAmount=20&currency=BRL&expiredAt=2025-01-18%2001%3A11%3A31&expire=1737173491282&raw=00020101021226870014br.gov.bcb.pix2565qrcode.santsbank.com%2Fdynamic%2Fdc8cf003-1616-47f8-94e6-16be500d05b45204000053039865802BR5907LF%20LTDA6009Sao%20Paulo62070503***6304DF54&type=QRCODE";
+    const [formData, setFormData] = useState<any>({}); // 存放表单数据
+    const onFinish = async (values: any) => {
+        const params = {
+            ...values,
+            channel_id: currentChannel?.id,
+            amount: +values.amount,
+            prod_id: currentProduct?.id,
+        };
+        const res = await getUserMoneyApi();
+        if (res.data?.tips_reset_rollover) {
+            tipModelRef.current?.onOpen();
+            setFormData(params);
+            return;
+        }
+        handleUserRecharge(false, params);
+    };
+    // const handleUserRecharge = (type: boolean) => {};
+    const handleUserRecharge = async (is_reset_rollover: boolean, data?: any) => {
+        let params = data || formData;
+
+        try {
+            const res = await getUserRechargeApi({ is_reset_rollover, ...params });
+            formInstanceRef.current?.resetFields();
+            tipModelRef.current?.onClose();
+            setAmount(undefined);
+            // const url =
+            //     "https://caixa.pay4z.com/brl/qrcode.html?tradeNo=T2501180056ijk21kJ&amount=20&payAmount=20&currency=BRL&expiredAt=2025-01-18%2001%3A11%3A31&expire=1737173491282&raw=00020101021226870014br.gov.bcb.pix2565qrcode.santsbank.com%2Fdynamic%2Fdc8cf003-1616-47f8-94e6-16be500d05b45204000053039865802BR5907LF%20LTDA6009Sao%20Paulo62070503***6304DF54&type=QRCODE";
 
-    //             if (res.data.pay_url) {
-    //                 eventInitiate();
-    //                 // fix: ios 限制
-    //                 setTimeout(() => {
-    //                     window.open(res.data.pay_url);
-    //                 }, 0);
-    //             } else {
-    //                 Toast.show({ icon: "success", content: t("code.200"), maskClickable: false });
-    //             }
-    //             const data = await getDepositApi();
-    //             setDepositState(data);
-    //             setActiveType(data[0]);
-    //             await actions();
-    //         })
-    //         .catch((error) => {
-    //             Toast.show({ content: t(`code.${error.data.code}`), maskClickable: false });
-    //         });
-    // };
+            if (res.data.pay_url) {
+                eventInitiate();
+                // fix: ios 限制
+                setTimeout(() => {
+                    window.open(res.data.pay_url);
+                }, 0);
+            } else {
+                Toast.show({ icon: "success", content: t("code.200"), maskClickable: false });
+            }
+
+            await actions();
+        } catch (error: any) {
+            Toast.show({ content: t(`code.${error.data.code}`), maskClickable: false });
+        }
+    };
 
     const onValuesChange = (changeValues: any) => {
         if (changeValues.amount) {
@@ -219,7 +180,7 @@ const DepositData: FC<Props> = (props) => {
                         </>
                     }
                     initialValues={userInfo}
-                    // onFinish={onFinish}
+                    onFinish={onFinish}
                     onValuesChange={onValuesChange}
                 >
                     {isStrictMode ? (