|
@@ -1,8 +1,11 @@
|
|
|
"use client";
|
|
|
|
|
|
-import { lredPacketApi, receiveRedPacketApi, redPacketApi } from "@/api/promo";
|
|
|
+import { receiveRedPacketApi } from "@/api/promo";
|
|
|
+import { useRouter } from "@/i18n";
|
|
|
import { getToken } from "@/utils/Cookies";
|
|
|
import { Mask } from "antd-mobile";
|
|
|
+import clsx from "clsx";
|
|
|
+import { useTranslations } from "next-intl";
|
|
|
import Image from "next/image";
|
|
|
import { forwardRef, Fragment, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
|
import styles from "./redpacked.module.scss";
|
|
@@ -252,13 +255,21 @@ const FallAnimation = (props: any) => {
|
|
|
|
|
|
const HbyInfoDetail = (props: any) => {
|
|
|
const { iconImg, onCloseHby } = props;
|
|
|
+ const router = useRouter();
|
|
|
+ const token = getToken();
|
|
|
+ const handler = () => {
|
|
|
+ if (!token) {
|
|
|
+ router.push("/login");
|
|
|
+ }
|
|
|
+ onCloseHby();
|
|
|
+ };
|
|
|
return (
|
|
|
<div
|
|
|
className={`absolute left-1/2 top-[50%] w-[90%] -translate-x-1/2 -translate-y-1/2 ${styles.promoRules}`}
|
|
|
>
|
|
|
{/* <Image src={"/hby/close.png"} alt={"close"} width={25} height={25} onClick={onCloseHby} className={styles.closeIcon}/> */}
|
|
|
<div onClick={onCloseHby} className={styles.closeIcon}></div>
|
|
|
- <Image src={iconImg} alt={"detail"} width={672} height={1044} />
|
|
|
+ <Image src={iconImg} onClick={handler} alt={"detail"} width={672} height={1044} />
|
|
|
{/* <div className={`h-[0.15rem] text-[#ffd800] text-[0.20rem] text-center ${styles.promoTitle}`}>Dinheiro como chuva</div>
|
|
|
<div className={styles.titleWrap}>
|
|
|
<span>R$200.00</span>
|
|
@@ -335,9 +346,14 @@ const HbyInfo = (props: any) => {
|
|
|
|
|
|
const HbyInfo2 = (props: any) => {
|
|
|
const { iconImg, onCloseHby, redAmount } = props;
|
|
|
+ const hbyInfoClass = clsx(
|
|
|
+ `${styles.redopen} absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-no-repeat bg-cover`
|
|
|
+ );
|
|
|
+ const t = useTranslations("packetsPopup");
|
|
|
return (
|
|
|
<div
|
|
|
- className={`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 ${styles.redopen}`}
|
|
|
+ className={hbyInfoClass}
|
|
|
+ style={{ background: `url(${iconImg})`, backgroundSize: "100% 100%" }}
|
|
|
>
|
|
|
<Image
|
|
|
src={"/hby/close.png"}
|
|
@@ -347,12 +363,12 @@ const HbyInfo2 = (props: any) => {
|
|
|
onClick={onCloseHby}
|
|
|
className={styles.closeIcon}
|
|
|
/>
|
|
|
- {/* <div onClick={onCloseHby} className={styles.closeIcon}></div> */}
|
|
|
- <Image src={iconImg} alt={"icon"} width={559} height={687} />
|
|
|
+
|
|
|
+ <div className={styles.title}>{t("title")}</div>
|
|
|
<div className={styles.cash}>{redAmount}</div>
|
|
|
- {/* <div className={styles.title}>Chuva de dinheiro</div>
|
|
|
- <div className={styles.cash}>{redAmount}</div>
|
|
|
- <div className={styles.tips}>Valor máximo de queda em dinheiro:Cada sessäo de chuva de dinheiro é </div> */}
|
|
|
+ <div className={styles.tips}>
|
|
|
+ {redAmount > 0 ? t("receiveSuccess") : t("receiveWarring")}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
);
|
|
|
};
|
|
@@ -362,7 +378,7 @@ type Props = {
|
|
|
};
|
|
|
export type RedPacketModalProps = {
|
|
|
onClose: () => void;
|
|
|
- onOpen: (index?: number) => void;
|
|
|
+ onOpen: (source: any[], index?: number) => void;
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -383,15 +399,17 @@ const RedPacketModal = forwardRef<RedPacketModalProps, Props>(function RedPacket
|
|
|
const [iconLists, setIconLists] = useState<any>([]);
|
|
|
// 初始状态为is_end, 展示活动详情页
|
|
|
const [status, setStatus] = useState<Status>(Status.is_end);
|
|
|
- const packet = useRef<any>({});
|
|
|
+ const packetCurrent = useRef<any>({});
|
|
|
+ const packets = useRef<any[]>([]);
|
|
|
|
|
|
- const [redAmount, setRedAmount] = useState<any>(0);
|
|
|
+ const [redAmount, setRedAmount] = useState<any>(1);
|
|
|
const activeIndex = useRef<number>(0);
|
|
|
const token = getToken();
|
|
|
useImperativeHandle(ref, () => {
|
|
|
return {
|
|
|
onClose: () => setVisible(false),
|
|
|
- onOpen: (index?: number) => {
|
|
|
+ onOpen: (source, index?: number) => {
|
|
|
+ packets.current = source;
|
|
|
if (index !== null && index !== undefined) {
|
|
|
activeIndex.current = index;
|
|
|
}
|
|
@@ -402,41 +420,35 @@ const RedPacketModal = forwardRef<RedPacketModalProps, Props>(function RedPacket
|
|
|
},
|
|
|
};
|
|
|
});
|
|
|
- useEffect(() => {
|
|
|
- // getRedPacketInfo();
|
|
|
- }, []);
|
|
|
|
|
|
const getRedPacketInfo = async () => {
|
|
|
try {
|
|
|
- let actList: any = [];
|
|
|
- if (token) {
|
|
|
- let redPacketInfo = await lredPacketApi();
|
|
|
- actList = redPacketInfo.data?.red_packets || [];
|
|
|
- } else {
|
|
|
- let redPacketInfo = await redPacketApi();
|
|
|
- actList = redPacketInfo.data;
|
|
|
- }
|
|
|
+ let actList = packets.current;
|
|
|
// 是否有已开始但是没领过的红包
|
|
|
- let packets = actList
|
|
|
+ let packetsFilter = actList
|
|
|
.filter((aItem: any) => {
|
|
|
return aItem.is_start && !aItem.is_receive;
|
|
|
})
|
|
|
.sort((pre: any, next: any) => pre.end_time - next.end_time);
|
|
|
|
|
|
// 有可领取红包
|
|
|
- if (packets.length > 0) {
|
|
|
- let current = packets[activeIndex.current];
|
|
|
+ if (packetsFilter.length > 0) {
|
|
|
+ let current = packetsFilter[activeIndex.current];
|
|
|
let iconList = JSON.parse(current.icon);
|
|
|
// 红包
|
|
|
- packet.current = current;
|
|
|
+ packetCurrent.current = current;
|
|
|
// 有可领取红包
|
|
|
- setStatus(Status.is_start);
|
|
|
setIconLists(iconList);
|
|
|
+ if (!token) {
|
|
|
+ setStatus(Status.is_end);
|
|
|
+ } else {
|
|
|
+ setStatus(Status.is_start);
|
|
|
+ }
|
|
|
} else {
|
|
|
// 无可领取红包
|
|
|
// 展示最近可领红包详情
|
|
|
let packets = actList.sort((pre: any, next: any) => pre.end_time - next.end_time);
|
|
|
- packet.current = packets[0];
|
|
|
+ packetCurrent.current = packets[0];
|
|
|
setIconLists(JSON.parse(packets[0].icon));
|
|
|
// 无可领取红包展示详情
|
|
|
setStatus(Status.is_end);
|
|
@@ -449,8 +461,8 @@ const RedPacketModal = forwardRef<RedPacketModalProps, Props>(function RedPacket
|
|
|
const onReciveRed = async () => {
|
|
|
try {
|
|
|
let paramsData = {
|
|
|
- id: packet.current?.id,
|
|
|
- index: packet.current?.index,
|
|
|
+ id: packetCurrent.current?.id,
|
|
|
+ index: packetCurrent.current?.index,
|
|
|
};
|
|
|
let receiveRedPacketInfo = await receiveRedPacketApi(paramsData);
|
|
|
let redNum = receiveRedPacketInfo.data;
|