index.vue 5.4 KB

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