<template>
	<view >
		<view class="video_body">
			<view class="video_box">
				<image :src="$method.splitImgHost(detail.coverUrl)" style="width: 100%;height: 460rpx;"></image>
			</view>
			<view>
				<u-row >
					<u-col span="8" offset="1">
						<view class="video_t1">
							{{detail.name}}
						</view>
					</u-col>
					<u-col span="3">
						<view class="price_num">
							￥{{detail.price}}
						</view>
					</u-col>
				</u-row>
			</view>
			<view>
				<u-tabs :list="list" font-size="24" bar-width="110" :current="current" @change="change" active-color="#32467B"></u-tabs>
			</view>
			<u-line color="#D6D6DB" />
			<view v-if="current==0">
				<!-- 重点考点介绍-->
				<view style="margin-top: 15rpx;">
					<u-row >
						<u-col span="9" >
							<view class="video_t2" style="display: flex;align-items: center;">
								<view class="top_line"></view>
								重点考点介绍
							</view>
						</u-col>
					</u-row>
					<view class="text_box">
						<u-parse :html="detail.introduction"></u-parse>
					</view>
				</view>
				<u-line color="#D6D6DB" />
			</view>
			<!-- 出题名师-->
			<view v-if="current<=1">
				<view style="margin: 15rpx 0;">
					<u-row >
						<u-col span="8" >
							<view class="video_t2" style="display: flex;align-items: center;">
								<view class="top_line"></view>
								出题名师
							</view>
						</u-col>
					</u-row>
					<view  v-for="(item,index) in teacherList" :key="index">
						<u-row >
							<view style="margin: 25rpx;display: flex;">
								<view >
									<image :src="$method.splitImgHost(item.avatar)" class="teacher_img"></image>
								</view>
								<view class="teacher_t">
									{{item.introduce}}
								</view>
							</view>
						</u-row>
					</view>
					
				</view>
				<u-line color="#D6D6DB" />
			</view>
			<!-- 相关推荐-->
			<view style="margin: 15rpx 0;">
				<u-row >
					<u-col span="8" >
						<view class="video_t2" style="display: flex;align-items: center;">
							<view class="top_line"></view>
							相关推荐
						</view>
					</u-col>
				</u-row>
				<view style="margin: 10rpx;">
					<view class="tj_box" v-for="(item,index) in recommendList" :key="index" @click="jumpDetail(item)">
						<image :src="$method.splitImgHost(item.coverUrl)"   style="width: 320rpx;height: 160rpx;"></image>
						<view style="font-size: 24rpx;color: #666666;text-align: left;">
							{{item.name}}
						</view>
						<view>
							<u-row >
								<u-col span="6" >
									<view style="margin-left: 20rpx;">
										<image src="/static/people.png"   style="width: 20rpx;height: 20rpx;"></image>
										<text style="color: #999999;font-size: 20rpx;margin-left: 10rpx;">2023</text>
									</view>
								</u-col>
								<u-col span="6" text-align="right">
									<text style="color: #E91313;font-size: 16rpx;margin-left: 8rpx;">
										活动价 
									</text>
									<text style="color: #E91313;font-size: 24rpx;font-weight: bold;">
										￥{{item.price}}
									</text>
								</u-col>
							</u-row>
						</view>
						
					</view>
				</view>
			</view>
		</view>
		<view  class="footer_tab">
			<u-line color="#D6D6DB" />
			<view style="height: 100%;display: flex;align-items: center;position: relative;">
				<view style="text-align: center;margin-left: 30rpx;" @click="favorites">
					<image :src="collecStatus ? '/static/star.png' : '/static/sc.png'" class="sc"></image>
					<view class="sc_t">收藏</view>
				</view>
				<view class="buy" v-if="payStatus === 0" @click="buyTK">
					立即购买
				</view>
				<view class="buy" v-if="payStatus === 1" @click="jumpPay">
					开始阅读
				</view>
			</view>
		</view>
<u-popup v-model="showPricePop" mode="bottom" border-radius="14">
			<view class="topBox">
				<view class="firstTopL">
					<view class="imageBs"><image :src="$method.splitImgHost(detail.coverUrl)" mode=""></image></view>
					<view class="textBs">{{ detail.name }}</view>
				</view>
				<view class="boldFonstType">
					类型：
					<span style="font-weight: bold;">{{ detail.categoryName }}</span>
				</view>
				<view class="priceBxs">
					<view class="pricleft">
						活动价
						<span style="font-weight: bold;">￥{{ detail.price }}</span>
					</view>
					<view class="pricright" style="text-decoration: line-through;color: #666;">￥{{ detail.price }}</view>
				</view>
			</view>
			<view class="btnspric">
				<view class="lefprL">
					实付：
					<span style="color: #E91313;">￥{{ prices }}</span>
				</view>
				<view class="lefprR" @click="getorder">提交订单</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '重点考点介绍'
				}, {
					name: '出题名师',
				}, {
					name: '相关推荐',
				}],
				current: 0,
				id:0,
				detail:{},
				teacherList:[],
				recommendList:[],
				showPricePop: false, //购买详情弹窗
				newDate: 0, //现在时间戳
				prices: 0, //实付
				payStatus: 0,//是否已购买
				collecStatus: false,
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getDetail()
			this.noteRecommendList({fileId:this.id})
			this.getHaveThis()
		},
		onShow(){
			if (!uni.getStorageSync('union_id') && this.$store.state.token === '') {
			} else {
				this.favoritesStatus();
			}
		},
		methods: {
			favoritesStatus() {
				this.$api.noteCollects(this.id).then(result => {
					if (result.data.data === undefined) {
						this.collecStatus = false;
					} else {
						this.collecStatus = true;
					}
				});
			},
			//收藏
			favorites() {
				var self = this;
				if (!uni.getStorageSync('union_id') && this.$store.state.token === '') {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				} else {
					if (this.collecStatus) {
						this.$api.noteCollects(self.id).then(results => {
							self.$api.noteCollectdelete(results.data.data.collectNoteId).then(resz => {
								self.favoritesStatus();
							});
						});
					} else {
						var data = {
							userId: this.$store.state.userInfo.userId,
							fileId: self.id
						};
						this.$api.noteCollectsadd(data).then(res => {
							self.favoritesStatus();
						});
					}
				}
			},
			//检测是否已购买该课程
			getHaveThis(){
				var self = this
				var data = {
					possessId: this.id,
					typeId: 3
				}
				if (this.$method.isLogin()) {
					this.$api.systemuserowner(data).then(res => {
						if(res.data.code === 200){
						self.payStatus = res.data.data.payStatus
						}
					})
				}
				
			},
			//提交订单
			getorder(){
				var self = this
				var data = {
					goodsList: [{
						goodsId: self.detail.fileId,
						num: 1,
						goodsType: 3
					}]
				}
				self.$api.order(data).then(res => {
					if(res.data.code === 200){
						uni.showModal({
							title: '提示',
							content: '兑换成功',
							showCancel: false,
							success: function(resst) {
								self.showPricePop = false;
								self.getHaveThis();
							}
						});
				/*		let objarr = res.data.data
						wx.requestPayment({
							timeStamp: objarr.timeStamp,
							nonceStr: objarr.nonceStr,
							package: objarr.package,
							signType: objarr.signType,
							paySign: objarr.sign,
							success (result) {
								uni.showModal({
								    title: '提示',
								    content: '支付成功',
									showCancel: false,
								    success: function (resst) {
										if(resst.confirm){
										self.showPricePop = false
										self.getHaveThis()
										}
								    }
								});
							},
							fail (err){
								uni.showModal({
								    title: '提示',
								    content: '支付失败',
									showCancel: false,
								    success: function (resst) {
										self.showPricePop = false
										self.getHaveThis()
								    }
								});
							}
						})*/
					}else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			//购买题库
			buyTK(){
				var self = this;
				uni.getStorage({
					key: 'union_id',
					success: function(res) {
						// 继续操作
						self.showPricePop = true;
					},
					fail: function(err) {
						//重新登入
						self.$navTo.togo('/pages/login/login', {});
					}
				});
			},
			jumpDetail(item) {
				this.$navTo.togo('/pages2/course/keynote', {
					id:item.fileId
				});
			},
			getDetail(){
				let self = this
				this.$api.noteInfo(this.id).then(res => {
					self.detail = res.data.data
					self.prices = res.data.data.price
					 if(self.detail.teacherIds&&self.detail.teacherIds!=''){
						 let param = {
							 teacherIds : self.detail.teacherIds
						 }
						 self.getTeacherList(param);
					} 
				})
			},
			getTeacherList(param){
				let self = this
				this.$api.teacherList(param).then(res => {
					self.teacherList = res.data.rows 
					
				})
			},
			noteRecommendList(param){
				let self = this
				this.$api.noteRecommendList(param).then(res => {
					self.recommendList = res.data.data
					
				})
			},
			change(index) {
				this.current = index;
			},
			jumpPay(){
				let url = 'https://m.xyyxt.net/'+this.detail.fileUrls
				this.$navTo.togo('/pages2/course/read', {url:url})
			},
			jumpRead(){
				if(!this.$method.isLogin()){
					this.$navTo.togo('/pages/login/login');
				}else{
					let url = 'https://m.xyyxt.net/'+(this.detail.fileUrls)
				//	console.log(url)
				/*	uni.downloadFile({
					        url:url,
					        success(res){
					          console.log(res)
					          let data = res.tempFilePath;
					          uni.openDocument({
					            filePath:data,
					            fileType:'pdf'
					          })
					        }
					      })*/
				//	this.$navTo.togo('/pages2/payment/payment', {})
					this.$navTo.togo('/pages2/course/read', {url:url})
				}
				
			}
		
		},
		
	}
</script>
<style>
	::-webkit-scrollbar{
		width: 0;
		height: 0;
		color: transparent;
	}
</style>
<style scope>
	
	.btnspric {
		border-top: 1rpx solid #eee;
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 108rpx;
		padding-left: 43rpx;
		padding-right: 32rpx;
	}
	.btnspric > .lefprL {
		font-size: 36rpx;
		color: #0c141f;
		font-weight: bold;
	}
	.btnspric > .lefprR {
		padding: 0rpx 24rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		color: #fff;
		background: #32467b;
		border-radius: 24rpx;
		box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
	}
	.yhj,
	.hdyhj {
		padding: 24rpx 29rpx 24rpx 34rpx;
	}
	.yhj {
		border-bottom: 16rpx solid #f9f9f9;
	}
	.yhjtit {
		font-size: 30rpx;
		color: #0c141f;
		font-weight: 500;
		margin-bottom: 14rpx;
	}
	.yhjList {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 14rpx;
	}
	.yhjList > .yhjLefts {
		display: flex;
		align-items: center;
	}
	.yhjLefts > .yhl {
		color: #32467b;
		font-size: 30rpx;
		margin-right: 31rpx;
	}
	.yhjLefts > .yhbq {
		font-size: 24rpx;
		color: #ff9500;
		border-radius: 18rpx;
		background-color: rgba(255, 149, 0, 0.2);
		border: 2rpx solid #ff9500;
		height: 38rpx;
		line-height: 38rpx;
		padding: 0rpx 16rpx;
	}
	.ts {
		font-size: 24rpx;
		color: #999;
		margin: 14rpx 0rpx;
		padding-right: 29rpx;
		padding-left: 34rpx;
	}
	.yh {
		padding-top: 20rpx;
	}
	.yh > .yhtitle {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-right: 29rpx;
		padding-left: 34rpx;
	}
	.priceBxs {
		display: flex;
		align-items: center;
	}
	.priceBxs > .pricleft {
		border-radius: 24rpx;
		border: 1rpx solid #e91313;
		background-color: rgba(233, 19, 19, 0.1);
		padding: 0rpx 18rpx;
		height: 49rpx;
		line-height: 49rpx;
		text-align: center;
		font-size: 30rpx;
		font-weight: 500;
		color: #e91313;
		margin-right: 13rpx;
	}
	.topBox {
		padding: 32rpx 32rpx 24rpx;
		border-bottom: 1rpx solid #eeeeee;
	}
	.topBox > .boldFonstType {
		font-weight: 500;
		font-size: 30rpx;
		margin: 16rpx 0rpx 23rpx;
	}
	.topBox > .firstTopL {
		display: flex;
		align-items: center;
	}
	.topBox > .firstTopL > .imageBs {
		width: 331rpx;
		height: 160rpx;
		border-radius: 6rpx;
		overflow: hidden;
		margin-right: 8rpx;
		box-shadow: 0rpx 6rpx 6rpx 0rpx rgba(47, 67, 121, 0.08);
	}
	.topBox > .firstTopL > .imageBs > image {
		width: 100%;
		height: 100%;
	}
	.topBox > .firstTopL > .textBs {
		font-size: 30rpx;
		font-weight: bold;
		color: #0c141f;
	}
	.text_box{
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #666666;
		line-height: 36rpx;
		padding: 20rpx;
	}
	.price_num{
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #E91313;
	}
	.price_t2{
		font-size: 18rpx;
		font-family: PingFang SC;
		font-weight: 500;
		text-decoration: line-through;
		color: #999999;
	}
	.price_t1{
		font-size: 33rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #E91313;
	}
	.sc_t{
		font-size: 22rpx;
		color: #000000;
	}
	.sc{
		width: 29rpx ;
		height: 29rpx;
	}
	.buy{
		width: 138rpx;
		height: 48rpx;
		line-height: 48rpx;
		background: #32467B;
		border-radius: 10rpx;
		color: #FFFFFF;
		font-size: 28rpx;
		text-align: center;
		vertical-align: middle;
		position: absolute;
		right: 30rpx;
	}
	.video_body{
		padding-bottom: 96rpx;
	}
	.footer_tab{
		position:fixed;
		bottom:0;
		height: 96rpx;
		width: 100%;
		background-color: #FFFFFF;
	}
	.tj_box{
		width: 50%;
		display: inline-block;
		text-align: center;
		margin: 10rpx 0;
	}
	.teacher_t{
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #666666;
		line-height: 36rpx;
		margin-left: 15rpx;
	}
	.teacher_img{
		width: 87rpx;
		height: 129rpx;
	}
	.t2{
		font-size: 24rpx;
		font-family: PingFang SC;
		color: #666666;
		line-height: 36rpx;
		margin: 15rpx;
	}
	.r_t2{
		width: 201rpx;
		height: 49rpx;
		background: rgba(22, 119, 255, 0.05);
		border: 1rpx solid #32467B;
		border-radius: 16rpx;
		color: #666666;
		font-size: 23rpx;
		text-align: center;
		display: flex;
		align-items: center;
		padding: 5rpx;
		
	}
	.scroll_box{
		width: 100%;
		height: 60rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
		white-space:nowrap;
		overflow: hidden;
		margin: 15rpx 0;
	}
	.r_sliper{
		padding: 0 20rpx;
	}
	.top_line{
		width: 6rpx;
		height: 22rpx;
		background: #32467B;
		margin-right: 10rpx;
	}
	.video_t2{
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
	}
	.video_t1{
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}
	.video_play{
		position:absolute;
		width: 95rpx;
		height: 95rpx;
		top:0;
		left:0;
		right:0;
		bottom:0;
		margin:auto;
	}
	.video_box{
		position: relative;
	}
	
page {
		background: #FFFFFF;
	}
</style>
