|
@@ -1,19 +1,100 @@
|
|
|
"use client";
|
|
|
/* eslint-disable @next/next/no-img-element */
|
|
|
+import { claimActivityReward } from "@/api/activity";
|
|
|
+import { UserVipInfo } from "@/api/user";
|
|
|
+import GlobalNotify from "@/components/ModalPopup/GlobalNotifyModal";
|
|
|
import { BoxListCom } from "@/components/ModalPopup/SignInModal";
|
|
|
import { useSignStore } from "@/stores/useSignStore";
|
|
|
+import { formatAmount } from "@/utils";
|
|
|
+import { server } from "@/utils/client";
|
|
|
+import { Toast } from "antd-mobile";
|
|
|
+import BigNumber from "bignumber.js";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
-import { FC, useEffect } from "react";
|
|
|
+import { useSearchParams } from "next/navigation";
|
|
|
+import { FC, useEffect, useMemo, useState } from "react";
|
|
|
+
|
|
|
+const getVipApi = async () => {
|
|
|
+ return server
|
|
|
+ .request<UserVipInfo>({
|
|
|
+ url: "/v1/api/user/user_vip_info",
|
|
|
+ method: "POST",
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code === 200) return res.data;
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
const SignIn: FC = () => {
|
|
|
+ const searchParams = useSearchParams();
|
|
|
+ const activity_id = Number(searchParams.get("activity_id"));
|
|
|
const t = useTranslations("signInPage");
|
|
|
+ const tCode = useTranslations();
|
|
|
+ const [vipInfo, setVipInfo] = useState<UserVipInfo | null>(null);
|
|
|
+ const [visible, setVisible] = useState(false);
|
|
|
+ const [amount, setAmount] = useState({});
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getVipInfo();
|
|
|
+ }, []);
|
|
|
+ const getVipInfo = async () => {
|
|
|
+ const vipInfoRes = await getVipApi();
|
|
|
+ if (vipInfoRes) {
|
|
|
+ setVipInfo(vipInfoRes);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const { getSignData, signData } = useSignStore((state) => ({
|
|
|
signData: state.signData,
|
|
|
getSignData: state.getSignData,
|
|
|
}));
|
|
|
useEffect(() => {
|
|
|
- getSignData({ active_id: 3 });
|
|
|
+ getSignData({ activity_id });
|
|
|
}, []);
|
|
|
+
|
|
|
+ const curData = useMemo(() => {
|
|
|
+ if (!signData || !signData.list || signData.cur_num == undefined) return null;
|
|
|
+ return signData.list[signData.cur_num];
|
|
|
+ }, [signData]);
|
|
|
+
|
|
|
+ const doClaim = async () => {
|
|
|
+ if (!curData) return null;
|
|
|
+ try {
|
|
|
+ const res = await claimActivityReward({
|
|
|
+ activity_id,
|
|
|
+ id: curData.id as number,
|
|
|
+ });
|
|
|
+ if (res.code === 200 && res?.data?.code === 1) {
|
|
|
+ getSignData({ activity_id });
|
|
|
+ if (res?.data?.reward) {
|
|
|
+ const amountObj: any = {};
|
|
|
+ res?.data?.reward.forEach((item: any) => {
|
|
|
+ amountObj[`coin_${item.coin_type}`] = formatAmount(item.amount);
|
|
|
+ });
|
|
|
+ //extra_reward
|
|
|
+ res?.data?.reward.forEach((item: any) => {
|
|
|
+ amountObj[`coin_${item.coin_type}`] = formatAmount(
|
|
|
+ new BigNumber(amountObj[`coin_${item.coin_type}`] || 0)
|
|
|
+ .plus(item.amount)
|
|
|
+ .toString()
|
|
|
+ );
|
|
|
+ });
|
|
|
+ setAmount(amountObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ setVisible(true);
|
|
|
+ } else {
|
|
|
+ throw new Error(tCode(`code.400`));
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ if (error) {
|
|
|
+ Toast.show({
|
|
|
+ content: error.message || error.toString(),
|
|
|
+ maskClickable: false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<div className="relative h-[100%] w-[100%]">
|
|
@@ -37,7 +118,7 @@ const SignIn: FC = () => {
|
|
|
/>
|
|
|
<div className="relative left-[10%] h-[100%]">
|
|
|
<p className="h-[50%] text-[0.12rem] font-bold leading-[0.2rem]">
|
|
|
- VIP0
|
|
|
+ VIP {vipInfo?.vip_level || 0}
|
|
|
</p>
|
|
|
<p className="h-[50%] text-[0.1rem] font-bold leading-[0.12rem]">
|
|
|
quanto maior o nível VlP, mais abundantes s?o as recompensas
|
|
@@ -67,7 +148,10 @@ const SignIn: FC = () => {
|
|
|
<PayBoxList type="page" />
|
|
|
</div> */}
|
|
|
{/* 签到按钮 */}
|
|
|
- <div className={"relative mt-[0.25rem] flex h-[.6045rem] justify-center"}>
|
|
|
+ <div
|
|
|
+ className={"relative mt-[0.25rem] flex h-[.6045rem] justify-center"}
|
|
|
+ onClick={doClaim}
|
|
|
+ >
|
|
|
<img src="/sign/button.png" className={"h-[100%]"} alt="" />
|
|
|
<span className="absolute text-[0.16rem] font-bold leading-[0.375rem] text-[white]">
|
|
|
Sign-in
|
|
@@ -101,6 +185,12 @@ const SignIn: FC = () => {
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <GlobalNotify
|
|
|
+ amount={amount}
|
|
|
+ visible={visible}
|
|
|
+ onChange={() => setVisible(false)}
|
|
|
+ deraction={5000}
|
|
|
+ ></GlobalNotify>
|
|
|
</div>
|
|
|
</>
|
|
|
);
|