123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <template>
- <view id="home" style="background-color: #f7f7f5;overflow: hidden;">
- <view class="top-bg"></view>
- <view class="section carousel-wrapper">
- <swiper class="carousel" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
- <swiper-item>
- <view class="swiper-item">
- <image class="image" src="../../static/images/material/carousel01.png" mode=""></image>
- </view>
- </swiper-item>
- <swiper-item>
- <view class="swiper-item">
- <image class="image" src="../../static/images/material/carousel02.png" mode=""></image>
- </view>
- </swiper-item>
- </swiper>
- </view>
- <view class="section">
- <view class="col-title">
- <image class="icon" style="width: 38rpx;height: 43rpx;" src="../../static/images/hot.png" mode="scaleToFill"></image>
- <text>今日拿货榜单</text>
- </view>
- <view class="hot-rank">
- <scroll-view scroll-x="true" :show-scrollbar="false" :enable-flex="true" style="white-space: nowrap;">
- <template v-for="product in rankProducts">
- <product-item type="swiper" :id="product.id" :image="product.images|imagesFilter" :title="product.name" :org-price="product.org_price"
- :price="product.price"></product-item>
- </template>
- </scroll-view>
- </view>
- </view>
- <view class="section">
- <view class="col-title">
- <image class="icon" style="width: 47rpx;height: 47rpx;" src="../../static/images/sale.png" mode="scaleToFill"></image>
- <text>最新上线</text>
- </view>
- <view class="new-rank">
- <scroll-view scroll-x="true" :show-scrollbar="false" :enable-flex="true" style="white-space: nowrap;">
- <template v-for="product in newProducts">
- <product-item type="swiper" :id="product.id" :image="product.images|imagesFilter" :title="product.name" :org-price="product.org_price"
- :price="product.price"></product-item>
- </template>
- </scroll-view>
- </view>
- </view>
- <view class="section" style="margin-top: 40upx;">
- <view class="col-img-title">
- <image src="../../static/images/like.png" mode="scaleToFill" style="height: 28rpx;width: 363rpx;"></image>
- </view>
- <view class="like">
- <template v-for="product in likeProducts">
- <product-item type="list" :id="product.id" :image="product.images|imagesFilter" :title="product.name" :org-price="product.org_price"
- :price="product.price"></product-item>
- </template>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- rankProducts: [],
- newProducts: [],
- likeProducts: [],
- page: 1,
- pageLoading: false
- }
- },
- components: {},
- onLoad() {
- this.getRankProductData();
- this.getNewProductData();
- this.getLikeProductsData();
-
- // uni.showModal({
- // title: '清除launchFlag值',
- // content: '确定要清除launchFlag值,进行重启测试?',
- // success: function (res) {
- // if (res.confirm) {
- // console.log('用户点击确定');
- // // 清除缓存
- // uni.clearStorage();
- // uni.showToast({
- // icon: 'none',
- // duration:3000,
- // title: '清除成功2秒后重启'
- // });
- // // 两秒后重启
- // setTimeout(function() {
- // uni.hideToast();
- // plus.runtime.restart();
- // }, 2000);
- // } else if (res.cancel) {
- // console.log('用户点击取消');
- // }
- // }
- // });
- },
- onShow() {},
- onPageScroll(e) {
- const query = uni.createSelectorQuery();
- query.select("#home").boundingClientRect(data => {
- if (e.scrollTop > data.height - uni.getSystemInfoSync().windowHeight * 2) {
- this.getLikeProductsData();
- }
- }).exec();
- },
- onNavigationBarButtonTap(e) {
- // console.log(e)
- switch (e.index) {
- case 0:
- uni.navigateTo({
- url: '/pages/message/message'
- });
- break;
- default:
- break;
- }
- },
- methods: {
- getRankProductData() {
- this.$http.get({
- url: "/product/rand",
- data: {
- limit: 10
- },
- success: (res) => {
- this.rankProducts = res.data.data
- }
- })
- },
- getNewProductData() {
- this.$http.get({
- url: "/product/rand",
- data: {
- limit: 10
- },
- success: (res) => {
- this.newProducts = res.data.data
- }
- })
- },
- getLikeProductsData() {
- if (!this.pageLoading) {
- console.log("加载下一页");
- this.pageLoading = true;
- this.$http.get({
- url: "/product/lists",
- data: {
- limit: 10,
- page: this.page,
- },
- success: (res) => {
- this.likeProducts = [...this.likeProducts, ...res.data.data.rows]
- this.page++;
- this.pageLoading = false;
- }
- })
- }
- }
- }
- }
- </script>
- <style lang="scss">
- .search {
- background-color: #FFFFFF;
- width: 100%;
- height: 60rpx;
- line-height: 60rpx;
- border-radius: 30rpx;
- text-align: center;
- color: #999999;
- }
- .top-bg {
- position: absolute;
- top: 0;
- width: 100%;
- height: 300rpx;
- background-color: $primary-color;
- overflow: hidden;
- }
- .top-bg::after {
- background: #F8F8F8;
- position: absolute;
- border-radius: 2000rpx;
- content: "";
- width: 4000rpx;
- height: 4000rpx;
- top: 260rpx;
- left: -1625rpx;
- }
- .carousel-wrapper {
- margin-top: 20rpx;
- .carousel {
- margin: auto;
- overflow: hidden;
- border-radius: 20rpx;
- transform: translateY(0);
- width: 702rpx;
- height: 340rpx;
- .image {
- width: 702rpx;
- height: 340rpx;
- }
- }
- }
- .section {
- // padding: 20rpx;
- }
- .col-title {
- height: 60rpx;
- line-height: 60rpx;
- font-weight: bold;
- display: flex;
- align-items: center;
- padding: 20upx 20upx 10upx 20upx;
- .icon {
- // vertical-align: middle;
- margin-right: 12rpx;
- }
- }
- .col-img-title {
- text-align: center;
- background: white;
- height: 80upx;
- line-height: 80upx;
- }
- .hot-rank .product-item,
- .new-rank .product-item {
- margin: 5rpx;
- &:first-child {
- margin-left: 20upx;
- }
- &:last-child {
- margin-right: 20upx;
- }
- }
- .like {
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- padding: 10upx 20upx;
- }
- .like .product-item {
- margin-bottom: 10upx;
- }
- </style>
|