AccountVipPopup.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 type { 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. // 当前slide下标
  123. const [activeIndex, setActiveIndex] = useState(0);
  124. const [VipGrothData, setVipGrothData] = useState<any>(null);
  125. // 如果不显示,直接 return null
  126. useEffect(() => {
  127. const fetchGrothValue = async () => {
  128. try {
  129. const res = await clientFetch("/api/customer/growth-value");
  130. if (res.success) {
  131. setVipGrothData(res.data);
  132. console.log("vip成长值数据:", res.data);
  133. }
  134. } catch (error) {
  135. console.error("获取vip成长值失败:", error);
  136. }
  137. };
  138. fetchGrothValue();
  139. }, []);
  140. if (!visible) return null;
  141. // 滑动切换触发
  142. const handleSlideChange = (swiper: SwiperType) => {
  143. setActiveIndex(swiper.activeIndex);
  144. console.log("aaa slide huadongle ");
  145. };
  146. const slideItem = vipList[activeIndex];
  147. const slideLevelNum = slideItem?.level ?? 1;
  148. const progressPercent = VipGrothData
  149. ? Math.min(
  150. Math.max(
  151. (VipGrothData.growth_value /
  152. VipGrothData.next_level.min_growth_value) *
  153. 100,
  154. 0,
  155. ),
  156. 100,
  157. )
  158. : 0;
  159. const userCurrentLevelNum =
  160. Number(VipGrothData?.current_level.name.replace(/[^0-9]/g, "")) || 0;
  161. let showText = "";
  162. console.log("userCurrentLevelNum", userCurrentLevelNum, slideLevelNum);
  163. if (userCurrentLevelNum === slideLevelNum) {
  164. showText = `Growth Value ${VipGrothData?.growth_value}/${VipGrothData?.next_level.min_growth_value}`;
  165. } else if (userCurrentLevelNum > slideLevelNum) {
  166. showText = "aaa";
  167. } else {
  168. showText = `Integral to 2000`;
  169. }
  170. return (
  171. // 全屏遮罩
  172. <div className="fixed inset-0 z-50 bg-black/50">
  173. {/* 弹框主体 - 从底部滑上来 */}
  174. <div className="absolute bottom-0 rounded-none left-0 right-0 w-full h-full bg-white overflow-auto">
  175. <div className="flex flex-col">
  176. {/* 顶部导航 */}
  177. <header className="bg-black text-white py-4 px-4 flex items-center">
  178. <button onClick={onClose} className="">
  179. <svg
  180. xmlns="http://www.w3.org/2000/svg"
  181. className="h-6 w-6"
  182. fill="none"
  183. viewBox="0 0 24 24"
  184. stroke="currentColor"
  185. >
  186. <path
  187. strokeLinecap="round"
  188. strokeLinejoin="round"
  189. strokeWidth={2}
  190. d="M15 19l-7-7 7-7"
  191. />
  192. </svg>
  193. </button>
  194. <h1 className="mx-auto">Vip Center</h1>
  195. </header>
  196. <div className="vipcenter-privileges-modal-innerscroll-father">
  197. <div id="vipcenter-privileges-modal-innerscroll">
  198. <div
  199. className=" relative
  200. h-170
  201. mt-8
  202. px-6
  203. bg-[url('https://cdn.alipearlhair.com/media/wysiwyg/wap/_2.png')]
  204. bg-no-repeat
  205. bg-[length:100%_100%]"
  206. >
  207. <div className="absolute top-0.75 left-8 text-4.5 text-[#FFD1B9] font-semibold">
  208. Vip <span className="levelcard">{userCurrentLevelNum}</span>
  209. </div>
  210. <div className="flex flex-col justify-between items-center text-white">
  211. <div className="w-18 h-18 mt-6">
  212. <Image
  213. src="https://cdn.alipearlhair.com/media/wysiwyg/newap/202303131637.png"
  214. alt=""
  215. width={0}
  216. height={0}
  217. sizes="100vw"
  218. className="max-w-full border-0 align-top w-full h-auto"
  219. />
  220. </div>
  221. <p className="text-4.5 mt-3 font-semibold"></p>
  222. <p className="text-text-sm mt-1.5 text-[#EFEFEF]">
  223. 18567768101@163.com
  224. </p>
  225. <p className="text-sm mt-1.5 text-[#EFEFEF]">
  226. Above current level
  227. </p>
  228. </div>
  229. <div className="box-border w-full mt-10.5 mb-9.75">
  230. <div className="text-center text-sm text-white mb-3">
  231. <span className="account-center-progress-text-pre">
  232. {showText}
  233. </span>
  234. </div>
  235. <div className="relative h-1 bg-[#5F4040]">
  236. <div
  237. className="w-4 h-4 rounded-full bg-black absolute top-1/2 -translate-y-1/2 block"
  238. style={{ left: `${progressPercent}%` }}
  239. ></div>
  240. <div
  241. className="rounded-[1.2821vw] h-full bg-[rgba(255,255,255,1)]"
  242. style={{ width: `${progressPercent}%` }}
  243. ></div>
  244. </div>
  245. {/* 轮播 */}
  246. <div className="swiper-container-center vip-swiper">
  247. <Swiper
  248. modules={[Navigation, Scrollbar]}
  249. slidesPerView={1}
  250. navigation={{
  251. prevEl: ".btn-prev", // 左箭头class
  252. nextEl: ".btn-next", // 右箭头class
  253. disabledClass: "opacity-20", // 滑到首尾自动加这个类,Tailwind直接用
  254. }}
  255. onSlideChange={handleSlideChange}
  256. spaceBetween={0}
  257. className="swiper-container-horizontal"
  258. >
  259. {vipList.map((item, idx) => (
  260. <SwiperSlide
  261. key={idx}
  262. className="swiper-slide-color"
  263. style={{ width: "343px" }}
  264. data-exppoints={item.exppoints}
  265. data-level={item.level}
  266. >
  267. {/* 标题 */}
  268. <h3 className="text-lg font-medium mb-4 mt-4">
  269. {item.title}
  270. </h3>
  271. {/* 权益卡片容器 */}
  272. <div className="vipcenter-privileges-coupnts flex gap-3 flex-wrap">
  273. {item.coupons.map((coupon, cIdx) => (
  274. <a
  275. key={cIdx}
  276. href={coupon.link}
  277. className="vipcenter-privileges-coupnt-a vipcenter-privileges-coupnt-ponit"
  278. >
  279. <button className="vipcenter-privileges-coupnt flex flex-col items-center p-2 border rounded">
  280. <img
  281. src={coupon.img}
  282. alt=""
  283. className="w-10 h-10 object-contain mb-1"
  284. />
  285. <p className="text-sm">{coupon.text1}</p>
  286. <p className="text-sm">{coupon.text2}</p>
  287. </button>
  288. </a>
  289. ))}
  290. </div>
  291. </SwiperSlide>
  292. ))}
  293. {/* 自定义左右按钮,放在Swiper内部,同级slide */}
  294. <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">
  295. {/* 自定义左箭头SVG */}
  296. <svg
  297. width="16"
  298. height="16"
  299. viewBox="0 0 24 24"
  300. fill="none"
  301. stroke="#fff"
  302. stroke-width="2"
  303. >
  304. <path d="M15 18l-6-6 6-6" />
  305. </svg>
  306. </button>
  307. <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">
  308. {/* 自定义右箭头SVG */}
  309. <svg
  310. width="16"
  311. height="16"
  312. viewBox="0 0 24 24"
  313. fill="none"
  314. stroke="#fff"
  315. stroke-width="2"
  316. >
  317. <path d="M9 18l6-6-6-6" />
  318. </svg>
  319. </button>
  320. </Swiper>
  321. </div>
  322. </div>
  323. </div>
  324. </div>
  325. </div>
  326. </div>
  327. </div>
  328. </div>
  329. );
  330. }