<template>
	<view class="itemContent">
		<view class="thumbnailBox">
			<image :src="thumbnailPath" alt="" mode="widthFix"></image>
		</view>
		<view class="courseDetailBox">
			<view class="title">
				<text style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{title}}</text>
				<!-- <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: Number
			}
		},
		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)
				}
			},
			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;
		height: 100%;
		.thumbnailBox {
			width: 300rpx;
			margin-right: 26rpx;
			align-items: center;
			
			image {
				max-width: 100%;	
				height: auto;
			}
		}

		.courseDetailBox {
			width: 100%;
			color: #333;
			height: auto;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				display: flex;
				max-width: 260rpx;
				// justify-content: space-between;
				// align-items: center;
				font-size: 32rpx;

				.detailBtn {
					font-size: 24rpx;
					color: #4A4A4A;
				}
			}

			h4 {
				font-size: 32rpx;
			}

			.summaryBox {
				font-size: 24rpx;
				// margin: 10rpx 0;

				text {
					margin-right: 20rpx;
				}
			}

			.dataBox {
				strong {
					color: #F15A1F;
					font-size: 30rpx;
					margin: 10rpx 20rpx 10rpx 0;
				}

				text {
					font-size: 28rpx;
				}
			}

			.tagListBox {
				display: flex;
				flex-wrap: wrap;
				// margin-top: 20rpx;

				.tagItem {
					color: #20279B;
					font-size: 24rpx;
					border-radius: 20rpx;
					border-top-left-radius: 0;
					border-bottom-right-radius: 0;
					padding: 5rpx 18rpx;
					border: 1px solid #20279B;
					margin-right: 20rpx;
					white-space: nowrap;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>
