index.vue 4.1 KB

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