"use client"; import { getWheelApi, WheelsType } from "@/api/cashWheel"; import Progress from "@/app/[locale]/(navbar)/cashback/@cashbackInfo/components/Progress"; import { useRouter } from "@/i18n/routing"; import { getToken } from "@/utils/Cookies"; import { percentage, timeFormat } from "@/utils/methods"; import { LuckyWheel } from "@lucky-canvas/react"; import { Mask } from "antd-mobile"; import Image from "next/image"; import { FC, forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react"; import styles from "./WheelModal.module.scss"; type Props = { onAfterHandler?: () => void; }; export type WheelModalProps = { onClose: () => void; onOpen: (value: WheelsType) => void; }; /** * 轮盘组件 */ const blocks = [ { padding: "0", imgs: [ { src: "/wheels/wheel.png", width: "100%", height: "100%", rotate: true, }, ], }, ]; const prizes = [ { fonts: [ { text: "5000", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { fonts: [{ text: "", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "empty" }], imgs: [ { src: "/wheels/prizes-empty.png", top: "20%", width: "0.2778rem", }, ], }, { fonts: [ { text: "50", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { fonts: [ { text: "", top: "30%", fontColor: "#a47716", fontWeight: "bold", type: "balance" }, ], imgs: [ { src: "/wheels/prizes-money.png", top: "20%", width: "0.3472rem", }, ], }, { fonts: [ { text: "1000", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { imgs: [ { src: "/wheels/prizes-empty.png", top: "20%", width: "0.2778rem", height: "0.2778rem", }, ], }, { fonts: [ { text: "1", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "bonus", fontSize: "0.1528rem", }, ], }, { fonts: [ { text: "", top: "20%", fontColor: "#a47716", fontWeight: "bold", type: "balance", fontSize: "0.1528rem", }, ], imgs: [ { src: "/wheels/prizes-money.png", top: "20%", width: "0.3472rem", }, ], }, ]; const defaultConfig = { offsetDegree: 20, }; /** * type: isRotate 是否可旋转, 分享页面不需要旋转, 而是跳转 */ export interface WheelProps { isRotate: boolean; wheel: Partial; onRotateEnd?: () => void; } export const WheelClient: FC = (props) => { const { isRotate, wheel, onRotateEnd } = props; const wheelRef = useRef(); /*是否旋转*/ const rotating = useRef(false); const router = useRouter(); const current = { ...(wheel?.activities?.[0] || {}), ...(wheel?.activate || {}) }; const [buttonText, setButtonText] = useState("0"); // 0 -> false 1:true // 当前中奖 const currentWin = useRef({}); const startRotate = (key: string) => { if (!isRotate) { router.push("/register"); return; } // 正在旋转中 if (rotating.current) return; if (!current.can) return; // 如果包含还没领取的奖励 if (wheel.not_receive && wheel.not_receive.length > 0) return; // 当前活动不存在 if (!current.id) return; // 开始旋转中 wheelRef.current?.play(); // 点击抽奖按钮会触发star回调 rotating.current = true; // getWheelRunApi({ activity_id: current.id }) // .then((res) => { // setTimeout(() => { // wheelRef.current?.stop(res.data.index); // // currentWin.current = res.data; // }, 2000); // }) // .catch(() => { // wheelRef.current?.init(); // }); }; const endRotate = (prize: any) => { rotating.current = false; if (currentWin.current.amount > 0) { setButtonText(`+${currentWin.current.amount}`); } else { setButtonText(`${current.can || 0}`); } setTimeout(() => { onRotateEnd && onRotateEnd(); }, 2000); }; useEffect(() => { setButtonText(`${current.can || 0}`); }, [wheel]); return (
{/*定位到中心圆*/}
{/*光圈图片 */}
{/*转盘*/}
startRotate("desktop")} > {"start"} {buttonText}
endRotate(prize)} />
); }; export const LeftListClient = () => { const allHistory: any[] = Array.from({ length: 100 }).map((item) => ({ phone_number: `55****${Math.floor(Math.random() * 10000) .toString() .padStart(4, "0")}`, receive_time: Date.now(), })); return ( <>
{allHistory && allHistory.length > 0 && allHistory?.map((item, index) => { return (
{item.phone_number} {timeFormat(item.receive_time, "br", undefined, true)}
+100 R$
); })}
); }; const DetailClient = (props: { wheel: Partial; onUnload: () => void }) => { const { wheel, onUnload } = props; const router = useRouter(); const goPage = () => { router.push("/cashWheel"); onUnload(); }; return (
{" "} R$ {wheel.activate?.amount}
SACAR{" "}
{percentage(wheel.activate?.amount || 0, 100)}%
{/*
*/} {/* */} {/*
*/}
Ainda e necessário{" "} {(100 - (wheel.activate?.amount || 0)).toFixed(2)} {" "} para realizar do saque{" "}
Reivindique mais para sacar
); }; const WheelModal = forwardRef(function RedPacketModal(props, ref) { const [visible, setVisible] = useState(false); const [detailsVisible, setDetailsVisible] = useState(false); const [wheel, setWheel] = useState>({}); useImperativeHandle(ref, () => { return { onClose: () => setVisible(false), onOpen: (wheelValue: WheelsType) => { setVisible(true); setWheel(wheelValue); }, }; }); const getWheel = () => { if (!getToken()) return Promise.resolve(undefined); return getWheelApi().then((res) => { setWheel(res.data); return res.data; }); }; // useEffect(() => { // getWheel().then((res) => { // if ( // res && // res.activities && // res.activities.length > 0 && // res.activate.can && // !res.not_receive?.length // ) { // setVisible(true); // } // }); // }, []); const onRotateEnd = () => { setTimeout(() => { setVisible(false); setDetailsVisible(true); getWheel(); }, 1000); }; const onUnload = () => { setDetailsVisible(false); }; return ( <>
{"moeny"} Receba R$ 100 de graca
setDetailsVisible(false)} >
setVisible(false)} >
); }); export default WheelModal;