index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="recommend-item" @click="handleClick">
  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. // 加入购物车时,传递 sourceFrom 参数为 2
  73. this.$refs.popup.open(this.item, props.showDesc ? 2 : 1);
  74. },
  75. onPopupConfirm(data) {
  76. // Emit the confirmed data
  77. this.$emit('add-cart', data);
  78. },
  79. //图书详情页
  80. handleClick() {
  81. uni.navigateTo({
  82. url: '/pages-sell/pages/detail?isbn=' + this.item.isbn
  83. });
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .recommend-item {
  90. padding: 30rpx 0;
  91. border-bottom: 1rpx dashed #EEEEEE;
  92. .main-info {
  93. display: flex;
  94. margin-bottom: 30rpx;
  95. .book-cover {
  96. width: 172rpx;
  97. height: 220rpx;
  98. border-radius: 8rpx;
  99. margin-right: 24rpx;
  100. flex-shrink: 0;
  101. }
  102. .info-right {
  103. flex: 1;
  104. display: flex;
  105. flex-direction: column;
  106. justify-content: space-between;
  107. padding: 4rpx 0;
  108. .title-author {
  109. .title {
  110. font-size: 32rpx;
  111. font-weight: bold;
  112. color: #333;
  113. margin-bottom: 12rpx;
  114. display: block;
  115. line-height: 1.4;
  116. }
  117. .author {
  118. font-size: 24rpx;
  119. color: #999;
  120. }
  121. }
  122. .price-action {
  123. display: flex;
  124. justify-content: space-between;
  125. align-items: flex-end;
  126. .price-box {
  127. .currency {
  128. font-size: 24rpx;
  129. color: #FF4B4B;
  130. font-weight: bold;
  131. }
  132. .price {
  133. font-size: 36rpx;
  134. color: #FF4B4B;
  135. font-weight: bold;
  136. margin-right: 12rpx;
  137. }
  138. .original {
  139. font-size: 24rpx;
  140. color: #999;
  141. text-decoration: line-through;
  142. }
  143. }
  144. .cart-btn {
  145. background: #38C248;
  146. border-radius: 30rpx;
  147. height: 60rpx;
  148. line-height: 60rpx;
  149. padding: 0 24rpx;
  150. text {
  151. font-size: 26rpx;
  152. color: #fff;
  153. }
  154. }
  155. }
  156. }
  157. }
  158. .desc-section {
  159. .desc-header {
  160. position: relative;
  161. display: inline-block;
  162. margin-bottom: 16rpx;
  163. .label {
  164. font-size: 30rpx;
  165. font-weight: bold;
  166. color: #333;
  167. position: relative;
  168. z-index: 1;
  169. }
  170. .indicator {
  171. position: absolute;
  172. bottom: 4rpx;
  173. right: 4rpx;
  174. width: 30rpx;
  175. height: 8rpx;
  176. background: #4ED964;
  177. border-radius: 4rpx;
  178. z-index: 0;
  179. }
  180. }
  181. .desc-content {
  182. font-family: Source Han Sans SC;
  183. font-size: 26rpx;
  184. color: #8D8D8D;
  185. line-height: 1.6;
  186. display: block;
  187. text-align: justify;
  188. }
  189. }
  190. }
  191. </style>