Q3学习计划
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.0 KiB

  1. <template>
  2. <!-- 猜你喜欢 -->
  3. <view class="caption">
  4. <text class="text">猜你喜欢</text>
  5. </view>
  6. <view class="guess">
  7. <navigator
  8. class="guess-item"
  9. v-for="item in guessList"
  10. :key="item.id"
  11. :url="`/pages/goods/goods?id=${item.id}`"
  12. >
  13. <image class="image" mode="aspectFill" :src="item.picture"></image>
  14. <view class="name"> {{ item.name }} </view>
  15. <view class="price">
  16. <text class="small">¥</text>
  17. <text>{{ item.price }}</text>
  18. </view>
  19. </navigator>
  20. </view>
  21. <view class="loading-text">
  22. {{ finish ? '没有更多数据~' : '正在加载...' }}
  23. </view>
  24. </template>
  25. <script setup lang="ts">
  26. import type { GuessItem } from '@/types/home'
  27. import { getHomeGoodsGuessLikeAPI } from '@/services/home'
  28. import { onMounted, ref } from 'vue'
  29. import type { PageParams } from '@/types/global'
  30. // 分页参数
  31. const pageParams: Required<PageParams> = {
  32. page: 1,
  33. pageSize: 10,
  34. }
  35. // 猜你喜欢的列表
  36. const guessList = ref<GuessItem[]>([])
  37. // 已结束标记
  38. const finish = ref(false)
  39. // 获取猜你喜欢数据
  40. const getHomeGoodsGuessLikeData = async () => {
  41. // 退出分页判断
  42. if (finish.value === true) {
  43. return uni.showToast({ icon: 'none', title: '没有更多数据~' })
  44. }
  45. const res = await getHomeGoodsGuessLikeAPI()
  46. // guessList.value = res.result.items
  47. // 数组追加
  48. guessList.value.push(...res.result.items)
  49. // 分页条件
  50. if (pageParams.page < res.result.pages) {
  51. // 页码累加
  52. pageParams.page++
  53. } else {
  54. finish.value = true
  55. }
  56. }
  57. // 组件挂载完毕
  58. onMounted(() => {
  59. getHomeGoodsGuessLikeData()
  60. })
  61. // 暴露方法
  62. defineExpose({
  63. getMore: getHomeGoodsGuessLikeData,
  64. })
  65. </script>
  66. <style lang="scss">
  67. :host {
  68. display: block;
  69. }
  70. /* 分类标题 */
  71. .caption {
  72. display: flex;
  73. justify-content: center;
  74. line-height: 1;
  75. padding: 36rpx 0 40rpx;
  76. font-size: 32rpx;
  77. color: #262626;
  78. .text {
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. padding: 0 28rpx 0 30rpx;
  83. &::before,
  84. &::after {
  85. content: '';
  86. width: 20rpx;
  87. height: 20rpx;
  88. background-image: url(@/static/images/bubble.png);
  89. background-size: contain;
  90. margin: 0 10rpx;
  91. }
  92. }
  93. }
  94. /* 猜你喜欢 */
  95. .guess {
  96. display: flex;
  97. flex-wrap: wrap;
  98. justify-content: space-between;
  99. padding: 0 20rpx;
  100. .guess-item {
  101. width: 345rpx;
  102. padding: 24rpx 20rpx 20rpx;
  103. margin-bottom: 20rpx;
  104. border-radius: 10rpx;
  105. overflow: hidden;
  106. background-color: #fff;
  107. }
  108. .image {
  109. width: 304rpx;
  110. height: 304rpx;
  111. }
  112. .name {
  113. height: 75rpx;
  114. margin: 10rpx 0;
  115. font-size: 26rpx;
  116. color: #262626;
  117. overflow: hidden;
  118. text-overflow: ellipsis;
  119. display: -webkit-box;
  120. -webkit-line-clamp: 2;
  121. -webkit-box-orient: vertical;
  122. }
  123. .price {
  124. line-height: 1;
  125. padding-top: 4rpx;
  126. color: #cf4444;
  127. font-size: 26rpx;
  128. }
  129. .small {
  130. font-size: 80%;
  131. }
  132. }
  133. // 加载提示文字
  134. .loading-text {
  135. text-align: center;
  136. font-size: 28rpx;
  137. color: #666;
  138. padding: 20rpx 0;
  139. }
  140. </style>