<template>
	<view class="content">
		<view class="bg">
			<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/dd7da40764af4db0ac326db271c7f1d3.png" />
		</view>
		 <view class="top-box"   >
		 	<view class="status_bar" :style="{height: statusBarHeight}"></view>
		 	<view class="btn-box">
				<view class="btns" @click="goback()">
					<view class="btn"  >
						<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/back_white.png" />
					</view>
					<view class="line"  ></view>
					<view class="btn" @click="gohome()" >
						<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/5981c2cd5f23484181f5b328c820d0de.png" />
					</view>
				</view>
			</view>
			
		 </view>
		<view class="cont">
			<view class="status_bar" :style="{height: statusBarHeight}"></view>
			<view class="docs" style="margin-top:88rpx" >
				<view class="tip" @click="navTo('/pages_doctor/doctorImgs?doctorId='+doctor.doctorId)">
					<view class="left">
						<view class="title">
							<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/a58ee2a3fb674c2e8339243cb4ca1378.png"></image>
							<view >实名认证</view>
						</view>
						<view class="cert">
							<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/62aeeb0579974b67863a6ab56e9562f9.png"></image>
							<view   >资格证编号:{{doctor.certificateCode!=null?doctor.certificateCode.substr(0,4)+"****"+doctor.certificateCode.substr(doctor.certificateCode.length-4,doctor.certificateCode.length):""}}</view>
						</view>
					</view>
					<view class="right">
						<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/1d519ad0467e4daea843aac745ae6b40.png"></image>
					</view>
				</view>
				<view class="doc-cont">
					<view class="doc-box">
						<view class="left">
							<image :src="doctor.avatar" mode="aspectFill"></image>
						</view>
						<view class="right">
							<view class="doc-name-box">
								<view class="doc-name">
									{{doctor.doctorName || ''}}
								</view>
								<view class="doc-btns"  >
									<view class="btn" @click="followChange()">
										<image v-if="isFollow" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_strar.png"></image>
										<image v-if="!isFollow" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/d509e50536804703a4b7dc066b16beee.png"></image>
										关注
									</view>
									<view class="btn">
										<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/f79c3b9cbefa40be8c2beb74f616eefc.png"></image>
										分享
										<button class="contact-btn"   data-name="shareBtn" open-type="share">分享</button>
									</view>
								</view>
							</view>
							<view class="doc-dept-box">
								{{doctor.position || ''}}
								<view class="line"></view>
								{{department.deptName || ''}} 
							</view>
							<view class="doc-his-box">
								{{hospital.hospitalName || ''}}
							</view>
							
						</view>
						
					</view>
					<view class="doc-desc-box">
						<view class="doc-desc-cont"  @click="navTo('/pages_doctor/doctorInfo?doctorId='+doctor.doctorId)">
							<view class="desc-cont ellipsis2"><text class="title">擅长:</text>{{doctor.speciality}}</view>
							<view class="btn">详情</view>
						</view>
						<view class="doc-desc-cont" @click="navTo('/pages_doctor/doctorInfo?doctorId='+doctor.doctorId)">
							<view class="desc-cont ellipsis2"><text class="title">介绍:</text>{{doctor.introduction}}</view>
							<view class="btn">详情</view>
						</view>
					</view>
					
				</view>
				
			</view>
			
			<view class="price-box">
				<view class="count-box">
					<view class="count-item">
						<view class="count yellow">{{doctor.pingStar||0}}分</view>
						<view class="name">好评</view>
					</view>
					<view class="count-item">
						<view class="count">{{doctor.orderNumber||0}}</view>
						<view class="name">接诊量</view>
					</view>
					<view class="count-item">
						<view class="count">{{doctor.speed||0}}分钟</view>
						<view class="name">平均响应</view>
					</view>
					<view class="count-item">
						<view class="count">0</view>
						<view class="name">粉丝数</view>
					</view>
				</view>
				<view class="price-list" v-if="doctor!=null&&doctor.prices!=null&&doctor.prices.length>0">
					<view class="price-item" @click="doInquiry(price)" v-for="(price,index) in doctor.prices">
						<view class="p-left">
							<image  v-if="price.type==1" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/645f3f298a264882b48e529342fc4074.png"></image>
							<image  v-if="price.type==2" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/45e904a9e74f4d1da771936a4b83f015.png"></image>
							<view class="price-name">
								<view class="price">
									<text class="title" v-if="price.type==1">图文问诊</text>
									<text class="title" v-if="price.type==2">视频问诊</text>
									<text class="money">{{price.price.toFixed(2)}}/次</text>
								</view>
								<view class="price-desc" v-if="price.type==1">
									与医生图文交流
								</view>
								<view class="price-desc" v-if="price.type==2">
									与医生视频交流
								</view>
							</view>
							
						</view>
						<view class="p-right">
							<view :class="doctor.workStatus==1?'btn':'btn gray'" >
								去咨询
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="his-box">
				<view class="title-box">
					<view class="title">执业医院</view>
				</view>
				<view class="his"  @click="navTo('/pages/index/hospitalDetails?hospitalId='+hospital.hospitalId)">
					<view class="left">
						<view class="his-name">
							{{hospital.hospitalName}}
						</view>
						<view class="his-desc" v-if="hospital.hospitalType!=null">
							{{hospital.hospitalType}}
						</view>
					</view>
					<view class="right">
						<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_arrow_r.png"></image>
					</view>
				</view>
			</view> -->
			<!-- <view class="desc-box">
				<view class="title-box">
					<view class="title">医生介绍</view>
				</view>
				<view class="desc" >
					{{doctor.introduction}}
				</view>
			</view> -->
			<view class="ping-box">
				<view class="title-box">
					<view class="left">
						<view class="title">患者评价({{pingsTotal}})</view>
					</view>
					<view class="more" @click="navTo('./doctorPingList?doctorId='+doctorId)">
						<view >更多</view>
						<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_arrow_r.png"></image>
					</view>
				</view>
				<view class="ping-list" v-if="pings.length>0">
					<view class="ping-item" v-for="(item) in pings">
					 	<view class="left">
							<image :src="item.avatar==null?'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/detault_head.jpg':item.avatar"></image>
						</view>
						<view class="right">
							<view class="user-name-box">
								<view class="user-name">
									{{item.nickName}}
								</view>
								<view class="ping-star">
									<u-rate activeColor="#ffc603" count="5" readonly v-model="item.pingStar"></u-rate>
								</view>
							</view>
							<view class="ping-cont">
								{{item.pingContent}}
							</view>
							<view class="ping-time">
								{{item.pingTime}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {checkFollow,doFollow,getDoctorDetails,getDoctorPingList} from '@/api/doctor.js'
	export default {
		data() {
			return {
				pingsTotal:0,
				statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
				isFollow:false,
				doctorId:null,
				doctor:{},
				department:{},
				hospital:{},
				pings:[]
			}
		},
		onLoad(options) {
			if(options.doctorId!=null){
				this.doctorId=options.doctorId;
			}
			else if (options.hasOwnProperty('q') && options.q) {
				// 通过下面这步解码，可以拿到url的值
				const url = decodeURIComponent(options.q)
				// // 对url中携带的参数提取处理
				const obj = this.$urlToObj(url)
				uni.setStorageSync('doctorId',obj.doctorId);
				this.doctorId=obj.doctorId;
			}
		},
		onShow() {
			this.getDoctorDetails();
			this.getDoctorPingList();
			var that=this;
			this.$isLogin().then(
				res => {
					if(res){
						that.checkFollow();
					}
				},
				rej => {}
			);
		},
		//发送给朋友
		onShareAppMessage(res) {
			return {
				title: this.doctor.doctorName,
				path: '/pages_doctor/doctorDetails?doctorId='+this.doctorId,
				imageUrl: 'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/sharelogo.png' //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
			}
			
		},
		//分享到朋友圈
		onShareTimeline(res) {
			return {
				title: this.doctor.doctorName,
				query:'doctorId='+this.doctorId,//页面参数
				imageUrl: 'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/sharelogo.png' //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
			}
			
		},
		methods: {
			goback(){
				uni.navigateBack()
			},
			gohome(){
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			doInquiry(price){
				if(this.doctor.workStatus==0){
					uni.showToast({
						icon:'none',
						title: "医生休息中",
					});
					return;
				}
				var that=this;
				this.$isLogin().then(
					res => {
						if(res){
							uni.navigateTo({
							 	url: "/pages_order/inquiryForm1?inquiryType=1&orderType="+price.type+"&doctorId="+that.doctorId
							})
						}
						else{
							uni.navigateTo({
								url:'/pages/auth/login'
							})
						}
						
					},
					rej => {}
				);
			},
			followChange() {
				this.$isLogin().then(
					res => {
						if(res){
							this.doFollow();
						}
						else{
							uni.navigateTo({
								url:'/pages/auth/login'
							})
						}
					},
					rej => {}
				);
			},
			checkFollow(){
				var that=this;
				var data={doctorId:this.doctorId}
				checkFollow(data).then(
					res => {
						
						if(res.code==200){
							if(res.isFollow==1) {
								this.isFollow=true;
								
							} else {
								this.isFollow=false;
							}
						}
						else{
							this.isFollow=false;
						}
					},
					rej => {}
				);
			},
			doFollow(){
				var that=this;
				var data={doctorId:this.doctorId}
				doFollow(data).then(
					res => {
						this.isFollow=!this.isFollow;
						if(res.code=200){
							uni.showToast({
								title: res.msg
							})
						}
					},
					rej => {}
				);
			},
			getDoctorDetails() {
				//联网加载数据
				var that = this;
				var data = {
					doctorId: this.doctorId
				};
				getDoctorDetails(data).then(res => {
					if(res.code==200){
						this.doctor=res.data.doctor || {};
						this.doctor.prices=JSON.parse(this.doctor.priceJson)
						this.department=res.data.department || {};
						this.hospital=res.data.hospital || {};
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			},
			getDoctorPingList() {
				//联网加载数据
				var that = this;
				var data = {
					doctorId: this.doctorId,
					pageNum: 1,
					pageSize: 10
				};
				getDoctorPingList(data).then(res => {
					if(res.code==200){
						this.pings=res.data.list;
						this.pingsTotal=res.data.total
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>
<style scoped lang="scss">
	.content{
		height: 100%;
		position: relative;
		.bg{
			width: 100%;
			height:500rpx;
			// background-color: #2583EB;
			// background: linear-gradient(#2583EB, #2EDAD4);
			border-radius: 0rpx 0rpx 50rpx 50rpx;
			position: fixed;
			image{
				width: 100%;
				height:500rpx;
			}
			// z-index: 1;
		}
		.top-box{
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1001;
			.btn-box{
				height:88rpx;
				margin-left: 15rpx;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				.btns{
					display: flex;
					align-items: center;
					justify-content: flex-start;
					background: rgba(255,255,255,0.4);
					border-radius: 44rpx;
					opacity: 1;
					.btn{
						display: flex;
						align-items: center;
						justify-content: center;
						padding: 15rpx 20rpx;
						image{
							width:32rpx;
							height:32rpx;
						}
					}
					.line{
						width:2rpx;
						height:40rpx;
						background: rgba(233,233,233,0.5);
						border-radius: 2px;
						opacity: 1;
					}
				}
				
			}
			 
		}
		.cont{
			top:50rpx;
			position: relative;
			padding: 0rpx 20rpx;
			z-index: 999;
			width: 100%;
			display: flex;
			flex-direction: column;
			
			.docs{
				margin-bottom: 20rpx;
				padding-top: 30rpx;
				position: relative;
				.tip{
					z-index: 110;
					width: 100%;
					position: absolute;
					top:-25rpx;
					padding: 0rpx 26rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					height:60rpx;
					background-color: #2c261f;
					border-radius: 15rpx 15rpx 0rpx 0rpx;
					.left{
						display: flex;
						align-items: center;
						justify-content: flex-start;
						.title{
							display: flex;
							align-items: center;
							justify-content: flex-start;
							color: #F0CBB1;
							font-size: 24rpx;
							font-weight: bold;
							image{
								margin-right: 5rpx;
								width:20rpx;
								height:20rpx;
							}
						}
						.cert{
							margin-left: 10rpx;
							display: flex;
							align-items: center;
							justify-content: flex-start;
							color: #F0CBB1;
							font-size: 24rpx;
							font-weight: bold;
							image{
								margin-right: 10rpx;
								width:20rpx;
								height:20rpx;
							}
						}
					}
					.right{
						image{
							width:20rpx;
							height:20rpx;
						}
					}
				}
				.doc-cont{
					z-index:111;
					padding: 30rpx;
					box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
					background-color: #fff;
					border-radius: 15rpx;
					.doc-box{
						display: flex;
						align-items: center;
						justify-content: flex-start;
						.left{
							width: 190upx;
							height: 190upx;
							image{
								box-sizing: border-box;
								border-radius: 50%;
								border:3rpx solid #2EDAD4;
								width: 190upx;
								height: 190upx;
							}
						}
						.right{
							display: flex;
							flex-direction: column;
							justify-content: flex-start;
							margin-left: 20rpx;
							height:190upx;
							width: calc(100% - 210upx);
							.doc-name-box{
								display: flex;
								align-items: center;
								justify-content: space-between;
								position: relative;
								.doc-name{
									font-size: 38rpx;
									font-weight: bold;
									color: #2A2B2E;
								}
								.doc-btns{
									display: flex;
									align-items: center;
									justify-content: flex-end;
									.btn{
										flex-shrink: 0;
										border-radius: 30rpx;
										padding: 10rpx 20rpx;
										border: 1rpx solid #2583EB;
										margin-left: 10rpx;
										display: flex;
										align-items: center;
										justify-content: center;
										margin-left: 10rpx;	
										color: #2583EB;
										font-size: 24rpx;
										font-weight: bold;
										position: relative;
										image{
											margin-right: 5rpx;
											width:24rpx;
											height:24rpx;
										}
										.contact-btn{
											display: inline-block;
											position: absolute;
											top: 0;
											left: 0;
											width: 100%;
											height: 100%;
											opacity: 0;
											z-index: 9999;
										}
									}
									
									
								}
								 
							}
							.doc-dept-box{
								display: flex;
								align-items: center;
								justify-content: flex-start;
								margin-top: 15rpx;
								font-size: 28upx;
								font-weight: bold;
								font-family: PingFang SC;
								color: #2d2b36;
								.line{
									height:25rpx;
									width:3rpx;
									background-color: #ECECEC;
									margin: 0rpx 10rpx;
								}
								 
							}
							.doc-his-box{
								display: flex;
								align-items: center;
								justify-content: flex-start;
								margin-top: 15rpx;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #2d2b36;
								 
							}
							
						}
						
					}
					.doc-desc-box{
						.doc-desc-cont{
							width: 100%;
							display: flex;
							align-items: center;
							justify-content: flex-start;
							position: relative;
							margin-top: 15rpx;
							.title{
								font-weight: bold;
								// position: absolute;
								// top:0rpx;
								// left:0rpx;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #2A2B2E;
							}
							.desc-cont{
								width: 100%;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #9a9a9c;
							}
							.btn{
								padding: 0rpx 0rpx 0rpx 15rpx;
								background-color: white;
								position: absolute;
								bottom: 0rpx;
								right:0rpx;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #3D74F7;
							}
							
						}
					}
				}
				
			}
			
			.price-box{
				margin-bottom: 20rpx;
				padding: 15rpx;
				background: linear-gradient(180deg, #F8EADC 0%, #FAF2E7 100%);
				box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
				border-radius: 15rpx;
				.count-box{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.count-item{
						width:25%;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: space-between;
						.count{
							font-size: 32upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #2A2B2E;
						}
						.yellow{
							font-size: 40rpx;
							color: #2583EB;
						}
						.name{
							margin-top: 10rpx;
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #626468;
						}
					}
				}
				.price-list{
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					justify-content: flex-start;
					margin-top: 15rpx;
					padding: 15rpx;
					.price-item{
						margin-bottom: 15rpx;
						padding: 20rpx;
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						border-radius: 15rpx;
						background-color: #ffffff;
						.p-left{
							display: flex;
							align-items: center;
							justify-content: flex-start;
							image{
								width: 96rpx;
								height:96rpx;
							}
							.price-name{
								padding: 10rpx 0rpx;
								margin-left: 15rpx;
								display: flex;
								flex-direction: column;
								align-items: flex-start;
								justify-content: space-between;
								.price{
									display: flex;
									align-items: center;
									justify-content: flex-start;
									
									.title{
										font-size: 32upx;
										font-family: PingFang SC;
										font-weight: bold;
										color: #111111;
									}
									.money{
										font-size: 32upx;
										font-family: PingFang SC;
										font-weight: bold;
										color: #FD8005;
									}
									
								}
								.price-desc{
									margin-top: 20rpx;
									font-size: 28upx;
									font-family: PingFang SC;
									color: #9a9a9c;
								}
								
							}
							
							
						}
						.p-right{
							.btn{
								padding: 15rpx 30rpx;
								background-color: #2583EB;
								color: #fff;
								font-size: 28rpx;
								border-radius: 30rpx;
							}
							.gray{
								background-color: #9a9a9c;
							}
						}
						
					}
				}
			}
			.his-box{
				margin-bottom: 20rpx;
				padding: 15rpx;
				box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
				background-color: #fff;
				border-radius: 15rpx;
				.title-box{
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: flex-start;
					.title{
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #111111;
					}
				}
				.his{
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 15rpx;
					.left{
						display: flex;
						flex-direction: column;
						align-items: flex-start;
						justify-content: center;
						.his-name{
							font-size: 32upx;
							font-family: PingFang SC;
							color: #111111;
						}
						.his-desc{
							margin-top: 15rpx;
							font-size: 28upx;
							font-family: PingFang SC;
							color: #9a9a9c;
						}
					}
					.right{
						image{
							width:30rpx;
							height:30rpx;
						}
					}
				}
			}
			.desc-box{
				margin-bottom: 20rpx;
				padding: 15rpx;
				box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
				background-color: #fff;
				border-radius: 15rpx;
				.title-box{
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: flex-start;
					.title{
						font-size: 32upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #111111;
					}
				}
				.desc{
					margin-top: 15rpx;
					font-size: 28upx;
					font-family: PingFang SC;
					color: #9a9a9c;
				}
			}
			.ping-box{
				margin-bottom: 20rpx;
				padding: 15rpx;
				box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
				background-color: #fff;
				border-radius: 15rpx;
				.title-box{
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;
					.left{
						display: flex;
						align-items: center;
						justify-content: center;
						.title{
							font-size: 32upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #111111;
						}
					}
					.more{
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28upx;
						font-family: PingFang SC;
						color: #9a9a9c;
						image{
							margin-left: 10rpx;
							width: 30rpx;
							height:30rpx;
						}
					}
					
					 
				}
				.ping-list{
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					justify-content: flex-start;
					margin-top: 15rpx;
					padding: 15rpx;
					.ping-item{
						padding: 20rpx 0rpx;
						border-bottom: 1rpx solid #efefef;
						width: 100%;
						display: flex;
						align-items: flex-start;
						justify-content: flex-start;
						&:last-child{
							padding-bottom: 0rpx;
							border-bottom: none;
						}
						.left{
							image{
								width:80rpx;
								height:80rpx;
								border-radius: 50%;
							}
						}
						.right{
							width: 100%;
							margin-left: 15rpx;
							.user-name-box{
								display: flex;
								align-items: center;
								justify-content: space-between;
								font-size: 28upx;
								font-family: PingFang SC;
								font-weight: bold;
								color: #111111;
							}
							.ping-cont{
								margin-top: 10rpx;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #9a9a9c;
							}
							.ping-time{
								margin-top: 10rpx;
								font-size: 28upx;
								font-family: PingFang SC;
								color: #9a9a9c;
							}
							 
						}
					}
				}
			}
		}
	}
	 
</style>
