MiddleImageSwiper.tsx 6.5 KB

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