"use client"; // import Link from "next/link"; // 轮播逻辑 import { Swiper, SwiperSlide } from "swiper/react"; import { Navigation, Scrollbar } from "swiper/modules"; import type { Swiper as SwiperType } from "swiper/types"; import { useEffect, useState } from "react"; import Image from "next/image"; import "swiper/css"; import "swiper/css/navigation"; import { clientFetch } from "@/lib/restApiClient"; // 模拟你的每一页数据,方便维护 const vipList = [ { level: 1, title: "V1 Privileges", exppoints: 1000, coupons: [ { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png", text1: "Points Redeem", text2: "Giftcard", link: "javascript:void(0)", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png", text1: "Exclusive", text2: "$100 Coupon", link: "javascript:void(0)", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png", text1: "Birthday", text2: "Treat", link: "javascript:void(0)", }, ], }, { level: 2, title: "V2 Privileges", exppoints: 2000, coupons: [ { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png", text1: "POINTS REDEEM", text2: "GIFTCARD", link: "javascript:void(0)", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png", text1: "EXCLUSIVE", text2: "$150 COUPON", link: "javascript:void(0)", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png", text1: "BIRTHDAY", text2: "TREAT", link: "javascript:void(0)", }, ], }, { level: 3, title: "V3 Privileges", exppoints: 10000, coupons: [ { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png", text1: "POINTS REDEEM", text2: "GIFTCARD", link: "javascript:void(0)", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png", text1: "EXCLUSIVE", text2: "$200 COUPON", link: "javascript:void(0)", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png", text1: "BIRTHDAY", text2: "TREAT", link: "javascript:void(0)", }, ], }, { level: 4, title: "V4 Privileges", exppoints: 50000, coupons: [ { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png", text1: "POINTS REDEEM", text2: "GIFTCARD", link: "/customer/account/pointsreceivelist", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png", text1: "EXCLUSIVE", text2: "$300 COUPON", link: "/customer/account/couponsreceivelist/v/4/", }, { img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png", text1: "BIRTHDAY", text2: "TREAT", link: "/customer/account/birthday", }, ], }, ]; export default function AccountVipPopup({ visible, onClose, }: { visible: boolean; onClose: () => void; }) { // 当前slide下标 const [activeIndex, setActiveIndex] = useState(0); const [VipGrothData, setVipGrothData] = useState(null); // 如果不显示,直接 return null useEffect(() => { const fetchGrothValue = async () => { try { const res = await clientFetch("/api/customer/growth-value"); if (res.success) { setVipGrothData(res.data); console.log("vip成长值数据:", res.data); } } catch (error) { console.error("获取vip成长值失败:", error); } }; fetchGrothValue(); }, []); if (!visible) return null; // 滑动切换触发 const handleSlideChange = (swiper: SwiperType) => { setActiveIndex(swiper.activeIndex); console.log("aaa slide huadongle "); }; const slideItem = vipList[activeIndex]; const slideLevelNum = slideItem?.level ?? 1; const progressPercent = VipGrothData ? Math.min( Math.max( (VipGrothData.growth_value / VipGrothData.next_level.min_growth_value) * 100, 0, ), 100, ) : 0; const userCurrentLevelNum = Number(VipGrothData?.current_level.name.replace(/[^0-9]/g, "")) || 0; let showText = ""; console.log("userCurrentLevelNum", userCurrentLevelNum, slideLevelNum); if (userCurrentLevelNum === slideLevelNum) { showText = `Growth Value ${VipGrothData?.growth_value}/${VipGrothData?.next_level.min_growth_value}`; } else if (userCurrentLevelNum > slideLevelNum) { showText = "aaa"; } else { showText = `Integral to 2000`; } return ( // 全屏遮罩
{/* 弹框主体 - 从底部滑上来 */}
{/* 顶部导航 */}

Vip Center

Vip {userCurrentLevelNum}

18567768101@163.com

Above current level

{showText}
{/* 轮播 */}
{vipList.map((item, idx) => ( {/* 标题 */}

{item.title}

{/* 权益卡片容器 */}
{item.coupons.map((coupon, cIdx) => ( ))}
))} {/* 自定义左右按钮,放在Swiper内部,同级slide */}
); }