AccountVipPopup.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. "use client";
  2. // import Link from "next/link";
  3. // 轮播逻辑
  4. import { Swiper, SwiperSlide } from "swiper/react";
  5. import { Navigation, Scrollbar } from "swiper/modules";
  6. import { Swiper as SwiperType } from "swiper/types";
  7. import { useEffect, useState } from "react";
  8. import Image from "next/image";
  9. import "swiper/css";
  10. import "swiper/css/navigation";
  11. import { clientFetch } from "@/lib/restApiClient";
  12. // 模拟你的每一页数据,方便维护
  13. const vipList = [
  14. {
  15. level: 1,
  16. title: "V1 Privileges",
  17. exppoints: 1000,
  18. coupons: [
  19. {
  20. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png",
  21. text1: "Points Redeem",
  22. text2: "Giftcard",
  23. link: "javascript:void(0)",
  24. },
  25. {
  26. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png",
  27. text1: "Exclusive",
  28. text2: "$100 Coupon",
  29. link: "javascript:void(0)",
  30. },
  31. {
  32. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png",
  33. text1: "Birthday",
  34. text2: "Treat",
  35. link: "javascript:void(0)",
  36. },
  37. ],
  38. },
  39. {
  40. level: 2,
  41. title: "V2 Privileges",
  42. exppoints: 2000,
  43. coupons: [
  44. {
  45. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png",
  46. text1: "POINTS REDEEM",
  47. text2: "GIFTCARD",
  48. link: "javascript:void(0)",
  49. },
  50. {
  51. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png",
  52. text1: "EXCLUSIVE",
  53. text2: "$150 COUPON",
  54. link: "javascript:void(0)",
  55. },
  56. {
  57. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png",
  58. text1: "BIRTHDAY",
  59. text2: "TREAT",
  60. link: "javascript:void(0)",
  61. },
  62. ],
  63. },
  64. {
  65. level: 3,
  66. title: "V3 Privileges",
  67. exppoints: 10000,
  68. coupons: [
  69. {
  70. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png",
  71. text1: "POINTS REDEEM",
  72. text2: "GIFTCARD",
  73. link: "javascript:void(0)",
  74. },
  75. {
  76. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png",
  77. text1: "EXCLUSIVE",
  78. text2: "$200 COUPON",
  79. link: "javascript:void(0)",
  80. },
  81. {
  82. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png",
  83. text1: "BIRTHDAY",
  84. text2: "TREAT",
  85. link: "javascript:void(0)",
  86. },
  87. ],
  88. },
  89. {
  90. level: 4,
  91. title: "V4 Privileges",
  92. exppoints: 50000,
  93. coupons: [
  94. {
  95. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130956.png",
  96. text1: "POINTS REDEEM",
  97. text2: "GIFTCARD",
  98. link: "/customer/account/pointsreceivelist",
  99. },
  100. {
  101. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130957.png",
  102. text1: "EXCLUSIVE",
  103. text2: "$300 COUPON",
  104. link: "/customer/account/couponsreceivelist/v/4/",
  105. },
  106. {
  107. img: "https://cdn.alipearlhair.com/media/wysiwyg/wap/202301130958.png",
  108. text1: "BIRTHDAY",
  109. text2: "TREAT",
  110. link: "/customer/account/birthday",
  111. },
  112. ],
  113. },
  114. ];
  115. export default function AccountVipPopup({
  116. visible,
  117. onClose,
  118. }: {
  119. visible: boolean;
  120. onClose: () => void;
  121. }) {
  122. // swiper实例
  123. const [_swiperRef, setSwiperRef] = useState<SwiperType | null>(null);
  124. // 当前slide下标
  125. const [activeIndex, setActiveIndex] = useState(0);
  126. const [_loading, setLoading] = useState(true);
  127. const [VipGrothData, setVipGrothData] = useState<any>(null);
  128. // 如果不显示,直接 return null
  129. useEffect(() => {
  130. const fetchGrothValue = async () => {
  131. try {
  132. setLoading(true);
  133. const res = await clientFetch("/api/customer/growth-value");
  134. if (res.data.success) {
  135. setVipGrothData(res.data.data);
  136. console.log("vip成长值数据:", res.data.data);
  137. }
  138. } catch (error) {
  139. console.error("获取vip成长值失败:", error);
  140. } finally {
  141. setLoading(false);
  142. }
  143. };
  144. fetchGrothValue();
  145. }, []);
  146. if (!visible) return null;
  147. // 滑动切换触发
  148. const handleSlideChange = (swiper: SwiperType) => {
  149. setActiveIndex(swiper.activeIndex);
  150. console.log("aaa slide huadongle ");
  151. };
  152. const slideItem = vipList[activeIndex];
  153. const slideLevelNum = slideItem?.level ?? 1;
  154. const progressPercent = VipGrothData
  155. ? Math.min(
  156. Math.max(
  157. (VipGrothData.growth_value /
  158. VipGrothData.next_level.min_growth_value) *
  159. 100,
  160. 0,
  161. ),
  162. 100,
  163. )
  164. : 0;
  165. const userCurrentLevelNum =
  166. Number(VipGrothData?.current_level.name.replace(/[^0-9]/g, "")) || 0;
  167. let showText = "";
  168. console.log("userCurrentLevelNum", userCurrentLevelNum, slideLevelNum);
  169. if (userCurrentLevelNum === slideLevelNum) {
  170. showText = `Growth Value ${VipGrothData?.growth_value}/${VipGrothData?.next_level.min_growth_value}`;
  171. } else if (userCurrentLevelNum > slideLevelNum) {
  172. showText = "aaa";
  173. } else {
  174. showText = `Integral to 2000`;
  175. }
  176. return (
  177. // 全屏遮罩
  178. <div className="fixed inset-0 z-50 bg-black/50">
  179. {/* 弹框主体 - 从底部滑上来 */}
  180. <div className="absolute bottom-0 rounded-none left-0 right-0 w-full h-full bg-white overflow-auto">
  181. <div className="flex flex-col">
  182. {/* 顶部导航 */}
  183. <header className="bg-black text-white py-4 px-4 flex items-center">
  184. <button onClick={onClose} className="">
  185. <svg
  186. xmlns="http://www.w3.org/2000/svg"
  187. className="h-6 w-6"
  188. fill="none"
  189. viewBox="0 0 24 24"
  190. stroke="currentColor"
  191. >
  192. <path
  193. strokeLinecap="round"
  194. strokeLinejoin="round"
  195. strokeWidth={2}
  196. d="M15 19l-7-7 7-7"
  197. />
  198. </svg>
  199. </button>
  200. <h1 className="mx-auto">Vip Center</h1>
  201. </header>
  202. <div className="vipcenter-privileges-modal-innerscroll-father">
  203. <div id="vipcenter-privileges-modal-innerscroll">
  204. <div
  205. className=" relative
  206. h-170
  207. mt-8
  208. px-6
  209. bg-[url('https://cdn.alipearlhair.com/media/wysiwyg/wap/_2.png')]
  210. bg-no-repeat
  211. bg-[length:100%_100%]"
  212. >
  213. <div className="absolute top-0.75 left-8 text-4.5 text-[#FFD1B9] font-semibold">
  214. Vip <span className="levelcard">{userCurrentLevelNum}</span>
  215. </div>
  216. <div className="flex flex-col justify-between items-center text-white">
  217. <div className="w-18 h-18 mt-6">
  218. <Image
  219. src="https://cdn.alipearlhair.com/media/wysiwyg/newap/202303131637.png"
  220. alt=""
  221. width={0}
  222. height={0}
  223. sizes="100vw"
  224. className="max-w-full border-0 align-top w-full h-auto"
  225. />
  226. </div>
  227. <p className="text-4.5 mt-3 font-semibold"></p>
  228. <p className="text-text-sm mt-1.5 text-[#EFEFEF]">
  229. 18567768101@163.com
  230. </p>
  231. <p className="text-sm mt-1.5 text-[#EFEFEF]">
  232. Above current level
  233. </p>
  234. </div>
  235. <div className="box-border w-full mt-10.5 mb-9.75">
  236. <div className="text-center text-sm text-white mb-3">
  237. <span className="account-center-progress-text-pre">
  238. {showText}
  239. </span>
  240. </div>
  241. <div className="relative h-1 bg-[#5F4040]">
  242. <div
  243. className="w-4 h-4 rounded-full bg-black absolute top-1/2 -translate-y-1/2 block"
  244. style={{ left: `${progressPercent}%` }}
  245. ></div>
  246. <div
  247. className="rounded-[1.2821vw] h-full bg-[rgba(255,255,255,1)]"
  248. style={{ width: `${progressPercent}%` }}
  249. ></div>
  250. </div>
  251. {/* 轮播 */}
  252. <div className="swiper-container-center vip-swiper">
  253. <Swiper
  254. modules={[Navigation, Scrollbar]}
  255. slidesPerView={1}
  256. navigation={{
  257. prevEl: ".btn-prev", // 左箭头class
  258. nextEl: ".btn-next", // 右箭头class
  259. disabledClass: "opacity-20", // 滑到首尾自动加这个类,Tailwind直接用
  260. }}
  261. onSwiper={(swiper) => setSwiperRef(swiper)}
  262. onSlideChange={handleSlideChange}
  263. spaceBetween={0}
  264. className="swiper-container-horizontal"
  265. >
  266. {vipList.map((item, idx) => (
  267. <SwiperSlide
  268. key={idx}
  269. className="swiper-slide-color"
  270. style={{ width: "343px" }}
  271. data-exppoints={item.exppoints}
  272. data-level={item.level}
  273. >
  274. {/* 标题 */}
  275. <h3 className="text-lg font-medium mb-4 mt-4">
  276. {item.title}
  277. </h3>
  278. {/* 权益卡片容器 */}
  279. <div className="vipcenter-privileges-coupnts flex gap-3 flex-wrap">
  280. {item.coupons.map((coupon, cIdx) => (
  281. <a
  282. key={cIdx}
  283. href={coupon.link}
  284. className="vipcenter-privileges-coupnt-a vipcenter-privileges-coupnt-ponit"
  285. >
  286. <button className="vipcenter-privileges-coupnt flex flex-col items-center p-2 border rounded">
  287. <img
  288. src={coupon.img}
  289. alt=""
  290. className="w-10 h-10 object-contain mb-1"
  291. />
  292. <p className="text-sm">{coupon.text1}</p>
  293. <p className="text-sm">{coupon.text2}</p>
  294. </button>
  295. </a>
  296. ))}
  297. </div>
  298. </SwiperSlide>
  299. ))}
  300. {/* 自定义左右按钮,放在Swiper内部,同级slide */}
  301. <button className="btn-prev absolute left-2 top-1/2 -translate-y-1/2 z-10 w-9 h-9 rounded-full bg-black/50 shadow flex items-center justify-center">
  302. {/* 自定义左箭头SVG */}
  303. <svg
  304. width="16"
  305. height="16"
  306. viewBox="0 0 24 24"
  307. fill="none"
  308. stroke="#fff"
  309. stroke-width="2"
  310. >
  311. <path d="M15 18l-6-6 6-6" />
  312. </svg>
  313. </button>
  314. <button className="btn-next absolute right-2 top-1/2 -translate-y-1/2 z-10 w-9 h-9 rounded-full bg-black/50 shadow flex items-center justify-center">
  315. {/* 自定义右箭头SVG */}
  316. <svg
  317. width="16"
  318. height="16"
  319. viewBox="0 0 24 24"
  320. fill="none"
  321. stroke="#fff"
  322. stroke-width="2"
  323. >
  324. <path d="M9 18l6-6-6-6" />
  325. </svg>
  326. </button>
  327. </Swiper>
  328. </div>
  329. </div>
  330. </div>
  331. </div>
  332. </div>
  333. </div>
  334. </div>
  335. </div>
  336. );
  337. }