home.vue 6.3 KB

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