index.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { View, Text, Swiper, SwiperItem, Image } from "@tarojs/components";
  2. import recommendBg1 from '../../../images/index/recommend-bg1.png'
  3. import recommendBg2 from '../../../images/index/recommend-bg2.png'
  4. import Taro from '@tarojs/taro'
  5. import "./index.less";
  6. const RecommendList = () => {
  7. // 模拟推荐商品数据
  8. const recommendProducts = [
  9. {
  10. id: 1,
  11. name: "商品名称商品名称商品名称商品名称商品名称",
  12. price: 99.99,
  13. sharePrice: 0.12,
  14. image: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6"
  15. },
  16. {
  17. id: 2,
  18. name: "商品名称商品名称商品名称商品名称",
  19. price: 88.88,
  20. sharePrice: 0.12,
  21. image: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6"
  22. },
  23. {
  24. id: 3,
  25. name: "商品名称商品名称商品名称",
  26. price: 77.77,
  27. sharePrice: 0.12,
  28. image: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6"
  29. },
  30. {
  31. id: 4,
  32. name: "商品名称商品名称商品名称商品名称",
  33. price: 66.66,
  34. sharePrice: 0.12,
  35. image: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6"
  36. },
  37. {
  38. id: 5,
  39. name: "商品名称商品名称商品名称",
  40. price: 55.55,
  41. sharePrice: 0.12,
  42. image: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6"
  43. },
  44. {
  45. id: 6,
  46. name: "商品名称商品名称商品名称商品名称",
  47. price: 44.44,
  48. sharePrice: 0.12,
  49. image: "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1saL6x.img?w=768&h=411&m=6"
  50. }
  51. ];
  52. // 将商品数据按每3个分组
  53. const groupedProducts = recommendProducts.reduce((groups, product, index) => {
  54. const groupIndex = Math.floor(index / 3);
  55. if (!groups[groupIndex]) {
  56. groups[groupIndex] = [];
  57. }
  58. groups[groupIndex].push(product);
  59. return groups;
  60. }, []);
  61. return (
  62. <View className="recommend-wrap">
  63. <View className="title">邀请人推荐</View>
  64. <Swiper
  65. className="recommend-swiper"
  66. indicatorDots
  67. indicatorColor="#d8d8d8"
  68. indicatorActiveColor="#ffcc1a"
  69. >
  70. {groupedProducts.map((group, groupIndex) => (
  71. <SwiperItem key={groupIndex} className="swiper-item">
  72. <View className="product-group">
  73. {group.map(product => (
  74. <View onClick={() => Taro.navigateTo({ url: `/pages/indexSub/productDetail/index?id=${product.id}` })} key={product.id} className="product-item">
  75. <Image className="product-img" src={product.image} mode="aspectFill" />
  76. <Text className="product-name">{product.name}</Text>
  77. <View className="price-info">
  78. <Text className="symbol">¥</Text>
  79. <Text className="price">{product.price.toFixed(2)}</Text>
  80. </View>
  81. <View className="share-price-tag">
  82. <Text className="share-text">分享价</Text>
  83. <Text className="share-symbol">¥</Text>
  84. <Text className="share-price">{product.sharePrice.toFixed(2)}</Text>
  85. </View>
  86. </View>
  87. ))}
  88. </View>
  89. </SwiperItem>
  90. ))}
  91. </Swiper>
  92. {/* 底部背景图 */}
  93. <View className="bottom-bg">
  94. <Image className="bg-left" src={recommendBg1} mode="aspectFit" />
  95. <Image className="bg-right" src={recommendBg2} mode="aspectFit" />
  96. </View>
  97. </View>
  98. );
  99. };
  100. export default RecommendList;