home.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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" :id="product.id" :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" :id="product.id" :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" :id="product.id" :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. // uni.showModal({
  76. // title: '清除launchFlag值',
  77. // content: '确定要清除launchFlag值,进行重启测试?',
  78. // success: function (res) {
  79. // if (res.confirm) {
  80. // console.log('用户点击确定');
  81. // // 清除缓存
  82. // uni.clearStorage();
  83. // uni.showToast({
  84. // icon: 'none',
  85. // duration:3000,
  86. // title: '清除成功2秒后重启'
  87. // });
  88. // // 两秒后重启
  89. // setTimeout(function() {
  90. // uni.hideToast();
  91. // plus.runtime.restart();
  92. // }, 2000);
  93. // } else if (res.cancel) {
  94. // console.log('用户点击取消');
  95. // }
  96. // }
  97. // });
  98. },
  99. onShow() {},
  100. onPageScroll(e) {
  101. const query = uni.createSelectorQuery();
  102. query.select("#home").boundingClientRect(data => {
  103. if (e.scrollTop > data.height - uni.getSystemInfoSync().windowHeight * 2) {
  104. this.getLikeProductsData();
  105. }
  106. }).exec();
  107. },
  108. onNavigationBarButtonTap(e) {
  109. // console.log(e)
  110. switch (e.index) {
  111. case 0:
  112. uni.navigateTo({
  113. url: '/pages/message/message'
  114. });
  115. break;
  116. default:
  117. break;
  118. }
  119. },
  120. methods: {
  121. getRankProductData() {
  122. this.$http.get({
  123. url: "/product/rand",
  124. data: {
  125. limit: 10
  126. },
  127. success: (res) => {
  128. this.rankProducts = res.data.data
  129. }
  130. })
  131. },
  132. getNewProductData() {
  133. this.$http.get({
  134. url: "/product/rand",
  135. data: {
  136. limit: 10
  137. },
  138. success: (res) => {
  139. this.newProducts = res.data.data
  140. }
  141. })
  142. },
  143. getLikeProductsData() {
  144. if (!this.pageLoading) {
  145. console.log("加载下一页");
  146. this.pageLoading = true;
  147. this.$http.get({
  148. url: "/product/lists",
  149. data: {
  150. limit: 10,
  151. page: this.page,
  152. },
  153. success: (res) => {
  154. this.likeProducts = [...this.likeProducts, ...res.data.data.rows]
  155. this.page++;
  156. this.pageLoading = false;
  157. }
  158. })
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss">
  165. .search {
  166. background-color: #FFFFFF;
  167. width: 100%;
  168. height: 60rpx;
  169. line-height: 60rpx;
  170. border-radius: 30rpx;
  171. text-align: center;
  172. color: #999999;
  173. }
  174. .top-bg {
  175. position: absolute;
  176. top: 0;
  177. width: 100%;
  178. height: 300rpx;
  179. background-color: $primary-color;
  180. overflow: hidden;
  181. }
  182. .top-bg::after {
  183. background: #F8F8F8;
  184. position: absolute;
  185. border-radius: 2000rpx;
  186. content: "";
  187. width: 4000rpx;
  188. height: 4000rpx;
  189. top: 260rpx;
  190. left: -1625rpx;
  191. }
  192. .carousel-wrapper {
  193. margin-top: 20rpx;
  194. .carousel {
  195. margin: auto;
  196. overflow: hidden;
  197. border-radius: 20rpx;
  198. transform: translateY(0);
  199. width: 702rpx;
  200. height: 340rpx;
  201. .image {
  202. width: 702rpx;
  203. height: 340rpx;
  204. }
  205. }
  206. }
  207. .section {
  208. // padding: 20rpx;
  209. }
  210. .col-title {
  211. height: 60rpx;
  212. line-height: 60rpx;
  213. font-weight: bold;
  214. display: flex;
  215. align-items: center;
  216. padding: 20upx 20upx 10upx 20upx;
  217. .icon {
  218. // vertical-align: middle;
  219. margin-right: 12rpx;
  220. }
  221. }
  222. .col-img-title {
  223. text-align: center;
  224. background: white;
  225. height: 80upx;
  226. line-height: 80upx;
  227. }
  228. .hot-rank .product-item,
  229. .new-rank .product-item {
  230. margin: 5rpx;
  231. &:first-child {
  232. margin-left: 20upx;
  233. }
  234. &:last-child {
  235. margin-right: 20upx;
  236. }
  237. }
  238. .like {
  239. display: flex;
  240. justify-content: space-between;
  241. flex-wrap: wrap;
  242. padding: 10upx 20upx;
  243. }
  244. .like .product-item {
  245. margin-bottom: 10upx;
  246. }
  247. </style>