index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view class="recommend-item">
  3. <!-- Main Info Row -->
  4. <view class="main-info" :style="{ 'margin-bottom': showDesc ? '30rpx' : '0' }">
  5. <image :src="item.cover" class="book-cover" mode="aspectFill"></image>
  6. <view class="info-right">
  7. <view class="title-author">
  8. <view class="title-row">
  9. <text class="title">{{ item.title }}</text>
  10. </view>
  11. <text class="author">{{ item.author }}</text>
  12. </view>
  13. <view class="price-action">
  14. <view class="price-box">
  15. <text class="currency">¥</text>
  16. <text class="price">{{ item.price }}</text>
  17. <text class="original">¥{{ item.originalPrice }}</text>
  18. </view>
  19. <view class="cart-btn" @click.stop="handleAddToCart">
  20. <text>加入购物车</text>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- Description Row -->
  26. <view class="desc-section" v-if="showDesc">
  27. <view class="desc-header">
  28. <text class="label">简介</text>
  29. <view class="indicator"></view>
  30. </view>
  31. <text class="desc-content">{{ item.desc || '暂无简介' }}</text>
  32. </view>
  33. <!-- Product Selection Popup -->
  34. <SelectGoodPopup ref="popup" @confirm="onPopupConfirm"></SelectGoodPopup>
  35. </view>
  36. </template>
  37. <script>
  38. import SelectGoodPopup from '../select-good-popup/index.vue';
  39. export default {
  40. name: 'RecommendItem',
  41. components: {
  42. SelectGoodPopup
  43. },
  44. props: {
  45. item: {
  46. type: Object,
  47. required: true
  48. },
  49. showDesc: {
  50. type: Boolean,
  51. default: true
  52. }
  53. },
  54. methods: {
  55. handleAddToCart() {
  56. // Open the popup using ref
  57. this.$refs.popup.open(this.item);
  58. },
  59. onPopupConfirm(data) {
  60. // Emit the confirmed data
  61. this.$emit('add-cart', data);
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .recommend-item {
  68. padding: 30rpx 0;
  69. border-bottom: 1rpx dashed #EEEEEE;
  70. .main-info {
  71. display: flex;
  72. margin-bottom: 30rpx;
  73. .book-cover {
  74. width: 172rpx;
  75. height: 220rpx;
  76. border-radius: 8rpx;
  77. background-color: #f5f5f5;
  78. margin-right: 24rpx;
  79. flex-shrink: 0;
  80. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
  81. }
  82. .info-right {
  83. flex: 1;
  84. display: flex;
  85. flex-direction: column;
  86. justify-content: space-between;
  87. padding: 4rpx 0;
  88. .title-author {
  89. .title {
  90. font-size: 32rpx;
  91. font-weight: bold;
  92. color: #333;
  93. margin-bottom: 12rpx;
  94. display: block;
  95. line-height: 1.4;
  96. }
  97. .author {
  98. font-size: 24rpx;
  99. color: #999;
  100. }
  101. }
  102. .price-action {
  103. display: flex;
  104. justify-content: space-between;
  105. align-items: flex-end;
  106. .price-box {
  107. .currency {
  108. font-size: 24rpx;
  109. color: #FF4B4B;
  110. font-weight: bold;
  111. }
  112. .price {
  113. font-size: 36rpx;
  114. color: #FF4B4B;
  115. font-weight: bold;
  116. margin-right: 12rpx;
  117. }
  118. .original {
  119. font-size: 24rpx;
  120. color: #999;
  121. text-decoration: line-through;
  122. }
  123. }
  124. .cart-btn {
  125. background: #38C248;
  126. border-radius: 30rpx;
  127. height: 60rpx;
  128. line-height: 60rpx;
  129. padding: 0 24rpx;
  130. text {
  131. font-size: 26rpx;
  132. color: #fff;
  133. }
  134. }
  135. }
  136. }
  137. }
  138. .desc-section {
  139. .desc-header {
  140. position: relative;
  141. display: inline-block;
  142. margin-bottom: 16rpx;
  143. .label {
  144. font-size: 30rpx;
  145. font-weight: bold;
  146. color: #333;
  147. position: relative;
  148. z-index: 1;
  149. }
  150. .indicator {
  151. position: absolute;
  152. bottom: 4rpx;
  153. right: 4rpx;
  154. width: 30rpx;
  155. height: 8rpx;
  156. background: #4ED964;
  157. border-radius: 4rpx;
  158. z-index: 0;
  159. }
  160. }
  161. .desc-content {
  162. font-family: Source Han Sans SC;
  163. font-size: 26rpx;
  164. color: #8D8D8D;
  165. line-height: 1.6;
  166. display: block;
  167. text-align: justify;
  168. }
  169. }
  170. }
  171. </style>