DimensionProducts.vue 2.7 KB

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