<template>
	<view class="page">
		<view class="video">
			<image :src="info.image" style="width: 750rpx;height: 456rpx;" mode=""></image>
			<image v-if="current==1" src="/static/images/play.png" mode="" @click="open" class="ding"></image>
			<image v-if="current==0" src="/static/images/free.png" mode="" @click="open" class="free"></image>
		</view>
		<view class="">
			<u-tabs active-color='#06A971' :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
			<view class="" style="border-top: 2rpx solid rgba(151, 151, 151, 0.1);" v-if="current==0">
				<view class="">
					<view class="" style="padding:  0 28rpx;">
						<view class="titles">{{info.title}}</view>
						<view class="teacher">
							<text>课程讲师：</text>
							<text>{{info.lecturer}}</text>
						</view>
						<view class="money">
							<text>¥</text>
							<text>{{info.price}}</text>
						</view>
					</view>
					<view class="back"></view>
					<view class="introduce">
						<view class="titles" style="margin-top: 0;">
							课程介绍
						</view>
						<view class="text-info" v-html="video_desc">
							<!-- {{video_desc}} -->
						</view>
					</view>
					<view class="" style="height:160rpx;"></view>
				</view>
			</view>
			<!-- 	<view class="" style="height: 166rpx;"></view> -->
			<view class="catalogue" v-if="current==1 && file.length > 0">
				<view v-for="(item,index) in file" :key="index" class="section u-flex u-row-between"
					@click="onplay(item.url,item.is_try)">
					<view class="">
						<text class="tong">{{item.title}}</text>
					</view>
					<view v-if="item.is_try==0" class="look">
						试看
					</view>
					<view v-else class="look">
						观看
					</view>
				</view>
			</view>
		</view>
		<view class="bottom" style="display: flex;justify-content: space-between;">
			<view class="button1 u-flex u-row-center" style="margin-right: 11rpx;" v-if="current==0&&trylist.length>0">
				<view  class="" @click="open">免费试看</view>
				<image src="/static/images/slice.png" style="width: 32rpx; height: 32rpx;margin-left: 12rpx;" mode="">
				</image>
			</view>
			<view style="flex: 1;" class="button2" v-if="current==0" @click="toorderinfo">
				立即订阅
			</view>
			<view @click="open()" class="button" v-if="current==1">
				立即学习
			</view>
		</view>
		<u-popup v-model="show1" mode="center">
			<view class="" style="font-size: 0;">
				<video :src='url' class="video" id="demoVideo" :controls="true" :enable-progress-gesture="false">
				</video>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show1: false,
				list: [{
					name: '课程介绍',
				}, {
					name: '目录',
				}],
				current: 0,
				show: false,
				id: '',
				video_desc: '',
				info: {
					image: '',
					lecturer: '',
					price: '',
					title: '',
					is_pay: '',
				},
				file: [],
				url: '',
				url1: '',
				trylist: []
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getVideoInfo()
		},
		methods: {
			toorderinfo() {
				if (uni.getStorageSync("token")) {
					this.$u.post('api/order/createOrder', {
						goods_id: this.id,
						type: 1
					}).then(res => {
						if (res.code == 1) {
							uni.navigateTo({
								url: '/pages/index/orderinfo?id=' + res.data.id + "&index=" + 3
							})
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '请先登录',
						confirmText: '我知道了',
						success: function(res) {
							if (res.confirm) {

							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			open() {
				this.show1 = true
				this.url = this.url1
			},
			//获取视频信息
			getVideoInfo() {
				this.$u.post('api/video/getVideoInfo', {
					id: this.id
				}).then(res => {
					console.log('info', res);
					this.info = res.data
					const a = new RegExp('style=""', 'gi')
					var content = res.data.video_desc.replace(a, `styles`)
					const regex = new RegExp('<img', 'gi')
					this.video_desc = content.replace(regex, `<img style="max-width: 100%; height: auto"`)
					this.file = res.data.file
					res.data.file.map(item => {
						if (item.is_try == 0) {
							this.trylist.push(item)
						}
					})
					this.url1 = trylist[0].url
				})
			},
			change(index) {
				this.current = index;
			},
			toupdown() {
				uni.navigateTo({
					url: '/pages/index/updown'
				})
			},
			onplay(url, is_try) {
				if (is_try == 0) {
					this.open()
				} else if (this.info.is_pay == 0) {
					this.show1 = true
					this.url = url
				} else {
					this.$u.toast("请购买后观看")
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.text-info {
		font-size: 28rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #222222;
		margin-top: 24rpx;
	}

	.button1 {
		width: 336rpx;
		height: 88rpx;
		background: #EEEEEE;
		border-radius: 12rpx;
		font-size: 32rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #444444;
		text-align: center;
		line-height: 88rpx;
	}

	.button2 {
		width: 336rpx;
		height: 88rpx;
		background: #06A971;
		border-radius: 12rpx;
		font-size: 32rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
	}

	.introduce {
		padding: 32rpx 28rpx;
	}

	.back {
		height: 20rpx;
		background: #F5F5F5;
	}

	.money {
		font-size: 28rpx;
		font-family: SFPro, SFPro;
		font-weight: 500;
		color: #CC3300;
		margin-top: 28rpx;
		margin-bottom: 40rpx;
	}

	.teacher {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #777777;
		margin-top: 24rpx;
	}

	.titles {
		font-size: 32rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #222222;
		margin-top: 30rpx;
	}

	.tong {
		font-size: 26rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.look {
		width: 64rpx;
		height: 36rpx;
		background: #06A971;
		border-radius: 6rpx;
		font-size: 20rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 36rpx;
	}

	.bottom {
		width: 750rpx;
		height: 166rpx;
		background: #FFFFFF;
		position: fixed;
		padding: 16rpx 28rpx 62rpx;
		bottom: 0;
		left: 0;
	}

	.catalogue {
		border-top: 2rpx solid rgba(151, 151, 151, 0.1);
		padding: 10rpx 28rpx;
	}

	.section {
		width: 702rpx;
		height: 84rpx;
		background: #F4F4F4;
		border-radius: 8rpx;
		padding: 24rpx 20rpx 24rpx 24rpx;
		margin-top: 20rpx;
	}

	.button {
		width: 694rpx;
		height: 88rpx;
		background: #06A971;
		border-radius: 12rpx;
		font-size: 32rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
	}

	.page {
		height: 100vh;
	}

	.video {
		width: 750rpx;
		height: 456rpx;
		position: relative;
	}

	.ding {
		position: absolute;
		left: 50%;
		top: 50%;
		width: 90rpx;
		height: 90rpx;
		margin-left: -45rpx;
		margin-top: -45rpx;
	}

	.free {
		position: absolute;
		left: 50%;
		top: 50%;
		width: 290rpx;
		height: 88rpx;
		margin-left: -145rpx;
		margin-top: -44rpx;
	}
</style>