<template>
	<view class="content" :style="$store.state.theme.currentMoban">
		<view class="detail-cont">
			<view class="title">{{item.title}}</view>
			<view class="info">
				<view class="reads">阅读数：{{item.views}}</view>
				<view class="time">{{item.publishTime}}</view>
			</view>
			<!-- 正文 -->
			<view class="full-text">
				<view v-html="item.contents"></view>
			</view>
		</view>
		<!-- 最近阅读 -->
		<view class="recent-reads">
			<view class="left">
				<text class="label">最近阅读</text>
				<view class="peop-box" @click="showUsers">
					<view class="head-box">
						<view class="head" v-for="(subitem,j) in views" :key="j">
							<image :src="subitem.avatar==null?'../../static/images/detault_head.jpg':subitem.avatar" mode=""></image>
						</view>
					</view>
					<image class="arrow" src="../../static/images/arrow_gray.png" mode=""></image>
				</view>
			</view>
			<view class="share-btn">
				<image src="../../static/images/share.png" mode=""></image>
				<text>分享</text>
				<button  class="share" data-name="shareBtn" open-type="share">分享</button>
			</view>
		</view>
		<!-- 咨询按钮 -->
		<view class="inquiry">
			<view class="content">
				<image src="../../static/images/consult.png" mode=""></image>
				<text class="text">咨询</text>
				<button class="contact-btn" open-type="contact"></button>
			</view>
			
		</view>
	</view> 
</template>

<script>
	import {getArticleByArticleId,updateView} from '@/api/article'
	export default {
		data() {
			return {
				articleId:null,
				item:{},
				views:[],
			};
		},
		onLoad(option) {
			this.articleId=option.articleId;
			this.utils.isLogin().then(res => {
				if(res){
					this.updateView();
				}
			})
			uni.showShareMenu({
				withShareTicket:true,
				//小程序的原生菜单中显示分享按钮，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
				menus:["shareAppMessage","shareTimeline"] //不设置默认发送给朋友
			})
		},
		onShow() {
			this.getArticleByArticleId();
		},
		//发送给朋友
		onShareAppMessage(res) {
			return {
				title: this.item.title,
				path: '/pages/healthy/detail?articleId='+this.item.productId,
				imageUrl: this.item.imageUrl //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
			}
			
		},
		//分享到朋友圈
		onShareTimeline(res) {
			return {
				title: this.item.title,
				query:'articleId='+this.item.articleId,
				imageUrl: this.item.imageUrl //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
			}
			
		},
		methods:{
			updateView(){
				updateView(this.articleId).then(
					res => {
					},
					rej => {}
				);
			},
			getArticleByArticleId(){
				let data = {articleId:this.articleId};
				getArticleByArticleId(data).then(
					res => {
						if(res.code==200){
							this.item=res.data;
							this.views=res.views;
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			// 查看阅读用户
			showUsers() {
				uni.navigateTo({
					url: './readUsers?articleId='+this.articleId
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	.detail-cont{
		flex: 1;
		padding: 40upx;
		overflow-y: auto;
		.title{
			font-size: 40upx;
			font-family: PingFang SC;
			// font-weight: bold;
			color: #222222;
			line-height: 70upx;
		}
		.info{
			display: flex;
			align-items: center;
			font-size: 24upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			line-height: 48upx;
			margin: 23upx 0;
			.reads{
				margin-right: 30upx;
			}
		}
		.full-text{
			font-size: 36upx;
			font-family: PingFang SC;
			// font-weight: 500;
			color: #222222;
			line-height: 60upx;
		}
	}
	.recent-reads{
		flex-shrink: 0;
		box-sizing: border-box;
		height: 121upx;
		background: #FFFFFF;
		border-top: 1px solid #F0F0F0;
		padding: 0 40upx 0 37upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.left{
			display: flex;
			align-items: center;
			.label{
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				line-height: 1;
				margin-right: 20upx;
			}
			.peop-box{
				display: flex;
				align-items: center;
				.head-box{
					margin-right: 28upx;
					display: flex;
					align-items: center;
					.head{
						width: 48upx;
						height: 48upx;
						border-radius: 50%;
						overflow: hidden;
						box-shadow: 0 0 0 1px #fff;
						margin-right: -10upx;
						image{
							width: 100%;
							height: 100%;
						}
					}
				}
				.arrow{
					width: 13upx;
					height: 23upx;
				}
			}
		}
		.share-btn{
			position: relative;
			width: 240upx;
			height: 80upx;
			line-height: 80upx;
			font-size: 30upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background: var(--base-color);
			border-radius: 40upx;
			display: flex;
			align-items: center;
			justify-content: center;
			image{
				width: 32upx;
				height: 32upx;
				margin-right: 15upx;
			}
			.share{
				position: absolute;
				width: 100%;
				height: 100%;
				opacity: 0;
			}
		}
	}
	.inquiry{
		width: 131upx;
		height: 131upx;
		position: fixed;
		right: 22upx;
		bottom: 193upx;
		z-index: 99;
		
		.content{
			position: relative;
			image{
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
				z-index: 9;
			}
			.text{
				position: absolute;
				top: 70upx;
				left: 50%;
				transform: translateX(-50%);
				z-index: 10;
				font-size: 22upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: var(--base-color);
				line-height: 1;
			}
			 
		}
		
		
	}
	.contact-btn{
		display: inline-block;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		opacity: 0;
		z-index: 9999;
	}
</style>
