DimensionProducts.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="section">
  3. <view class="section-header">
  4. <text class="section-title">🛍️ 推荐商品</text>
  5. <text class="section-more" @click="$emit('moreProducts')">更多 ›</text>
  6. </view>
  7. <view v-if="!displayProducts || displayProducts.length === 0" class="empty-state">
  8. <text class="empty-tip">{{ isLoggedIn ? '暂无商品' : '登录后查看更多商品' }}</text>
  9. </view>
  10. <view class="product-list" v-if="displayProducts && displayProducts.length > 0">
  11. <view class="product-card" v-for="prod in displayProducts" :key="prod.id" @click="$emit('productClick', prod)">
  12. <image class="product-img" :src="prod.coverImage || '/static/default-product.png'" mode="aspectFill" />
  13. <text class="product-name line-clamp-2">{{ prod.name }}</text>
  14. <text class="product-price" v-if="prod.priceLabel">{{ prod.priceLabel }}</text>
  15. <text class="product-price" v-else-if="prod.price">{{ formatPriceWithSymbol(prod.price) }}</text>
  16. <text class="product-price" v-else>免费</text>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. dimensionCode: { type: String, required: true },
  25. products: { type: Array, default: function() { return [] } },
  26. isLoggedIn: { type: Boolean, default: false }
  27. },
  28. data: function() {
  29. return {
  30. }
  31. },
  32. computed: {
  33. displayProducts: function() {
  34. return this.products
  35. }
  36. },
  37. methods: {
  38. }
  39. }
  40. </script>
  41. <style scoped>
  42. .section {
  43. margin: 20rpx 20rpx;
  44. }
  45. .section-header {
  46. display: flex;
  47. justify-content: space-between;
  48. align-items: center;
  49. margin-bottom: 20rpx;
  50. }
  51. .section-title {
  52. font-size: 30rpx;
  53. font-weight: bold;
  54. color: #333;
  55. }
  56. .section-more {
  57. font-size: 24rpx;
  58. color: #999;
  59. }
  60. .product-list {
  61. display: flex;
  62. flex-wrap: wrap;
  63. }
  64. .product-card {
  65. width: calc(50% - 10rpx);
  66. background: #fff;
  67. border-radius: 16rpx;
  68. overflow: hidden;
  69. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  70. margin-right: 20rpx;
  71. margin-bottom: 20rpx;
  72. }
  73. .product-card:nth-child(2n) {
  74. margin-right: 0;
  75. }
  76. .product-img {
  77. width: 100%;
  78. height: 240rpx;
  79. background: #f0f0f0;
  80. }
  81. .product-name {
  82. font-size: 26rpx;
  83. color: #333;
  84. padding: 12rpx 16rpx 0;
  85. }
  86. .product-price {
  87. font-size: 28rpx;
  88. color: #F97316;
  89. font-weight: bold;
  90. padding: 8rpx 16rpx 16rpx;
  91. display: block;
  92. }
  93. .line-clamp-2 {
  94. overflow: hidden;
  95. text-overflow: ellipsis;
  96. display: -webkit-box;
  97. -webkit-line-clamp: 2;
  98. -webkit-box-orient: vertical;
  99. }
  100. .empty-state {
  101. display: flex;
  102. justify-content: center;
  103. padding: 40rpx 0;
  104. }
  105. .empty-tip {
  106. font-size: 24rpx;
  107. color: #999;
  108. }
  109. </style>