HomeBestSellers.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // import { Swiper, SwiperSlide } from "swiper/react";
  2. // import { Navigation, Pagination } from "swiper/modules";
  3. import { OpenAddToCartModalButton } from "@/components/common/AddToCartModal/OpenAddToCartModalButton";
  4. import type { HomeProduct,HomeSection } from "@/types/home/type";
  5. import Link from "next/link";
  6. import Image from "next/image";
  7. interface jinGangSectionProps{
  8. bestSellerSection:HomeSection |undefined;
  9. }
  10. // interface HomeBestSellersProps {
  11. // bestSellers: HomeProduct[];
  12. // }
  13. const HomeBestSellers = ({ bestSellerSection }: jinGangSectionProps) => {
  14. const bestSellers: HomeProduct[] = bestSellerSection?.products ?? [];
  15. if (!bestSellers || bestSellers.length === 0) return null;
  16. // 4. 真实数据按每6个拆分一组,替换原来的模拟拆分逻辑
  17. const chunkSize = 6;
  18. const productBlocks: HomeProduct[][] = [];
  19. for (let i = 0; i < bestSellers.length; i += chunkSize) {
  20. productBlocks.push(bestSellers.slice(i, i + chunkSize));
  21. }
  22. return (
  23. <div className="w-full mx-auto px-12 py-12">
  24. {/* 标题 */}
  25. <h2 className="text-4xl text-center font-bold leading-ly-46 mb-6">{bestSellerSection?.title}</h2>
  26. <div className="grid grid-cols-4 gap-8">
  27. {bestSellers.map((product) => (
  28. <div key={product.id} className="flex min-w-0 flex-col gap-2">
  29. <div className="relative aspect-[3/4] w-full overflow-hidden rounded-sm">
  30. <Image
  31. src={product.image_url}
  32. alt={product.name}
  33. fill
  34. sizes="25vw"
  35. className="object-cover"
  36. />
  37. </div>
  38. <Link
  39. href="/wiggins-ready-go-250-density-popping-curly-hd-lace-front-wigs-medium-length-human-hair-wigs.html"
  40. className="truncate text-sm leading-ly-22 font-normal text-gray-800"
  41. >
  42. {product.name}
  43. </Link>
  44. <div className="flex items-center gap-1">
  45. <div className="flex">
  46. {[1, 2, 3, 4, 5].map((star) => (
  47. <svg
  48. key={star}
  49. className="h-4 w-4 text-green-500"
  50. fill="currentColor"
  51. viewBox="0 0 20 20"
  52. >
  53. <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
  54. </svg>
  55. ))}
  56. </div>
  57. <span className="text-xs text-gray-600">
  58. {product.review_count}
  59. </span>
  60. </div>
  61. <div className="flex items-center justify-between">
  62. <div className="flex items-center gap-1">
  63. <span className="font-semibold">${product.min_price}</span>
  64. <span className="text-xs text-gray-500 line-through">
  65. ${product.price}
  66. </span>
  67. </div>
  68. <OpenAddToCartModalButton
  69. productId={product.id}
  70. icon={
  71. <svg
  72. xmlns="http://www.w3.org/2000/svg"
  73. width="32"
  74. height="32"
  75. viewBox="0 0 32 32"
  76. fill="none"
  77. >
  78. <rect
  79. x="0"
  80. y="0"
  81. width="32"
  82. height="32"
  83. rx="8"
  84. fill="#036141"
  85. ></rect>
  86. <path
  87. stroke="rgba(255, 255, 255, 1)"
  88. stroke-width="1.3333333333333333"
  89. stroke-linejoin="round"
  90. stroke-linecap="round"
  91. 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"
  92. ></path>
  93. <ellipse
  94. cx="11.066040515899658"
  95. cy="23.199928283691406"
  96. rx="1.4000248908996582"
  97. ry="1.4000015258789062"
  98. stroke="rgba(255, 255, 255, 1)"
  99. stroke-width="1.3333333333333333"
  100. stroke-linejoin="round"
  101. stroke-linecap="round"
  102. ></ellipse>
  103. <ellipse
  104. cx="23.1998291015625"
  105. cy="23.199928283691406"
  106. rx="1.4000244140625"
  107. ry="1.4000015258789062"
  108. stroke="rgba(255, 255, 255, 1)"
  109. stroke-width="1.3333333333333333"
  110. stroke-linejoin="round"
  111. stroke-linecap="round"
  112. ></ellipse>
  113. <path
  114. stroke="rgba(255, 255, 255, 1)"
  115. stroke-width="1.3333333333333333"
  116. stroke-linejoin="round"
  117. stroke-linecap="round"
  118. d="M15.2656 15.2665L18.999 15.2665"
  119. ></path>
  120. <path
  121. stroke="rgba(255, 255, 255, 1)"
  122. stroke-width="1.3333333333333333"
  123. stroke-linejoin="round"
  124. stroke-linecap="round"
  125. d="M17.1348 17.1332L17.1348 13.3999"
  126. ></path>
  127. </svg>
  128. }
  129. />
  130. </div>
  131. </div>
  132. ))}
  133. </div>
  134. <div className="w-[186px] h-[32px] m-auto text-center text-sm leading-ly-32 mt-12 opacity-100 rounded-[29px] bg-white border border-solid">
  135. View More
  136. </div>
  137. </div>
  138. );
  139. };
  140. export default HomeBestSellers;