|
@@ -1,8 +1,9 @@
|
|
|
"use client";
|
|
|
-import { DepositsTypes, PayChannel, ShopInfo } from "@/api/depositsApi";
|
|
|
+import { DepositsTypes, PayChannel, ShopInfo, ShopProductItem } from "@/api/depositsApi";
|
|
|
import { getUserMoneyApi, getUserRechargeApi } from "@/api/user";
|
|
|
import Box from "@/components/Box";
|
|
|
import ButtonOwn from "@/components/ButtonOwn";
|
|
|
+import Empty from "@/components/Empty";
|
|
|
import TipsModal, { ModalProps } from "@/components/TipsModal";
|
|
|
import { useEventPoint } from "@/hooks/useEventPoint";
|
|
|
import { useSystemStore } from "@/stores/useSystemStore";
|
|
@@ -14,7 +15,7 @@ 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, useRef, useState } from "react";
|
|
|
+import { FC, useEffect, useMemo, useRef, useState } from "react";
|
|
|
import { Swiper, SwiperSlide } from "swiper/react";
|
|
|
import actions from "./actions";
|
|
|
import Reward from "./Reward";
|
|
@@ -46,6 +47,8 @@ const DepositData: FC<Props> = (props) => {
|
|
|
// const router = useRouter();
|
|
|
const userInfo = useUserInfoStore((state) => state.userInfo);
|
|
|
const [currentProduct, setCurrentProduct] = useState<any>(null);
|
|
|
+ const [btns, setBtns] = useState<ShopProductItem[]>([]);
|
|
|
+ const [formInput, setFormInput] = useState<ShopProductItem | null>(null);
|
|
|
const { eventInitiate } = useEventPoint();
|
|
|
|
|
|
const isStrictMode = useSystemStore((state) => state.identity_verify.deposit === 1);
|
|
@@ -53,37 +56,37 @@ const DepositData: FC<Props> = (props) => {
|
|
|
const formInstanceRef = useRef<FormInstance>(null);
|
|
|
let [amount, setAmount] = useState<number | undefined>(undefined);
|
|
|
|
|
|
- // useEffect(() => {
|
|
|
- // if (props.onActiveChange) {
|
|
|
- // props.onActiveChange(activeType as DepositsTypes);
|
|
|
- // }
|
|
|
- // }, [activeType]);
|
|
|
-
|
|
|
const titleChangeHandler = (data: PayChannel) => {
|
|
|
setAmount(undefined);
|
|
|
if (typeof setChannel === "function") setChannel(data);
|
|
|
formInstanceRef.current?.resetFields();
|
|
|
};
|
|
|
|
|
|
- // const currentProduct = useMemo(() => {
|
|
|
- // if (!shopInfo?.products?.length) return null;
|
|
|
- // let result = shopInfo?.products?.find((item) => item.par_value === amount);
|
|
|
- // console.log(result);
|
|
|
- // if (!result) {
|
|
|
- // result = shopInfo?.products?.find((item) => item.par_value === 0);
|
|
|
- // }
|
|
|
- // return result;
|
|
|
- // }, [shopInfo?.products, amount]);
|
|
|
-
|
|
|
const tipModelRef = useRef<ModalProps>(null); // 充值清空打码量弹窗
|
|
|
const [formData, setFormData] = useState<any>({}); // 存放表单数据
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (shopInfo?.products?.length) {
|
|
|
+ const normalProduct: ShopProductItem[] = [];
|
|
|
+ let formProduct = null;
|
|
|
+ shopInfo?.products.forEach((item) => {
|
|
|
+ if (item.type === 2) {
|
|
|
+ formProduct = item;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ normalProduct.push(item);
|
|
|
+ });
|
|
|
+
|
|
|
+ setFormInput(formProduct);
|
|
|
+ setBtns(normalProduct);
|
|
|
+ }
|
|
|
+ }, [shopInfo]);
|
|
|
+
|
|
|
const getCurrentProduct = (amount: number) => {
|
|
|
if (!shopInfo?.products?.length) return null;
|
|
|
-
|
|
|
let result = shopInfo?.products?.find((item) => item.par_value === Number(amount));
|
|
|
if (!result) {
|
|
|
- result = shopInfo?.products?.find((item) => item.par_value === 0);
|
|
|
+ result = shopInfo?.products?.find((item) => item.type === 2);
|
|
|
}
|
|
|
setCurrentProduct(result);
|
|
|
};
|
|
@@ -166,6 +169,14 @@ const DepositData: FC<Props> = (props) => {
|
|
|
return Promise.resolve();
|
|
|
};
|
|
|
|
|
|
+ const isEmpty = useMemo(() => {
|
|
|
+ if (btns?.length === 0 && !formInput) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }, [shopInfo]);
|
|
|
+
|
|
|
// useLayoutEffect(() => {
|
|
|
// getDepositApi().then((data) => {
|
|
|
// setDepositState(data);
|
|
@@ -173,7 +184,7 @@ const DepositData: FC<Props> = (props) => {
|
|
|
// });
|
|
|
// }, []);
|
|
|
|
|
|
- // if (!depositState.length) return <Empty />;
|
|
|
+ if (isEmpty) return <Empty />;
|
|
|
|
|
|
return (
|
|
|
<div className="deposit-box">
|
|
@@ -202,7 +213,9 @@ const DepositData: FC<Props> = (props) => {
|
|
|
ref={formInstanceRef}
|
|
|
footer={
|
|
|
<>
|
|
|
- <ButtonOwn active>{t("DepositPage.DepositarAgora")}</ButtonOwn>
|
|
|
+ {!isEmpty && (
|
|
|
+ <ButtonOwn active>{t("DepositPage.DepositarAgora")}</ButtonOwn>
|
|
|
+ )}
|
|
|
</>
|
|
|
}
|
|
|
initialValues={userInfo}
|
|
@@ -234,7 +247,7 @@ const DepositData: FC<Props> = (props) => {
|
|
|
name="amount"
|
|
|
label=""
|
|
|
rules={[{ required: true, type: "number", validator: amountValidator }]}
|
|
|
- style={{ display: shopInfo?.type === 2 ? "block" : "none" }}
|
|
|
+ style={{ display: formInput ? "block" : "none" }}
|
|
|
>
|
|
|
<Input
|
|
|
placeholder={`${t("DepositPage.Montante")}: (${currentShop?.condition?.min}-${currentShop?.condition?.max})`}
|
|
@@ -246,7 +259,7 @@ const DepositData: FC<Props> = (props) => {
|
|
|
<div className={"flex flex-col"}>
|
|
|
<div className={"flex-1"}>
|
|
|
<ul className="ul-box">
|
|
|
- {shopInfo?.products?.map((item, index) => {
|
|
|
+ {btns?.map((item, index) => {
|
|
|
if (item.par_value <= 0) return null;
|
|
|
return (
|
|
|
<li
|
|
@@ -277,10 +290,12 @@ const DepositData: FC<Props> = (props) => {
|
|
|
</div>
|
|
|
</div>
|
|
|
</Form>
|
|
|
+
|
|
|
<div className={"mt-[5px] text-[0.12rem] text-[#3af3ff]"}>
|
|
|
{t("DepositPage.depositTips")}
|
|
|
</div>
|
|
|
</Box>
|
|
|
+
|
|
|
<TipsModal title={"Tips"} ref={tipModelRef}>
|
|
|
<div className={"flex items-center justify-between"}>
|
|
|
<h2 className={"text-[0.14rem]"}>Mantenha Bônus</h2>
|