浏览代码

feat: 修改

year 2 月之前
父节点
当前提交
36f47d4d3e
共有 2 个文件被更改,包括 48 次插入24 次删除
  1. 2 2
      src/api/depositsApi.ts
  2. 46 22
      src/app/[locale]/(TabBar)/deposit/DepositData.tsx

+ 2 - 2
src/api/depositsApi.ts

@@ -118,8 +118,8 @@ export interface ShopInfo {
     type: 1 | 2;
     products: ShopProductItem[];
     condition: {
-        Min: number;
-        Max: number;
+        min: number;
+        max: number;
     };
 }
 

+ 46 - 22
src/app/[locale]/(TabBar)/deposit/DepositData.tsx

@@ -14,7 +14,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, useMemo, useRef, useState } from "react";
+import { FC, useRef, useState } from "react";
 import { Swiper, SwiperSlide } from "swiper/react";
 import actions from "./actions";
 import Reward from "./Reward";
@@ -44,6 +44,7 @@ const DepositData: FC<Props> = (props) => {
     const t = useTranslations();
     // const router = useRouter();
     const userInfo = useUserInfoStore((state) => state.userInfo);
+    const [currentProduct, setCurrentProduct] = useState<any>(null);
     const { eventInitiate } = useEventPoint();
 
     const isStrictMode = useSystemStore((state) => state.identity_verify.deposit === 1);
@@ -63,17 +64,28 @@ const DepositData: FC<Props> = (props) => {
         formInstanceRef.current?.resetFields();
     };
 
-    const currentProduct = useMemo(() => {
+    // 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>({}); // 存放表单数据
+
+    const getCurrentProduct = (amount: number) => {
         if (!shopInfo?.products?.length) return null;
-        let result = shopInfo?.products?.find((item) => item.par_value === amount);
+
+        let result = shopInfo?.products?.find((item) => item.par_value === Number(amount));
         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>({}); // 存放表单数据
+        setCurrentProduct(result);
+    };
     const onFinish = async (values: any) => {
         if (!amount) return Toast.show({ content: t("form.amount") });
         const params = {
@@ -121,6 +133,7 @@ const DepositData: FC<Props> = (props) => {
     const onValuesChange = (changeValues: any) => {
         if (changeValues.amount) {
             setAmount(changeValues.amount);
+            getCurrentProduct(changeValues.amount);
         }
     };
     const amountChange = (value: number) => {
@@ -128,15 +141,18 @@ const DepositData: FC<Props> = (props) => {
         setAmount(value);
     };
     const amountValidator = (rules: any, value: any) => {
-        // if (!value) return Promise.reject(new Error(t("form.amount")));
-        // if (+value < activeType.min_amount!)
-        //     return Promise.reject(
-        //         new Error(t("form.amountMinReg", { amount: activeType.min_amount }))
-        //     );
-        // if (+value > activeType.max_amount!)
-        //     return Promise.reject(
-        //         new Error(t("form.amountMaxReg", { amount: activeType.max_amount }))
-        //     );
+        if (!value) return Promise.reject(new Error(t("form.amount")));
+        if (shopInfo?.condition) {
+            if (+value < shopInfo.condition.min)
+                return Promise.reject(
+                    new Error(t("form.amountMinReg", { amount: shopInfo.condition.min }))
+                );
+            if (+value > shopInfo.condition.max)
+                return Promise.reject(
+                    new Error(t("form.amountMaxReg", { amount: shopInfo.condition.max }))
+                );
+        }
+
         return Promise.resolve();
     };
 
@@ -208,12 +224,12 @@ const DepositData: FC<Props> = (props) => {
                         name="amount"
                         label=""
                         rules={[{ required: true, type: "number", validator: amountValidator }]}
-                        style={{ display: shopInfo?.type === 2 ? "block" : "none" }}
+                        // style={{ display: shopInfo?.type === 2 ? "block" : "none" }}
                     >
                         <Input
-                            placeholder={`${t("DepositPage.Montante")}: (${shopInfo?.condition?.Min}-${shopInfo?.condition?.Max})`}
+                            placeholder={`${t("DepositPage.Montante")}: (${shopInfo?.condition?.min}-${shopInfo?.condition?.max})`}
                             type={"number"}
-                            maxLength={shopInfo?.condition?.Max}
+                            maxLength={shopInfo?.condition?.max}
                         />
                     </Form.Item>
 
@@ -224,9 +240,17 @@ const DepositData: FC<Props> = (props) => {
                                     if (item.par_value <= 0) return null;
                                     return (
                                         <li
-                                            className={amount == item.par_value ? "active" : ""}
+                                            className={
+                                                amount == item.par_value &&
+                                                currentProduct?.id === item.id
+                                                    ? "active"
+                                                    : ""
+                                            }
                                             key={index}
-                                            onClick={() => amountChange(item.par_value)}
+                                            onClick={() => {
+                                                setCurrentProduct(item);
+                                                amountChange(item.par_value);
+                                            }}
                                         >
                                             {!!item.is_hot && <span className="hot"></span>}
                                             <div className="amountContent">