Files
ZhHealth/pages/store/index.vue
2022-01-06 17:09:07 +08:00

272 lines
5.8 KiB
Vue

<template>
<view class="content">
<!-- swiper -->
<view class="swiper">
<view class="swiper-box">
<swiper autoplay @change="swiperCount = $event.detail.current">
<swiper-item v-for="(item, index) in banners" :key="index">
<image :src="item.cover" mode="aspectFill"></image>
</swiper-item>
</swiper>
<view class="swiper-pages">
<block v-for="(item, index) in banners" :key="index">
<text class="pages-item" :class="{'show':swiperCount === index}"></text>
</block>
</view>
</view>
</view>
<!-- 健康产品分类 -->
<u-scroll-list class="classify-box" indicatorColor="#ddd" indicatorActiveColor="#34CE98">
<view v-for="(item, index) in goodTabs" :key="index" class="classify-item">
<view class="classify-item-nav">
<image class="classify-item-cover" :src="item.cover"></image>
<view class="classify-item-title">{{item.name}}</view>
</view>
</view>
</u-scroll-list>
<!-- 每日上新 -->
<view class="new-box">
<view class="title">上新精选</view>
<view class="news">
<view class="news-item" v-for="(item, index) in newGood" :key="index">
<view class="news-cover">
<image :src="item.cover" mode="aspectFill"></image>
</view>
<view class="news-title nowrap">{{item.name}}</view>
<view class="news-price nowrap">{{item.price.price_min}}</view>
</view>
</view>
</view>
<!-- 推荐品类 -->
<view class="card-box">
<block v-for="(item, index) in meals" :key="index">
<view class="card-box-item" :style="{'backgrond': item.color}" @click="$Router.push({name: 'StoreList', params: {id: item.meal_id}})">
<view class="card-title">{{item.title}}</view>
<view class="card-subtitle">{{item.subtitle}}</view>
<image class="card-cover" :src="item.cover" mode="aspectFill"></image>
</view>
</block>
</view>
<!-- goods -->
<view class="goods-box">
<oct-goods
:lists="goodsArr"
color="#e6576b"
@onGoods="$Router.push({ name: 'StoreGoods', params: {id: $event.goods_id}})"
/>
<!-- <u-loadmore status="loading" /> -->
</view>
</view>
</template>
<script>
import { mall } from "@/apis/interfaces/store"
export default {
data() {
return {
swiperCount : 0,
banners : [],
goodTabs : [],
newGood : [],
goodsArr : [],
meals : []
};
},
mounted(){
this.getMall()
},
methods:{
getMall(){
mall().then(res => {
console.log(res)
this.banners = res.banners
this.goodsArr = res.goods
this.newGood = res.news
this.goodTabs = res.categories
this.meals = res.meals
uni.stopPullDownRefresh()
}).catch(err => {
console.log(err)
})
}
},
onPullDownRefresh() {
this.getMall()
}
}
</script>
<style lang="scss">
.content{
background: $window-color;
}
// 商城列表
.goods-box{
padding-bottom: $padding;
&>.title{
padding: $padding $padding 0;
font-size: $title-size-lg;
color: $text-color;
font-weight: bold;
margin-bottom: -$margin/2;
}
}
// 商城分类
.classify-box{
.classify-item{
padding: 0 10rpx;
&:last-child{
padding-right: $padding;
}
&:first-child{
padding-left: $padding;
}
&-nav{
text-align: center;
width: 138rpx;
}
&-cover{
width: 86rpx;
height: 86rpx;
border-radius: 50%;
vertical-align: top;
margin-bottom: $margin/2;
}
&-title{
line-height: 40rpx;
font-size: $title-size-sm;
color: $text-color;
}
}
}
// 卡片推荐
.card-box{
padding: $padding $padding - 10;
padding-bottom: 0;
display: flex;
flex-wrap: wrap;
&-item{
margin: 0 10rpx;
width: calc(50% - 20rpx);
padding: $padding;
border-radius: $radius;
box-sizing: border-box;
position: relative;
.card-title{
font-size: $title-size-lg;
font-weight: bold;
color: $text-color;
line-height: 40rpx;
@extend .nowrap;
}
.card-subtitle{
font-size: 20rpx;
color: $text-gray;
line-height: 40rpx;
@extend .nowrap;
}
.card-cover{
width: 80rpx;
height: 80rpx;
position: absolute;
right: $margin;
top: $margin;
}
}
&-item:nth-child(1){
background: #fef2ae;
}
&-item:nth-child(2){
background: #c9ead9;
}
}
// 上新精选
.new-box{
padding: 0 $margin;
border-radius: $radius;
// padding: $padding - 10;
.title{
font-size: $title-size-lg;
color: $text-color;
font-weight: bold;
}
.news{
margin: $margin/2 -10rpx 0;
display: flex;
.news-item{
margin: 0 10rpx;
width: calc(25% - 20rpx);
.news-cover{
position: relative;
width: 100%;
padding-top: 100%;
background-color: white;
border-radius: $radius-lg;
overflow: hidden;
image{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
.news-title{
margin-top: $margin/2;
font-size: $title-size-sm;
text-align: center;
color: $text-color;
line-height: 40rpx;
}
.news-price{
text-align: center;
font-size: $title-size-sm;
font-weight: bold;
color: $text-price;
line-height: 40rpx;
}
}
}
}
// swiper
.swiper{
background: linear-gradient(#FFF, #F3F6FB);
padding: $padding;
.swiper-box{
position: relative;
padding-top: 40%;
swiper,
image{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
image{
border-radius: $radius;
}
}
.swiper-pages{
position: absolute;
z-index: 9;
left: 0;
right: 0;
bottom: $margin - 10;
height: 7rpx;
text-align: center;
.pages-item{
vertical-align: top;
display: inline-block;
height: 7rpx;
width: 25rpx;
margin: 0 5rpx;
background: rgba($color: #fff, $alpha: .5);
&.show{
background: white;
}
}
}
}
</style>