index.vue 4.6 KB

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