<template>
	<view class="itemContent">
		<view class="thumbnailBox">
			<image :src="thumbnailPath" alt="" mode="widthFix"></image>
		</view>
		<view class="courseDetailBox">
			<view class="title">
				<h4  @click="curriculumDetail()">{{title}}</h4>
				<text class="detailBtn" @click="viewDetail()" v-if="isNeedViewDetail">订单详情></text>
			</view>
			<view class="summaryBox" v-if="summaryBox">
				<text>{{summaryBox}}</text>
			</view>
			<view class="dataBox" v-if="dataList">
				<strong>￥{{dataList.coursePrice}}</strong>
				<text>{{dataList.salesNumber}}人购买</text>
			</view>
			<view class="tagListBox" v-if="tagList || fileLecturerId">
				<template v-if="tagList">
					<view class="tagItem" v-for="tagItem in tagConcat(tagList.v1,tagList.v2)">{{tagItem}}</view>
				</template>
				<template v-else-if="_tagList">
					<view class="tagItem" v-for="tagItem in tagConcat(_tagList.v1,_tagList.v2)">{{tagItem}}</view>
				</template>
				
			</view>
		</view>
	</view>
</template>

<script>
	import api from "@/api/api";
	export default {
		name:"courseItem",
		props:{
			fileLecturerId:{
				type:Number
			},
			thumbnailPath:{
				type:String
			},
			title:{
				type:String
			},
			summaryBox:{
				type:String
			},
			dataList:{
				type:Object
			},
			isNeedViewDetail:{
				type:Boolean
			},
			orderId:{
				type:Number
			},
			tagList:{
				type:Object
			},
			fileId:{
				type: String
			}
		},
		data() {
			return {
				_tagList:{}
			};
		},
		methods:{
			tagConcat(v1,v2){
				if(v1 && v2 && v2.indexOf(',') > 0 && v1.indexOf(',') > 0){
					return [].concat(v2.split(',').split(','),v1.split(','))
				}else if(v1 && v1.indexOf(',') > 0){
					return [].concat(v2,v1.split(','))
				}else if(v2 && v2.indexOf(',') > 0){
					return [].concat(v2.split(','),v1)
				}else{
					return [].concat(v2,v1)
				}
			},
			viewDetail(){
				uni.navigateTo({
					url:`/pages/orderDetail/orderDetail?id=${this.orderId}&type=drop`
				})
			},
			curriculumDetail(){
				uni.navigateTo({
					url:`/pages/courseDetail/courseDetail?fileId=${this.fileId}`
				})
			},
			lecturerQuery(){
				api.lecturerQuery({id:this.fileLecturerId}).then(res=>{
					if(res['success']){
						this._tagList['v1'] = res['data']['lecturerInfos'][0]['lecturerRankNames'];
						this._tagList['v2'] = res['data']['lecturerInfos'][0]['lecturerName'];
					}
				})
			}
			
		},
		updated() {
			if(this.fileLecturerId){
				this.lecturerQuery()
			}
		},
		mounted() {}
	}
</script>

<style lang="scss">
	.itemContent{
		display: flex;
		.thumbnailBox{
			width: 200rpx;
			height: 200rpx;
			margin-right: 26rpx;
			image{
				max-width: 100%;
				height: auto;
			}
		}
		.courseDetailBox{
			width: 100%;
			color: #333;
			.title{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.detailBtn{
					font-size: 24rpx;
					color: #4A4A4A;
					white-space: nowrap;
				}
			}
			h4{
				font-size: 32rpx;
			}
			.summaryBox{
				font-size: 24rpx;
				margin: 10rpx 0;
				text{
					margin-right: 20rpx;
				}
			}
			.dataBox{
				strong{
					color: #F15A1F;
					font-size: 30rpx;
					margin-right: 20rpx;
				}
				text{
					font-size: 28rpx;
				}
			}
			.tagListBox{
				display: flex;
				flex-wrap: wrap;
				.tagItem{
					color: #20279B;
					font-size: 28rpx;
					border-radius: 20rpx;
					border-top-left-radius: 0;
					border-bottom-right-radius: 0;
					padding: 10rpx 18rpx;
					border: 1px solid #20279B;
					margin-right: 20rpx;
					white-space: nowrap;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>