MiddleImageSwiper.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { Swiper, SwiperSlide } from "swiper/react";
  2. import { Pagination } from "swiper/modules";
  3. import "swiper/css";
  4. import "swiper/css/pagination";
  5. import "swiper/css/navigation";
  6. import "./css/swiper-custom.css";
  7. import { OpenAddToCartModalButton } from "@/components/common/AddToCartModal/OpenAddToCartModalButton";
  8. import type {HomeProduct,HomeSectionImage} from "@/types/home/type"
  9. interface zeroWearProps {
  10. zeroWear: HomeProduct[];
  11. zeroWearImage:HomeSectionImage[]
  12. }
  13. // const productList = [
  14. // {
  15. // id: 1,
  16. // img: "https://picsum.photos/400/500?random=1",
  17. // title: "14-36 In Water Wave Hum...",
  18. // price: 143.35,
  19. // },
  20. // {
  21. // id: 2,
  22. // img: "https://picsum.photos/400/500?random=2",
  23. // title: "14-36 In Water Wave Hum.",
  24. // price: 143.35,
  25. // },
  26. // {
  27. // id: 3,
  28. // img: "https://picsum.photos/400/500?random=3",
  29. // title: "14-36 In Water Wave Hum...",
  30. // price: 143.35,
  31. // },
  32. // {
  33. // id: 4,
  34. // img: "https://picsum.photos/400/500?random=4",
  35. // title: "14-36 In Water Wave Hum.",
  36. // price: 143.35,
  37. // },
  38. // ];
  39. const MiddleImageSwiper = ({ zeroWear,zeroWearImage }: zeroWearProps) => {
  40. if (!zeroWear || zeroWear.length === 0) return null;
  41. const productList = zeroWear
  42. const WearImage = zeroWearImage;
  43. return (
  44. <div className="w-full pr-4 pl-4 mx-auto rounded-lg ">
  45. <div className="w-full">
  46. <img
  47. src={WearImage[0].image || 'https://cdn.asteriahair.com/uploads/202602/11/20260211095330_7ec9031a4ab36e44.gif'}
  48. alt={WearImage[0].title || 'ZEROWEAR hair banner'}
  49. className="w-full h-auto object-cover block"
  50. />
  51. </div>
  52. <div className="py-4 px-4 pb-6 relative min-h-83 bg-[#f0f5f3] pb-10">
  53. <div className="w-full relative">
  54. <Swiper
  55. modules={[Pagination]}
  56. spaceBetween={16}
  57. slidesPerView={2}
  58. pagination={{
  59. type: "progressbar",
  60. el: ".my-progress-bar",
  61. }}
  62. className="mySwiper"
  63. breakpoints={{
  64. 480: { slidesPerView: 1 },
  65. 768: { slidesPerView: 2 },
  66. }}
  67. >
  68. {productList.map((item) => (
  69. <SwiperSlide key={item.id}>
  70. <div className="bg-white rounded overflow-hidden flex flex-col">
  71. <img
  72. src={item.image_url}
  73. alt={item.name}
  74. className="w-full aspect-[3/4] object-cover"
  75. />
  76. <div className="p-2 flex flex-col gap-2">
  77. <p className="text-sm text-gray-800 truncate">
  78. {item.name}
  79. </p>
  80. {/* 价格 + 购物车图标 */}
  81. <div className="flex items-center justify-between">
  82. <div className="flex items-center gap-1">
  83. <span className="font-semibold">${item.min_price}</span>
  84. <span className="text-xs text-gray-500 line-through">
  85. ${item.price}
  86. </span>
  87. </div>
  88. {/* 购物车图标 */}
  89. <OpenAddToCartModalButton
  90. productId={item.id}
  91. icon={
  92. <svg
  93. xmlns="http://www.w3.org/2000/svg"
  94. width="32"
  95. height="32"
  96. viewBox="0 0 32 32"
  97. fill="none"
  98. >
  99. <rect
  100. x="0"
  101. y="0"
  102. width="32"
  103. height="32"
  104. rx="8"
  105. fill="#036141"
  106. ></rect>
  107. <path
  108. stroke="rgba(255, 255, 255, 1)"
  109. stroke-width="1.3333333333333333"
  110. stroke-linejoin="round"
  111. stroke-linecap="round"
  112. d="M6.40039 7.79993L8.03372 7.79993L8.73372 10.5999M8.73372 10.5999L11.0671 19.9333L23.2004 19.9333L25.5337 10.5999L8.73372 10.5999Z"
  113. ></path>
  114. <ellipse
  115. cx="11.066040515899658"
  116. cy="23.199928283691406"
  117. rx="1.4000248908996582"
  118. ry="1.4000015258789062"
  119. stroke="rgba(255, 255, 255, 1)"
  120. stroke-width="1.3333333333333333"
  121. stroke-linejoin="round"
  122. stroke-linecap="round"
  123. ></ellipse>
  124. <ellipse
  125. cx="23.1998291015625"
  126. cy="23.199928283691406"
  127. rx="1.4000244140625"
  128. ry="1.4000015258789062"
  129. stroke="rgba(255, 255, 255, 1)"
  130. stroke-width="1.3333333333333333"
  131. stroke-linejoin="round"
  132. stroke-linecap="round"
  133. ></ellipse>
  134. <path
  135. stroke="rgba(255, 255, 255, 1)"
  136. stroke-width="1.3333333333333333"
  137. stroke-linejoin="round"
  138. stroke-linecap="round"
  139. d="M15.2656 15.2665L18.999 15.2665"
  140. ></path>
  141. <path
  142. stroke="rgba(255, 255, 255, 1)"
  143. stroke-width="1.3333333333333333"
  144. stroke-linejoin="round"
  145. stroke-linecap="round"
  146. d="M17.1348 17.1332L17.1348 13.3999"
  147. ></path>
  148. </svg>
  149. }
  150. />
  151. </div>
  152. </div>
  153. </div>
  154. </SwiperSlide>
  155. ))}
  156. </Swiper>
  157. <div className="my-progress-bar mt-5 w-full h-1 bg-gray-200 rounded-full bottom-0 [top:unset]"></div>
  158. </div>
  159. </div>
  160. </div>
  161. );
  162. };
  163. export default MiddleImageSwiper;