index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="hot-item">
  3. <!-- Rank -->
  4. <view class="rank-col">
  5. <image v-if="rank === 1" src="/pages-sell/static/hot/icon-first.png" class="rank-icon" mode="widthFix"></image>
  6. <image v-else-if="rank === 2" src="/pages-sell/static/hot/icon-second.png" class="rank-icon" mode="widthFix"></image>
  7. <image v-else-if="rank === 3" src="/pages-sell/static/hot/icon-third.png" class="rank-icon" mode="widthFix"></image>
  8. <text v-else class="rank-text">{{ rank < 10 ? '0' + rank : rank }}</text>
  9. </view>
  10. <!-- Book Info -->
  11. <view class="book-info" @click.stop="navigateToDetail">
  12. <view class="image-wrapper">
  13. <image :src="item.bookImg" class="book-cover" mode="aspectFill"></image>
  14. <!-- 状态遮罩 -->
  15. <view class="status-mask" v-if="item.availableStock === 0">
  16. <text>暂无库存</text>
  17. </view>
  18. </view>
  19. <view class="info-right">
  20. <text class="title">{{ item.bookName || '-' }}</text>
  21. <text class="author">{{ item.author || '-' }}</text>
  22. <view class="bottom-row">
  23. <view class="price-box">
  24. <text class="currency">¥</text>
  25. <text class="price">{{ item.bookPrice }}</text>
  26. <text class="original">¥{{ item.bookOriginalPrice }}</text>
  27. </view>
  28. <view class="cart-btn" :class="{ 'gray-btn': item.availableStock === 0 && item.hasArrivalNotice === 1 }" @click.stop="handleAction">
  29. <text v-if="item.availableStock === 0 && item.hasArrivalNotice === 1">取消到货通知</text>
  30. <text v-else-if="item.availableStock === 0">到货通知</text>
  31. <text v-else>加入购物车</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { eventBus } from '@/utils/event-bus'
  40. export default {
  41. name: 'HotSellItem',
  42. props: {
  43. rank: {
  44. type: Number,
  45. required: true
  46. },
  47. item: {
  48. type: Object,
  49. required: true
  50. }
  51. },
  52. methods: {
  53. navigateToDetail() {
  54. uni.navigateTo({
  55. url: '/pages-sell/pages/detail?isbn=' + this.item.bookIsbn || ''
  56. });
  57. },
  58. handleAction() {
  59. if (this.item.availableStock === 0) {
  60. this.handleNotify();
  61. } else {
  62. this.handleAddToCart();
  63. }
  64. },
  65. handleNotify() {
  66. const isCancel = this.item.hasArrivalNotice === 1;
  67. const apiUrl = isCancel ? '/token/shop/user/noticeArrivalCancel' : '/token/shop/user/noticeArrival';
  68. uni.$u.http.post(apiUrl, {
  69. isbn: this.item.bookIsbn,
  70. }).then(res => {
  71. if (res.code === 200) {
  72. const newValue = isCancel ? 0 : 1;
  73. this.$emit('update-item', { ...this.item, hasArrivalNotice: newValue });
  74. this.$set(this.item, 'hasArrivalNotice', newValue);
  75. this.item.hasArrivalNotice = newValue;
  76. this.$u.toast(isCancel ? '已取消到货通知' : '到货通知设置成功');
  77. }
  78. });
  79. },
  80. handleAddToCart() {
  81. const product = {
  82. ...this.item,
  83. isbn: this.item.bookIsbn || this.item.isbn || '',
  84. };
  85. eventBus.emit('openSelectGoodPopup', { product, sourceFrom: 1 });
  86. },
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .hot-item {
  92. display: flex;
  93. align-items: center;
  94. padding: 30rpx 0;
  95. border-bottom: 1rpx solid #f6f7f8;
  96. .rank-col {
  97. width: 80rpx;
  98. display: flex;
  99. justify-content: center;
  100. margin-right: 10rpx;
  101. .rank-icon {
  102. width: 60rpx;
  103. height: 60rpx;
  104. }
  105. .rank-text {
  106. font-family: Arial-BoldItalicMT;
  107. font-size: 36rpx;
  108. color: #706F6D;
  109. font-style: italic;
  110. font-weight: bold;
  111. }
  112. }
  113. .book-info {
  114. flex: 1;
  115. display: flex;
  116. align-items: center;
  117. .image-wrapper {
  118. position: relative;
  119. width: 140rpx;
  120. height: 180rpx;
  121. border-radius: 4rpx;
  122. background-color: #f5f5f5;
  123. margin-right: 24rpx;
  124. flex-shrink: 0;
  125. overflow: hidden;
  126. .book-cover {
  127. width: 100%;
  128. height: 100%;
  129. }
  130. .status-mask {
  131. position: absolute;
  132. bottom: 0;
  133. left: 0;
  134. width: 100%;
  135. height: 40rpx;
  136. background-color: rgba(0, 0, 0, 0.6);
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. text {
  141. color: #fff;
  142. font-size: 20rpx;
  143. }
  144. }
  145. }
  146. .info-right {
  147. flex: 1;
  148. height: 190rpx;
  149. display: flex;
  150. flex-direction: column;
  151. justify-content: space-between;
  152. padding: 10rpx 0;
  153. .title {
  154. font-size: 32rpx;
  155. color: #303030;
  156. font-weight: bold;
  157. line-height: 1.2;
  158. overflow: hidden;
  159. text-overflow: ellipsis;
  160. display: -webkit-box;
  161. -webkit-line-clamp: 2;
  162. -webkit-box-orient: vertical;
  163. }
  164. .author {
  165. font-size: 24rpx;
  166. color: #999999;
  167. }
  168. .bottom-row {
  169. display: flex;
  170. justify-content: space-between;
  171. align-items: flex-end;
  172. .price-box {
  173. display: flex;
  174. align-items: baseline;
  175. .currency {
  176. font-size: 36rpx;
  177. color: #D81A00;
  178. font-weight: bold;
  179. margin-right: 6rpx;
  180. }
  181. .price {
  182. font-size: 36rpx;
  183. color: #D81A00;
  184. font-weight: bold;
  185. margin-right: 12rpx;
  186. }
  187. .original {
  188. font-size: 24rpx;
  189. color: #999999;
  190. text-decoration: line-through;
  191. }
  192. }
  193. .cart-btn {
  194. width: 160rpx;
  195. height: 56rpx;
  196. background: linear-gradient(90deg, #4ED964 0%, #38C248 100%);
  197. border-radius: 28rpx;
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. &.gray-btn {
  202. background: #cccccc;
  203. }
  204. text {
  205. font-size: 24rpx;
  206. color: #fff;
  207. font-weight: 500;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. </style>