home.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view id="home" style="background-color: #f7f7f5;overflow: hidden;">
  3. <view class="top-bg"></view>
  4. <view class="section carousel-wrapper">
  5. <swiper class="carousel" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
  6. <swiper-item>
  7. <view class="swiper-item">
  8. <image class="image" src="../../static/images/material/carousel01.png" mode=""></image>
  9. </view>
  10. </swiper-item>
  11. <swiper-item>
  12. <view class="swiper-item">
  13. <image class="image" src="../../static/images/material/carousel02.png" mode=""></image>
  14. </view>
  15. </swiper-item>
  16. </swiper>
  17. </view>
  18. <view class="section">
  19. <view class="col-title">
  20. <image class="icon" style="width: 38rpx;height: 43rpx;" src="../../static/images/hot.png" mode="scaleToFill"></image>
  21. <text>今日拿货榜单</text>
  22. </view>
  23. <view class="hot-rank">
  24. <scroll-view scroll-x="true" :show-scrollbar="false" :enable-flex="true" style="white-space: nowrap;">
  25. <template v-for="product in rankProducts">
  26. <product-item type="swiper" :image="product.images|imagesFilter" :title="product.name" :org-price="product.org_price"
  27. :price="product.price"></product-item>
  28. </template>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. <view class="section">
  33. <view class="col-title">
  34. <image class="icon" style="width: 47rpx;height: 47rpx;" src="../../static/images/sale.png" mode="scaleToFill"></image>
  35. <text>最新上线</text>
  36. </view>
  37. <view class="new-rank">
  38. <scroll-view scroll-x="true" :show-scrollbar="false" :enable-flex="true" style="white-space: nowrap;">
  39. <template v-for="product in newProducts">
  40. <product-item type="swiper" :image="product.images|imagesFilter" :title="product.name" :org-price="product.org_price"
  41. :price="product.price"></product-item>
  42. </template>
  43. </scroll-view>
  44. </view>
  45. </view>
  46. <view class="section" style="margin-top: 40upx;">
  47. <view class="col-img-title">
  48. <image src="../../static/images/like.png" mode="scaleToFill" style="height: 28rpx;width: 363rpx;"></image>
  49. </view>
  50. <view class="like">
  51. <template v-for="product in likeProducts">
  52. <product-item type="list" :image="product.images|imagesFilter" :title="product.name" :org-price="product.org_price"
  53. :price="product.price"></product-item>
  54. </template>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. data() {
  62. return {
  63. rankProducts: [],
  64. newProducts: [],
  65. likeProducts: [],
  66. page: 1,
  67. pageLoading: false
  68. }
  69. },
  70. components: {},
  71. onLoad() {
  72. this.getRankProductData();
  73. this.getNewProductData();
  74. this.getLikeProductsData();
  75. },
  76. onShow() {},
  77. onPageScroll(e) {
  78. const query = uni.createSelectorQuery();
  79. query.select("#home").boundingClientRect(data => {
  80. if (e.scrollTop > data.height - uni.getSystemInfoSync().windowHeight * 2) {
  81. this.getLikeProductsData();
  82. }
  83. }).exec();
  84. },
  85. onNavigationBarButtonTap(e) {
  86. // console.log(e)
  87. switch (e.index) {
  88. case 0:
  89. uni.navigateTo({
  90. url: '/pages/message/message'
  91. });
  92. break;
  93. default:
  94. break;
  95. }
  96. },
  97. methods: {
  98. getRankProductData() {
  99. this.$http.get({
  100. url: "/product/rand",
  101. data: {
  102. limit: 10
  103. },
  104. success: (res) => {
  105. this.rankProducts = res.data.data
  106. }
  107. })
  108. },
  109. getNewProductData() {
  110. this.$http.get({
  111. url: "/product/rand",
  112. data: {
  113. limit: 10
  114. },
  115. success: (res) => {
  116. this.newProducts = res.data.data
  117. }
  118. })
  119. },
  120. getLikeProductsData() {
  121. if (!this.pageLoading) {
  122. console.log("加载下一页");
  123. this.pageLoading = true;
  124. this.$http.get({
  125. url: "/product/lists",
  126. data: {
  127. limit: 10,
  128. page: this.page,
  129. },
  130. success: (res) => {
  131. this.likeProducts = [...this.likeProducts, ...res.data.data.rows]
  132. this.page++;
  133. this.pageLoading = false;
  134. }
  135. })
  136. }
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss">
  142. .search {
  143. background-color: #FFFFFF;
  144. width: 100%;
  145. height: 60rpx;
  146. line-height: 60rpx;
  147. border-radius: 30rpx;
  148. text-align: center;
  149. color: #999999;
  150. }
  151. .top-bg {
  152. position: absolute;
  153. top: 0;
  154. width: 100%;
  155. height: 300rpx;
  156. background-color: $primary-color;
  157. overflow: hidden;
  158. }
  159. .top-bg::after {
  160. background: #F8F8F8;
  161. position: absolute;
  162. border-radius: 2000rpx;
  163. content: "";
  164. width: 4000rpx;
  165. height: 4000rpx;
  166. top: 260rpx;
  167. left: -1625rpx;
  168. }
  169. .carousel-wrapper {
  170. margin-top: 20rpx;
  171. .carousel {
  172. margin: auto;
  173. overflow: hidden;
  174. border-radius: 20rpx;
  175. transform: translateY(0);
  176. width: 702rpx;
  177. height: 340rpx;
  178. .image {
  179. width: 702rpx;
  180. height: 340rpx;
  181. }
  182. }
  183. }
  184. .section {
  185. // padding: 20rpx;
  186. }
  187. .col-title {
  188. height: 60rpx;
  189. line-height: 60rpx;
  190. font-weight: bold;
  191. display: flex;
  192. align-items: center;
  193. padding: 20upx 20upx 10upx 20upx;
  194. .icon {
  195. // vertical-align: middle;
  196. margin-right: 12rpx;
  197. }
  198. }
  199. .col-img-title {
  200. text-align: center;
  201. background: white;
  202. height: 80upx;
  203. line-height: 80upx;
  204. }
  205. .hot-rank .product-item,
  206. .new-rank .product-item {
  207. margin: 5rpx;
  208. &:first-child {
  209. margin-left: 20upx;
  210. }
  211. &:last-child {
  212. margin-right: 20upx;
  213. }
  214. }
  215. .like {
  216. display: flex;
  217. justify-content: space-between;
  218. flex-wrap: wrap;
  219. padding: 10upx 20upx;
  220. }
  221. .like .product-item {
  222. margin-bottom: 10upx;
  223. }
  224. </style>