<template>
	<view class="container"  @scroll="handleScroll">
		<u-loading-page :loading="loading"></u-loading-page>
		
		
		<page-container v-if="!loading" custom-style="" class="pcontainer" :show="isShow" @beforeleave="beforeleave" :position="top" :overlay="false">
			<uni-nav-bar :fixed="true" title="文章详情" background-color="#ffffff" status-bar left-icon="left"
						 @clickLeft="back" />
			<scroll-view  style="height: 90vh;overflow-y:scroll" scroll-y="true" @scrolltolower="scrollToBottom">		 
				<contentVue :listData="listData"/>
			</scroll-view>	
			<u-modal :show="show" @confirm="confirm" @cancel="cancel" :title="title" :showCancelButton="true"
			 confirmText="继续阅读" cancelText="退出" confirmColor="#106DFF" cancelColor="#999999">
				<view class="slot-content">
					<view class="img">
						<image src="../../static/pic_quit_big@2x.png" mode="widthFix" style="width: 120px;"></image>
					</view>
					<view class="backtip1">您还阅读完</view>
					<view class="backtip2">中途退出观看不加积分</view>
					
				</view>
			</u-modal>
			
			<u-modal :show="show2" @confirm="confirmok" @cancel="cancel" :title="title" :showCancelButton="true"
			 confirmText="我知道了"  confirmColor="#106DFF" >
				<view class="slot-content">
					<view class="img">
						<image src="../../static/pic_points_big@2x.png" mode="widthFix" style="width: 120px;"></image>
					</view>
					<view class="backtip1" style="color: #FF1D1D;">+ {{listData.jf}}</view>
					<view class="backtip2">恭喜您完成阅读获得积分</view>
					
				</view>
			</u-modal>
		</page-container>
		
	</view>
</template>

<script>
	import { detailApp,jfupdate} from '@/api/ffxc.js'
	import contentVue from './content.vue';
	export default {
		components:{contentVue},
		data() {
			return {
				loading:true,
				isread:false,
				scrollToView: '',
				isReadFinished: false, // 是否阅读完毕的标志
				isShow:true,
				show:false,
				show2:false,
				listData:{},
				item:{type:1,author:'测试'},
				content: `<p>在北京航天飞行控制中心拍摄的天舟五号货运飞船与空间站组合体完成自主快速交会对接示意图。孙丰晓摄（新华社发）</p>
				<p>北京时间2022年11月12日10时03分，在文昌航天发射场，搭载天舟五号货运飞船的长征七号遥六运载火箭点火发射，将天舟五号货运飞船送入预定轨道。随后，天舟五号货运飞船与在轨运行的空间站组合体进行自主快速交会对接，中国航天员首次在空间站迎接货运飞船来访。</p>
				<p>朝着在距离地面约400公里轨道上运行的中国空间站组合体，天舟五号首次实现2小时自主快速交会对接，创造世界纪录。这一技术突破对于提升我国空间交会对接水平，提升空间站任务应急物资补给能力具有重要意义。</p>
				<p>空间站阶段最快交会对接，让人类航天器交会对接用时进入“2小时”时代。</p>
				<p>此次任务是中国空间站“T”字基本构型在轨组装完成后，“太空快递”首次送达，执行运输任务的仍是长七火箭。</p>`
			};
		},
		onLoad(options) {
			uni.showLoading({
				title: '加载中'
			});
			detailApp(options.id).then(res=>{
				this.listData = res.data
				this.loading = false
			}).finally(()=>{
				uni.hideLoading()
			})
		},
		methods:{
			scrollToBottom: function() {
			    // 在这里可以执行加载更多数据的操作,如果没读过提示加积分
				if(this.listData.type!=1){
					if(!this.isread){
						this.show2 = true
						this.addjf()
					}
				}else{
					this.$u.func.showToast({ title: '该文章您已经领取过积分'})
				}
					
			  },
			  confirmok(){
				  this.show2 = false
			  },
			addjf(){
				jfupdate({ffxcId:this.listData.id,jf:this.listData.jf}).then(res=>{
					this.isread = true
				})
			},
			handleScroll(event) {
			      const { scrollTop, scrollHeight, clientHeight } = event.detail;
			      if (scrollTop + clientHeight >= scrollHeight) {
			        // 已经滚动到底部
			        console.log('已经滚动到底部');
			      }
			    },
			beforeleave(){
				if(this.listData.type==1){
					uni.switchTab({
						url: "/pages/index/index"
					});
					return
				}
				if(!this.isread){
					this.isShow = false
					uni.showModal({
						confirmColor: '#bd3124',
						title: "您还没阅读完",
						content: '中途退出观看不加积分',
						cancelText: "退出", // 取消按钮的文字  
						confirmText: "继续阅读", // 确认按钮的文字  
						confirmColor: '#106DFF',
						cancelColor: '#999999',
						success: (e) => {
							if (e.confirm) {
								this.isShow = true
							}else{
							 this.isShow = false
							 // 返回上一页
							 uni.switchTab({
								url: "/pages/index/index"
							 });
							}
						}
				 })
				}else{
					uni.switchTab({
					   url: "/pages/index/index", // 确保 url 是正确的
					 });
				}
			},
			back() {
				if(!this.isread){
					if(this.listData.type!=1){
						this.show = true
					}else{
					uni.switchTab({
					   url: "/pages/index/index", // 确保 url 是正确的
					 });
				}
					
				}else{
					uni.switchTab({
					   url: "/pages/index/index", // 确保 url 是正确的
					 });
				}
			},
			confirm(){
				 this.show = false
			},
			cancel(){
				this.isShow = false;	
				 // 返回上一页
				  uni.switchTab({
					 url: "/pages/index/index", // 确保 url 是正确的
				   });
			},
		}
		

	};
</script>

<style lang="scss">
	.container {
		padding: 0 0 150rpx;
	}
	.slot-content{
		position: relative;
		.img{
			text-align: center;
		}
	}
.classify{
				font-weight: 500;
				font-size: 24rpx;
				line-height: 42rpx;
				text-align: right;
				font-style: normal;
				border-radius: 8rpx;
				text-align: center;
				padding: 2px 5px;
				margin-left: 6rpx;
				position: relative;
				top: -2px;
			}
			.classify1{
				color: #00A870;
				background: #D7F5EB;
			}
			.classify2{
				color: #ED7B2F;
				background: #FEECDF;
			}
			.classify3{
				color: #E34D59;
				background: #FEE4E7;
			}
	.right-nav {
		display: flex;
		align-items: center;
		margin-right: 40rpx;

		.icon {
			height: auto;

			&-search {
				width: 40rpx;
				margin-right: 40rpx;
			}

			&-menu {
				width: 40rpx;
			}
		}
	}
    /deep/ .uni-navbar--border{
		border-bottom: none !important;
	}
	.backtip1{
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #111111;
		line-height: 52rpx;
		text-align: center;
		font-style: normal;
		
	}
	.backtip2{
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
		line-height: 40rpx;
		text-align: center;
		font-style: normal;
	}
	.header {
		display: flex;
		align-items: center;
		padding: 44rpx;

		.avatar {
			flex-shrink: 0;
			width: 69rpx;
			height: 69rpx;
			background: #ffffff;
			border: 1px solid #69b0ff;
			border-radius: 50%;
		}

		.info {
			flex: 1;
			margin-left: 14rpx;

			.name {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #000000;
				line-height: 36rpx;

				.tag {
					margin-left: 10rpx;
					display: inline-block;
					padding: 8rpx 10rpx;
					font-size: 14rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #4cbeca;
					line-height: 21rpx;
					border: 1px solid #0bb9c8;
					border-radius: 6px;
				}
			}

			.date {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #a3a3a3;
				line-height: 36rpx;
			}
		}

		.btn {
			padding: 8rpx 19rpx;
			background: #e6e6e6;
			border-radius: 6rpx;
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #4cbeca;
			line-height: 1;
		}
	}

	.content {
		padding: 0 44rpx;
        
		.title {
			font-size: 40rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #000000;
			line-height: 47rpx;
		}

		.static {
			margin-top: 34rpx;
			justify-content: space-between;
			align-items: center;

			.left,
			.right {
				padding:3px 0;
				align-items: center;

				.block {
					display: flex;
					align-items: center;
					margin-right: 10rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 32rpx;
					text-align: left;
					font-style: normal;
				}
			}

			.left {
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #787878;
				line-height: 1;
				width:100%;
				.gf {
					width: 24rpx;
					height: 24rpx;
					margin-right: 8rpx;
				}
			}

			
		}

		.detail {
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #666666;
			line-height: 44rpx;
			text-align: left;
			font-style: normal;
			margin-top: 50rpx;
		}
	}

	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 999;
		height: 100rpx;
		padding: 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #ffffff;

		.ipt {
			width: 380rpx;
			height: 77rpx;
			background: #f7f7f7;
			border-radius: 38px;
			padding: 0 37rpx;
			box-sizing: border-box;
			margin-right: 20rpx;
		}

		.control {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.block {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
			}

			.icon {
				height: auto;
			}

			.c {
				width: 41rpx;
				margin-right: 10rpx;
			}

			.s {
				width: 36rpx;
			}

			.t {
				width: 31rpx;
			}
		}
	}
</style>
