<template>
	<view :class="{pad:onlyShowList!=0}">
		<!--搜索组件-->
		<search :isSearch="1" v-if="onlyShowList!=0" @send="getCourseList"></search>
		<!--轮播组件-->
		<carousel :carouselList="fileUploadItemCFFPList" v-if="onlyShowList!=0"></carousel>
		<h4 v-if="cffpCourseInfos.length<=0" class="noListTip">暂无课程列表</h4>
		<view class="ulBox" v-if="cffpCourseInfos.length>0">
			<view class="liBox" v-for="item in cffpCourseInfos" :key="item.fileId" @click="goDetail(item)">
				<course-item :thumbnailPath="item.displayImage" :title="item.fileTitle" :summaryBox="item.fileSynopsis" :dataList="{coursePrice:item.coursePrice,salesNumber:item.salesNumber}" :tagList="{v1:item.fileLecturerRanks,v2:item.fileLecturerName}"></course-item>
			</view>
		</view>
	</view>
	<tabBar :currentPage="currentPage" v-if="onlyShowList!=0"></tabBar>
</template>

<script>
	import api from "../../api/api";
	import courseItem from "@/components/courseItem/courseItem.vue";
	import tabBar from '../../components/tabBar/tabBar.vue';
	import carousel from '@/components/carousel/carousel.vue';
	import search from '@/components/search/search.vue';
	export default{
		props:['tagIds','onlyShowList'],
		data(){
			return{
				cffpCourseInfos:[],
				currentPage:'courselist',
				fileUploadItemCFFPList:[],
				queryName:null
			}
		},
		name:'courselist',
		components:{
			courseItem,
			tabBar,
			carousel,
			search
		},
		onLoad(){
			this.fileUploadItemCFFPList = uni.getStorageSync('fileUploadItemCFFPList');
		},
		methods:{
			goDetail(item){
				uni.navigateTo({
					url: `/pages/courseDetail/courseDetail?fileId=${item.fileId}`
				});
			},
			courseList(){
				const param = {
					queryName:this.queryName
				}
				api.courseList(param).then(res=>{
					if(res['success']){
						this.cffpCourseInfos = res['data']['data'];
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'					
						})
					}
				})
			},
			tagConcat(val,v2){
				if(val.indexOf(',') > 0){
					return [].concat(v2,val.split(','))
				}else{
					return [].concat(v2,val)
				}
			},
			getCourseList(res){
                 console.log("res=========",res)
				 this.queryName = res;
				 this.courseList()
            }
		},
		mounted() {
			this.courseList();
		}
	}
</script>

<style lang="scss">
	.ulBox,.liBox{
		
		display: flex;
	}
	.ulBox{
		flex-direction: column;
	}
	.liBox{
		background-color: #fff;
		border-radius: 20rpx;
		margin-bottom: 10rpx;
		padding: 10rpx;
	}
	.pad{
		padding:0 30rpx 100rpx 30rpx;
	}
</style>