<template>
	<view class="content">
		<view class="detail-cont">
			<view class="title">{{item.title}}</view>
			<view class="doctor-info">
				<image :src="item.avatar!==null?item.avatar:'https://qinggetai.oss-rg-china-mainland.aliyuncs.com/qgt/20240511/e7668e973cb44f1d8d7bf749c827f814.jpg'" mode="aspectFill"></image>
				<view class="doctor">{{item.doctorName||'崔医生'}}</view>
				<view class="source">179集团医院</view>
			</view>
			<view class="info">
				<view class="time">{{utils.timeFormat(item.createTime,'yyyy年mm月dd日 hh:MM:ss') }}</view>
			</view>
			<view class="video"  v-if="item.videoUrl!=null">
				<video class="myVideo" id="myVideo" :src="item.videoUrl"
				                  @error="videoErrorCallback"   controls></video>
			</view>
			<!-- 正文 -->
			<view class="full-text"  >
				<view v-html="item.content"></view>
			</view>
			<view class="reads">阅读数：{{item.views}}</view>
		</view>
		<!-- 咨询按钮 -->
	<!-- 	<view class="inquiry"  >
			<view class="content"  @click="navTo('/pages_doctor/doctorDetails?doctorId='+item.doctorId)">
				<image  mode="aspectFill"  :src="item.avatar" ></image>
				<text class="text">{{item.doctorName}}</text>
			</view>
		</view> -->
		<!-- <view class="ad">
			<u-swiper
					:list="advImgs"
					indicator
					indicatorMode="line"
					circular
					@click="handleAdvClick">
			  </u-swiper>
		</view> -->
	</view> 
</template>

<script>
	// import {getAdvList} from '@/api/adv.js'
	import {getDoctorArticleById} from '@/api/doctorArticle.js'
	export default {
		data() {
			return {
				advs:[],
				advImgs:[],
				src: '',
				articleId:null,
				item:{},
			};
		},
		onLoad(option) {
			this.articleId=option.articleId;
			 
		},
		onShow() {
			//this.getAdvList()
			this.getDoctorArticleById();
		},
		//发送给朋友
		onShareAppMessage(res) {
			return {
				title: this.item.title,
				path: '/pages_index/index/doctorArticleDetails?articleId='+this.articleId,
			}
			
		},
		//分享到朋友圈
		onShareTimeline(res) {
			return {
				title: this.item.title,
				query:'articleId='+this.articleId,//页面参数
			}
			
		},
		methods:{
			handleAdvClick(index){
				var ad=this.advs[index];
				console.log(ad.advUrl);
				if(ad.showType==1){
					uni.setStorageSync('url',ad.advUrl);
					uni.navigateTo({
						url:"h5"
					})
				}
				else if(ad.showType==2){
					uni.navigateTo({
						url:ad.advUrl
					})
				}
				else if(ad.showType==3){
					 uni.setStorageSync('content',ad.content);
					 uni.navigateTo({
					 	url:"content"
					 })
				}
				
			},
			getAdvList() {
				//联网加载数据
				var that = this;
				var data = {
					advType:10
				};
				getAdvList(data).then(res => {
					if(res.code==200){
						that.advImgs=[];
						that.advs=[];
						res.data.forEach(function(element) {
							if(element.imageUrl!=null&&element.imageUrl!=""){
								that.advs.push(element);
								that.advImgs.push(element.imageUrl);
							}
						});
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			},
			 
			videoErrorCallback: function(e) {
				uni.showModal({
					content: e.target.errMsg,
					showCancel: false
				})
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
			getDoctorArticleById(){
				let data = {articleId:this.articleId};
				getDoctorArticleById(data).then(
					res => {
						if(res.code==200){
							this.item=res.data;
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	.detail-cont{
		width: calc(100% - 60rpx) ;
		flex: 1;
		padding: 30upx;
		overflow-y: auto;
		background: #fff;
		.title{
			font-size: 44upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #222222;
			line-height: 70upx;
		}
		.doctor-info{
			display: flex;
			align-items: center;
			margin:20rpx 0;
			image{
				width: 64rpx;
				height: 64rpx;
				border-radius: 50%;
			}
			.doctor{
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #222426;
				text-align: left;
				margin:0 16rpx ;
			}
			.source{
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #66789E;
				text-align: left;
			}
		}
		.info{
			display: flex;
			align-items: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #B2B2B2;
			line-height: 48upx;
			margin: 23upx 0;
			
		}
		.full-text{
			width: 100%;
			font-size: 34upx;
			font-family: PingFang SC;
			// font-weight: 500;
			color: #222222;
			line-height: 60upx;
		}
		.reads{
			margin-top: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #B2B2B2;
			text-align: left;
		}
		.video{
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			video{
				width: 100%;
			}
		}
	}
	.ad{
		margin-bottom: 50rpx;
		width: 100%;
		padding: 15rpx;
		 
	}
	.inquiry{
		position: fixed;
		right: 22upx;
		bottom: 193upx;
		z-index: 99;
		.content{
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			image{
				box-sizing: border-box;
				width: 100upx;
				height: 100upx;
				border-radius: 50%;
				z-index: 9;
				border: 2rpx solid #0bb3f2;
			}
			.text{
				margin-top: 15upx;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #0bb3f2;
			}
			 
		}
		
	}
	 
</style>
