index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. <rich-text class="title" :nodes="highlightedName"></rich-text>
  10. </view>
  11. <rich-text class="author" :nodes="highlightedAuthor"></rich-text>
  12. </view>
  13. <view class="price-action">
  14. <view class="price-box">
  15. <text class="currency">¥</text>
  16. <text class="price">{{ item.productPrice || item.price }}</text>
  17. <text class="original">¥{{ item.price }}</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. <rich-text class="desc-content" :nodes="highlightedDesc"></rich-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. computed: {
  55. highlightedName() {
  56. return this.parseEmTag(this.item.name || this.item.title || '');
  57. },
  58. highlightedAuthor() {
  59. return this.parseEmTag(this.item.author || '');
  60. },
  61. highlightedDesc() {
  62. return this.parseEmTag(this.item.description || this.item.desc || '暂无简介');
  63. }
  64. },
  65. methods: {
  66. parseEmTag(text) {
  67. if (!text) return '';
  68. return text.replace(/<em>/g, '<span style="color: #38C148">').replace(/<\/em>/g, '</span>');
  69. },
  70. handleAddToCart() {
  71. // Open the popup using ref
  72. this.$refs.popup.open(this.item);
  73. },
  74. onPopupConfirm(data) {
  75. // Emit the confirmed data
  76. this.$emit('add-cart', data);
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .recommend-item {
  83. padding: 30rpx 0;
  84. border-bottom: 1rpx dashed #EEEEEE;
  85. .main-info {
  86. display: flex;
  87. margin-bottom: 30rpx;
  88. .book-cover {
  89. width: 172rpx;
  90. height: 220rpx;
  91. border-radius: 8rpx;
  92. margin-right: 24rpx;
  93. flex-shrink: 0;
  94. }
  95. .info-right {
  96. flex: 1;
  97. display: flex;
  98. flex-direction: column;
  99. justify-content: space-between;
  100. padding: 4rpx 0;
  101. .title-author {
  102. .title {
  103. font-size: 32rpx;
  104. font-weight: bold;
  105. color: #333;
  106. margin-bottom: 12rpx;
  107. display: block;
  108. line-height: 1.4;
  109. }
  110. .author {
  111. font-size: 24rpx;
  112. color: #999;
  113. }
  114. }
  115. .price-action {
  116. display: flex;
  117. justify-content: space-between;
  118. align-items: flex-end;
  119. .price-box {
  120. .currency {
  121. font-size: 24rpx;
  122. color: #FF4B4B;
  123. font-weight: bold;
  124. }
  125. .price {
  126. font-size: 36rpx;
  127. color: #FF4B4B;
  128. font-weight: bold;
  129. margin-right: 12rpx;
  130. }
  131. .original {
  132. font-size: 24rpx;
  133. color: #999;
  134. text-decoration: line-through;
  135. }
  136. }
  137. .cart-btn {
  138. background: #38C248;
  139. border-radius: 30rpx;
  140. height: 60rpx;
  141. line-height: 60rpx;
  142. padding: 0 24rpx;
  143. text {
  144. font-size: 26rpx;
  145. color: #fff;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. .desc-section {
  152. .desc-header {
  153. position: relative;
  154. display: inline-block;
  155. margin-bottom: 16rpx;
  156. .label {
  157. font-size: 30rpx;
  158. font-weight: bold;
  159. color: #333;
  160. position: relative;
  161. z-index: 1;
  162. }
  163. .indicator {
  164. position: absolute;
  165. bottom: 4rpx;
  166. right: 4rpx;
  167. width: 30rpx;
  168. height: 8rpx;
  169. background: #4ED964;
  170. border-radius: 4rpx;
  171. z-index: 0;
  172. }
  173. }
  174. .desc-content {
  175. font-family: Source Han Sans SC;
  176. font-size: 26rpx;
  177. color: #8D8D8D;
  178. line-height: 1.6;
  179. display: block;
  180. text-align: justify;
  181. }
  182. }
  183. }
  184. </style>