product_item.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="product-item" @click="handleClick">
  3. <view class="product-image">
  4. <image :src="item.image" mode="aspectFill" />
  5. <!-- 视频播放图标 -->
  6. <view v-if="item.isVideo" class="play-icon">
  7. <i class="icon-font icon-play"></i>
  8. </view>
  9. <!-- 收藏图标 -->
  10. <view class="favorite-icon" @click.stop="toggleFavorite">
  11. <i class="icon-font icon-star" :class="{ active: item.isFavorite }"></i>
  12. </view>
  13. </view>
  14. <view class="product-info">
  15. <view class="product-title">{{ item.title }}</view>
  16. <view class="product-sales">{{ item.sales }}</view>
  17. <view class="product-price">
  18. <text class="current-price">¥{{ item.currentPrice }}</text>
  19. <text class="original-price">¥{{ item.originalPrice }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup>
  25. import { defineProps, defineEmits } from "vue";
  26. const props = defineProps({
  27. item: {
  28. type: Object,
  29. required: true,
  30. },
  31. });
  32. const emit = defineEmits(["click", "favorite"]);
  33. const handleClick = () => {
  34. emit("click", props.item);
  35. };
  36. const toggleFavorite = () => {
  37. emit("favorite", props.item);
  38. };
  39. </script>
  40. <style lang="less" scoped>
  41. @import url("@/style.less");
  42. .product-item {
  43. background: var(--light);
  44. border-radius: 16rpx;
  45. overflow: hidden;
  46. margin-bottom: 20rpx;
  47. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  48. .product-image {
  49. width: 100%;
  50. height: 300rpx;
  51. position: relative;
  52. image {
  53. width: 100%;
  54. height: 100%;
  55. }
  56. .play-icon {
  57. position: absolute;
  58. top: 20rpx;
  59. left: 20rpx;
  60. width: 60rpx;
  61. height: 60rpx;
  62. background: rgba(0, 0, 0, 0.6);
  63. border-radius: 50%;
  64. display: flex;
  65. align-items: center;
  66. justify-content: center;
  67. .icon-play {
  68. color: white;
  69. font-size: 32rpx;
  70. }
  71. }
  72. .favorite-icon {
  73. position: absolute;
  74. bottom: 20rpx;
  75. right: 20rpx;
  76. width: 60rpx;
  77. height: 60rpx;
  78. background: rgba(255, 255, 255, 0.9);
  79. border-radius: 50%;
  80. display: flex;
  81. align-items: center;
  82. justify-content: center;
  83. .icon-star {
  84. color: var(--text-01);
  85. font-size: 32rpx;
  86. &.active {
  87. color: var(--primary);
  88. }
  89. }
  90. }
  91. }
  92. .product-info {
  93. padding: 24rpx;
  94. .product-title {
  95. font-size: 28rpx;
  96. color: var(--black);
  97. line-height: 1.4;
  98. margin-bottom: 12rpx;
  99. overflow: hidden;
  100. text-overflow: ellipsis;
  101. display: -webkit-box;
  102. -webkit-line-clamp: 2;
  103. -webkit-box-orient: vertical;
  104. }
  105. .product-sales {
  106. font-size: 24rpx;
  107. color: var(--text-01);
  108. margin-bottom: 12rpx;
  109. }
  110. .product-price {
  111. display: flex;
  112. align-items: center;
  113. gap: 12rpx;
  114. .current-price {
  115. font-size: 32rpx;
  116. font-weight: bold;
  117. color: var(--primary);
  118. }
  119. .original-price {
  120. font-size: 24rpx;
  121. color: var(--text-01);
  122. text-decoration: line-through;
  123. }
  124. }
  125. }
  126. }
  127. </style>