<template>
	<view style="background-color: #fff;padding-bottom: 116rpx;">
		<view class="title-content" id="title-content">
			<!-- 答题时展示小节课程名，其他展示课程名 -->
			<!-- 小节课程名 -->
			<view class="subtitlebox" v-if="isLogin&&isAddKf==1">
				{{courseInfo.title}}
			</view>
			<!-- 课程名字 -->
			<view class="miantitlebox" v-else>
				{{courseInfo.courseName}}
			</view>
			<view class="giftbtn" v-if="showAnswerTip&&source == 'app'" @click="handleGift">兑换礼品</view>
		</view>
		<view class="descbox" >
			<template v-if="!isLogin||isAddKf!=1">
				<view class="descbox-title">{{courseInfo.title}}</view>
				<view class="descbox-info">
					<!-- <view class="descbox-info-l">
						<view>{{courseInfo.views}}次播放</view>
						<view class="descbox-info-time">总时长：{{courseInfo.totalDuration}}</view>
					</view> -->
					<view class="descbox-info-r expand" v-if="textHeight > 21">
						<text @click="handleExpand">{{isExpand ? '收起简介' : '展开简介'}}</text>
						<image src="/static/images/course_arrow_up_icon.png" v-show="isExpand"></image>
						<image src="/static/images/course_arrow_down_icon.png" v-show="!isExpand"></image>
					</view>
				</view>
			</template>
			<view class="descbox-desc" id="descbox-desc" :style="{height: isExpand ? 'auto': '42rpx'}">
				<text>{{courseInfo.description}}</text>
				<view :class="isExpand ? 'expand': 'expand expand-ab'" v-if="isLogin&&isAddKf==1&&textHeight > 21">
					<text @click="handleExpand">{{isExpand ? '收起简介' : '展开简介'}}</text>
					<image src="/static/images/course_arrow_up_icon.png" v-show="isExpand"></image>
					<image src="/static/images/course_arrow_down_icon.png" v-show="!isExpand"></image>
				</view>
			</view>
			<view class="giftbtn-big" v-if="isLogin">
				兑换礼品
				<wx-open-launch-weapp appid="wx20d588bebb30130f" path="pages_user/integralGoodsList" @launch="weappLaunch" @error="weappError">
					<component :is="'script'" type="text/wxtag-template">
						<div class="giftbtn-big-weapp"></div>
					</component>
				</wx-open-launch-weapp>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			isLogin: {
				type: Boolean,
				default: false,
			},
			isAddKf: {
				type: [String,Number],
				default: 0,
			},
			courseInfo: {
				type: Object,
				default: {},
			},
			showAnswerTip: {
				type: Boolean,
				default: false,
			},
			source: {
				type: String,
				default: '',
			},
		},
		data() {
			return {
				// 是否展开
				isExpand: true,
				textHeight: 0, //文本高度
			}
		},
		methods: {
			// 展开简介
			handleExpand() {
				this.isExpand = !this.isExpand
			},
			getDescHeight() {
				this.$nextTick(() => {
					const query = uni.createSelectorQuery().in(this);
					query
						.select("#descbox-desc")
						.boundingClientRect((data) => {
							if(data){
								this.textHeight = data.height
							}
						})
						.exec();
				})
			},
			handleGift() {
				this.$emit('handleGift')
			}
		}
	}
</script>
<style>
	.giftbtn-big-weapp {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
</style>
<style scoped lang="scss">
	@mixin u-flex($flexD, $alignI, $justifyC) {
		display: flex;
		flex-direction: $flexD;
		align-items: $alignI;
		justify-content: $justifyC;
	}
	.giftbtn-big {
		width: 100%;
		height: 98rpx;
		border-radius: 19rpx;
		line-height: 98rpx;
		text-align: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		font-size: 32rpx;
		color: #FF5C03;
		@include u-flex(row, center, center);
		border: 1px solid #FF5C03;
		position: relative;
	}
	.miantitlebox {
		padding: 30rpx 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #222222;
	}
	.subtitlebox {
		padding: 30rpx 0;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #222222;
	}
	.title-content {
		padding: 0 32rpx;
		background-color: #fff;
		font-size: 28rpx;
		line-height: 1.6;
		@include u-flex(row, center, space-between);
		.title {
			font-size: 36rpx;
			font-weight: 500;
			color: #414858;
		}
	
		.time-or-subtitle {
			margin-top: 12rpx;
			color: #666666;
		}
		.giftbtn {
			flex-shrink: 0;
			padding: 6rpx 16rpx;
			background: #FF5C03;
			border-radius: 42rpx 42rpx 42rpx 42rpx;
			@include u-flex(row, center, center);
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
	.descbox {
		padding: 14rpx 32rpx;
		margin-bottom: 20rpx;
		background-color: #fff;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #222222;
		line-height: 42rpx;
		word-break: break-word;
	
		&-title {
			margin-bottom: 24rpx;
			font-weight: 500;
			font-size: 32rpx;
		}
	
		&-info {
			margin-bottom: 24rpx;
			@include u-flex(row, center, space-between);
			font-size: 26rpx;
			color: #757575;
	
			&-l {
				flex: 1;
				@include u-flex(row, center, flex-start);
			}
	
			&-time {
				margin-left: 18rpx;
				padding-left: 18rpx;
				position: relative;
	
				&::after {
					content: "";
					width: 4rpx;
					height: 4rpx;
					background: #999999;
					border-radius: 50%;
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
				}
			}
	
			&-r {
				background: transparent;
			}
		}
	
		&-desc {
			overflow: hidden;
			position: relative;
		}
	}
	.expand {
		flex-shrink: 0;
		@include u-flex(row, center, flex-end);
		color: #FF5C03;
		font-weight: 400;
		font-size: 24rpx;
	
		image {
			width: 32rpx;
			height: 32rpx;
		}
	}
	
	.expand-ab {
		position: absolute;
		top: 0;
		right: 0;
		box-shadow: -50rpx 0 20rpx 8rpx #FFFFFF;
		background-color: #fff;
	}
	
</style>