index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="hot-item" @click="navigateToDetail">
  3. <view class="image-wrapper">
  4. <image :src="item.cover" class="book-cover" mode="aspectFill"></image>
  5. <!-- 状态遮罩 -->
  6. <view class="status-mask" v-if="item.availableStock === 0">
  7. <text>暂无库存</text>
  8. </view>
  9. </view>
  10. <view class="info-right">
  11. <view class="info-top">
  12. <text class="title">{{ item.name || '-' }}</text>
  13. <view class="price-row">
  14. <text class="currency">¥</text>
  15. <text class="price">{{ item.productPrice }}</text>
  16. </view>
  17. <view class="flex space-between">
  18. <view class="discount-tag" v-if="item.discountDesc">
  19. <text class="discount">{{ item.discountDesc }}</text>
  20. <text class="discount-desc">省{{ item.discountPrice }}元</text>
  21. </view>
  22. <view class="btn-cart" :class="{ 'gray-btn': item.availableStock === 0 && item.hasArrivalNotice === 1 }" @click.stop="handleAction">
  23. <text v-if="item.availableStock === 0 && item.hasArrivalNotice === 1">取消到货通知</text>
  24. <text v-else-if="item.availableStock === 0">到货通知</text>
  25. <text v-else>加入购物车</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { eventBus } from '@/utils/event-bus'
  34. export default {
  35. name: 'HotRecommendItem',
  36. props: {
  37. item: {
  38. type: Object,
  39. required: true,
  40. default: () => ({})
  41. }
  42. },
  43. methods: {
  44. navigateToDetail() {
  45. uni.navigateTo({
  46. url: '/pages-sell/pages/detail?isbn=' + this.item.isbn
  47. });
  48. },
  49. handleAction() {
  50. if (this.item.availableStock === 0) {
  51. this.handleNotify();
  52. } else {
  53. this.handleAddToCart();
  54. }
  55. },
  56. handleNotify() {
  57. const isCancel = this.item.hasArrivalNotice === 1;
  58. const apiUrl = isCancel ? '/token/shop/user/noticeArrivalCancel' : '/token/shop/user/noticeArrival';
  59. uni.$u.http.post(apiUrl, {
  60. isbn: this.item.isbn,
  61. }).then(res => {
  62. if (res.code === 200) {
  63. const newValue = isCancel ? 0 : 1;
  64. // Notify parent component to update the item
  65. this.$emit('update-item', { ...this.item, hasArrivalNotice: newValue });
  66. // Try updating local object properties directly (Vue reactivity)
  67. this.$set(this.item, 'hasArrivalNotice', newValue);
  68. this.item.hasArrivalNotice = newValue;
  69. this.$u.toast(isCancel ? '已取消到货通知' : '到货通知设置成功');
  70. }
  71. });
  72. },
  73. handleAddToCart() {
  74. eventBus.emit('openSelectGoodPopup', { product: this.item, sourceFrom: 1 });
  75. },
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .hot-item {
  81. display: flex;
  82. border-radius: 16rpx;
  83. .image-wrapper {
  84. position: relative;
  85. width: 140rpx;
  86. height: 180rpx;
  87. border-radius: 4rpx;
  88. background-color: #f5f5f5;
  89. margin-right: 20rpx;
  90. flex-shrink: 0;
  91. overflow: hidden;
  92. .book-cover {
  93. width: 100%;
  94. height: 100%;
  95. }
  96. .status-mask {
  97. position: absolute;
  98. bottom: 0;
  99. left: 0;
  100. width: 100%;
  101. height: 40rpx;
  102. background-color: rgba(0, 0, 0, 0.6);
  103. display: flex;
  104. justify-content: center;
  105. align-items: center;
  106. text {
  107. color: #fff;
  108. font-size: 20rpx;
  109. }
  110. }
  111. }
  112. .info-right {
  113. flex: 1;
  114. .info-top {
  115. height: 100%;
  116. display: flex;
  117. flex-direction: column;
  118. justify-content: space-between;
  119. .title {
  120. font-size: 30rpx;
  121. font-weight: bold;
  122. color: #333;
  123. margin-bottom: 10rpx;
  124. display: block;
  125. }
  126. .price-row {
  127. display: flex;
  128. align-items: baseline;
  129. margin-bottom: 10rpx;
  130. .currency {
  131. font-size: 32rpx;
  132. color: #D81A00;
  133. font-weight: bold;
  134. }
  135. .price {
  136. font-size: 36rpx;
  137. color: #D81A00;
  138. font-weight: bold;
  139. }
  140. }
  141. .discount-tag {
  142. display: inline-block;
  143. border-radius: 10rpx;
  144. font-family: Source Han Sans SC;
  145. font-weight: 500;
  146. font-size: 22rpx;
  147. height: 40rpx;
  148. line-height: 40rpx;
  149. background-color: #fff;
  150. border: 2rpx solid #D81A00;
  151. box-sizing: border-box;
  152. overflow: auto;
  153. .discount {
  154. background: #D81A00;
  155. color: #fff;
  156. display: inline-block;
  157. padding: 0 12rpx;
  158. box-sizing: border-box;
  159. }
  160. .discount-desc {
  161. color: #D81A00;
  162. padding: 0 10rpx;
  163. }
  164. }
  165. }
  166. .btn-cart {
  167. align-self: flex-end;
  168. background: #38C248;
  169. border-radius: 30rpx;
  170. height: 60rpx;
  171. display: flex;
  172. align-items: center;
  173. justify-content: center;
  174. padding: 0 20rpx;
  175. &.gray-btn {
  176. background: #cccccc;
  177. }
  178. text {
  179. font-size: 28rpx;
  180. color: #fff;
  181. }
  182. }
  183. }
  184. }
  185. </style>