martial-arts/pages/tabbar/pagehome/pagehome.vue

226 lines
6.5 KiB
Vue

<template>
<view>
<status-container :ifReturn="false" titlet="传武佳小程序">
<view slot="content">
<view class="" style="margin-top: -20rpx;">
<swiper-pu newBottom="20rpx" newHeight="460rpx"></swiper-pu>
</view>
<view class="posi-sticky" :style="{top:newtop+'px'}">
<swiper-tab id="tab" :list="dataList" v-model="current" @changeEv="clickTab" :itemColor="'#e42417'" :lineColor="'#e42417'"></swiper-tab>
</view>
<view class="pad-zy20 pad-s25" v-if="ifLoading">
<view class="" v-if="bigCourse.length">
<view class="radius8 bacf pad10 boxshow1" v-for="(item,index) in bigCourse" :key="index">
<view class="posir">
<image :src="item.cover" style="height: 518rpx;" mode="aspectFill" class="width100" lazy-load></image>
<view class="posia-xzy bac5 fon24 colf pad18">
<view class="clips1">{{item.name}}</view>
<view class="disjbac ae">
<view class="">
<span class="bold">¥{{item.price}}</span>
<span class="fon20 colf8 mar-z20 tline-through">¥{{item.original_price}}</span>
</view>
<view class="radius18 pad-zy12 pad-sx4 borbot-f disjcac">购买</view>
</view>
</view>
</view>
</view>
</view>
<view class="" v-else>
<pitera textStr="查询课程列表无果o(╥﹏╥)o" textColor="#b0aaa9" paddingStr="40rpx 0 20rpx 0"></pitera>
</view>
<!-- 两列列表 start -->
<list ref="refcourse" @goDetail="goCourseDetail"></list>
<!-- 两列列表 end -->
<!-- 推荐视频 start -->
<view class="disjb ae mar-s40 mar-x20">
<view class="fon32 bold colb">推荐视频</view>
<view class="fon20" style="color: #bbb4b3;" @tap="goMore(0)">更多+</view>
</view>
<view class="radius8 bacf pad10 boxshow1 mar-x30" v-for="(item,index) in videoList" :key="index">
<view class="posir disjcac">
<image :src="item.cover" style="height: 388rpx;" mode="aspectFill" class="width100" lazy-load></image>
<image @tap="palyVideo(index)" class="posia" src="/static/tabbar/icon-play.png" mode="" style="width: 70rpx;height: 70rpx;" lazy-load></image>
</view>
<view class="fon24 pad-sx16 disjcac" style="color: #262626;">
<view class="clips2">{{item.title}}</view>
</view>
</view>
<!-- 推荐视频 end -->
<!-- 推荐商品 start -->
<view class="disjb ae mar-s40">
<view class="fon32 bold colb">推荐商品</view>
<view class="fon20" style="color: #bbb4b3;" @tap="goMore(1)">+</view>
</view>
<list ref="refshop" @goDetail="goShopDetail"></list>
<!-- end -->
</view>
</view>
</status-container>
<!-- 底部tab -->
<foot-tab></foot-tab>
</view>
</template>
<script>
import swiperPu from '@/components/swipers/swiper-pu.vue';
import swiperTab from '@/components/swiper-tab/swiper-tab.vue';
import footTab from '@/components/foot-tabs/foot-tab.vue';
import list from '@/components/list.vue';
import pitera from '@/components/nothing/pitera.vue';
export default {
components:{
'foot-tab' :footTab,
swiperTab,
swiperPu,
list,
pitera
},
data() {
return {
newtop:uni.getSystemInfoSync().statusBarHeight + 40,
current:0,
dataList:[],//分类列表
classId:'',//分类id
bigCourse:[],
videoList:[],//推荐视频
ifLoading:false,
ifCount:0
}
},
onShow() {
// 开启banner图自动轮播
this.$store.commit('setAutoplay',true);
},
onHide() {
// 关闭banner图自动轮播
this.$store.commit('setAutoplay',false);
},
onLoad() {
// 调用获取分类列表
this.getCourseCate();
},
methods: {
// tab点击事件
clickTab(index){
this.current = index;
// 设置分类id
this.classId = this.dataList[index].id;
this.bigCourse = [];
this.$refs.refcourse.list = [];
this.ifCount++;
// 调用获取课程列表
this.getCourseList();
},
// 获取分类列表
getCourseCate(){
this.$requst.get('/api/spu/category',{type:'course'}).then(res=>{
// 设置分类列表
this.dataList = res.data;
// 如果分类列表不为空
if(this.dataList.length){
// 设置分类id
this.classId = this.dataList[0].id;
// 调用获取课程列表
this.getCourseList();
}
})
},
// 获取课程列表
getCourseList(){
let params = {
category_id:this.classId,
is_home:1
}
this.$requst.post('/api/spu/course',params).then(res=>{
if(res.code==0){
this.ifLoading = true;
if(!this.ifCount){
// 调用获取推荐视频列表
this.getVideoList();
// 调用获取推荐视频列表
this.getShopList();
}
let dataList = res.data.list;
if(dataList.length){
this.bigCourse.push(dataList[0]);
dataList.splice(0,1);
if(dataList.length){
setTimeout(()=>{
// 设置课程列表
this.$refs.refcourse.list = dataList;
},200)
}
}
}
})
},
// 获取推荐视频列表
getVideoList(){
this.$requst.post('/api/spu/video',{is_home:1}).then(res=>{
if(res.code==0){
// 设置推荐视频列表
this.videoList = res.data.list;
}
})
},
// 获取推荐商品
getShopList(){
let params = {
page:1,
size:20,
is_home:1
}
this.$requst.post('/api/spu/list',{params}).then(res=>{
if(res.code==0){
this.$refs.refshop.list = res.data.list;
}
})
},
// 播放视频
palyVideo(index){
if(!this.videoList[index].src){
// #ifdef MP-WEIXIN
wx.openChannelsActivity({
finderUserName:this.videoList[index].video_number,
feedId:this.videoList[index].subtitle,
success:(res)=>{},fail:()=>{
this.$toolAll.tools.showToast('视频已丢失或已删除')
}
})
// #endif
} else {
let newArr = [];
newArr.push(this.videoList[index])
uni.setStorageSync('videoList',newArr);
uni.navigateTo({
url:`/pagesB/play-video/play-video?current=${index}`
})
}
},
// 更多
goMore(index){
uni.reLaunch({
url:['/pages/tabbar/video/video','/pages/tabbar/shop/shop'][index]
})
},
// 去课程详情
goCourseDetail(id){
uni.navigateTo({
url:`/pagesB/course-detail/course-detail?id=${id}`
})
},
// 去商品详情
goShopDetail(id){
uni.navigateTo({
url:`/pagesB/shop-detail/shop-detail?id=${id}`
})
}
}
}
</script>
<style>
</style>