index.vue 4.2 KB

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