MiddleImageSwiper.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { Swiper, SwiperSlide } from "swiper/react";
  2. import { Pagination } from "swiper/modules";
  3. import Link from "next/link";
  4. import Image from "next/image";
  5. import { OpenAddToCartModalButton } from "@/components/common/AddToCartModal/OpenAddToCartModalButton";
  6. import type {HomeProduct,HomeSectionImage} from "@/types/home/type"
  7. interface zeroWearProps {
  8. zeroWear: HomeProduct[];
  9. zeroWearImage:HomeSectionImage[]
  10. }
  11. // const productList = [
  12. // {
  13. // id: 1,
  14. // img: "https://picsum.photos/400/500?random=1",
  15. // title: "14-36 In Water Wave Hum...",
  16. // price: 143.35,
  17. // },
  18. // {
  19. // id: 2,
  20. // img: "https://picsum.photos/400/500?random=2",
  21. // title: "14-36 In Water Wave Hum.",
  22. // price: 143.35,
  23. // },
  24. // {
  25. // id: 3,
  26. // img: "https://picsum.photos/400/500?random=3",
  27. // title: "14-36 In Water Wave Hum...",
  28. // price: 143.35,
  29. // },
  30. // {
  31. // id: 4,
  32. // img: "https://picsum.photos/400/500?random=4",
  33. // title: "14-36 In Water Wave Hum.",
  34. // price: 143.35,
  35. // },
  36. // ];
  37. const MiddleImageSwiper = ({ zeroWear,zeroWearImage }: zeroWearProps) => {
  38. if (!zeroWear || zeroWear.length === 0) return null;
  39. const productList = zeroWear
  40. const WearImage = zeroWearImage;
  41. return (
  42. <div className="w-full pr-4 pl-4 mx-auto rounded-lg ">
  43. <div className="w-full">
  44. <img
  45. src={WearImage[0].image || 'https://cdn.asteriahair.com/uploads/202602/11/20260211095330_7ec9031a4ab36e44.gif'}
  46. alt={WearImage[0].title || 'ZEROWEAR hair banner'}
  47. className="w-full h-auto object-cover block"
  48. />
  49. </div>
  50. <div className="py-4 px-4 pb-6 relative min-h-83 bg-[#f0f5f3] pb-10">
  51. <div className="w-full relative">
  52. <Swiper
  53. modules={[Pagination]}
  54. spaceBetween={16}
  55. slidesPerView={2}
  56. pagination={{
  57. type: "progressbar",
  58. el: ".my-progress-bar",
  59. }}
  60. className="mySwiper middle-image-swiper"
  61. breakpoints={{
  62. 480: { slidesPerView: 1 },
  63. 768: { slidesPerView: 2 },
  64. }}
  65. >
  66. {productList.map((item) => (
  67. <SwiperSlide key={item.id}>
  68. <div className="bg-white rounded overflow-hidden flex flex-col">
  69. <Link href={`/products/${item.urlKey}_${item.id}.html`} className="relative aspect-[3/4] w-full overflow-hidden rounded-sm block">
  70. <Image
  71. src={item.image_url}
  72. alt={item.name}
  73. fill
  74. className="object-cover"
  75. />
  76. </Link>
  77. <div className="p-2 flex flex-col gap-2">
  78. <Link href={`/products/${item.urlKey}_${item.id}.html`} className="text-sm text-gray-800 truncate">
  79. {item.name}
  80. </Link>
  81. {/* 价格 + 购物车图标 */}
  82. <div className="flex items-center justify-between">
  83. <div className="flex items-center gap-1">
  84. <span className="font-semibold">${item.min_price}</span>
  85. <span className="text-xs text-gray-500 line-through">
  86. ${item.price}
  87. </span>
  88. </div>
  89. {/* 购物车图标 */}
  90. <OpenAddToCartModalButton
  91. productId={item.id}
  92. />
  93. </div>
  94. </div>
  95. </div>
  96. </SwiperSlide>
  97. ))}
  98. </Swiper>
  99. <div className="my-progress-bar mt-5 w-full h-1 bg-gray-200 rounded-full bottom-0 [top:unset]"></div>
  100. </div>
  101. </div>
  102. </div>
  103. );
  104. };
  105. export default MiddleImageSwiper;