<template>
	<view class="content">
		<u-alert fontSize="13"  type = "info" description = "为了给您提供更好的服务，希望您能用几分钟时间，将您的感受和建议告诉我们，我们非常重视您的宝贵意见!"></u-alert>
		<view class="cont-box">
			<view class="cont">
				<view class="doctor">
					<view class="left">
						<view class="name"  >发布医生:{{dortor!=null?doctor.doctorName:""}}</view>
						<view class="count" v-if="follow!=null">{{follow.num}}/{{follow.totalNum}}期</view>
					</view>
					<view class="right">
						{{follow.planTime}}
					</view>
				</view>
				<view class="item-box">
					<view class="item" v-for="(item,index) in form">
						<view class="title">{{item.question}}</view>
						<view class="option">
							<u-radio-group
								:disabled="true"
								v-if="item.type==1"
							    v-model="item.answers"
							    placement="column"
							  >
							    <u-radio
							      :customStyle="{marginBottom: '8px'}"
							      v-for="(option, subIndex) in item.options"
							      :key="subIndex"
							      :label="option"
							      :name="option"
							    >
							    </u-radio>
							</u-radio-group>
							<u-checkbox-group
								:disabled="true"
								v-if="item.type==2"
							    v-model="item.answers"
							    placement="column"
							  >
							    <u-checkbox
							      :customStyle="{marginBottom: '8px'}"
							      v-for="(option, subIndex) in item.options"
							      :key="subIndex"
							      :label="option"
							      :name="option"
							    >
							    </u-checkbox>
							</u-checkbox-group>
							<u--textarea :disabled="true" count maxlength="200" v-if="item.type==3" v-model="item.answers" placeholder="请输入内容" ></u--textarea>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btn-box" >
			<view class="btn cancel" @click="toIM()"  >咨询</view>
		</view>
	</view>
</template>
 
<script  >
	import store from "@/store";
	import {getFollowById,doFollow} from '@/api/follow.js'
	import {navigateToDesignatedConversation,setConversation} from "@/pages_im/util/imCommon";
	import IMSDK, {SessionType} from "openim-uniapp-polyfill";
	export default {
		data() {
			return {
				followId:null,
				follow:null,
				doctor:null,
				form:null,
			}
		},
		onLoad(options) {
			this.followId=options.followId;
		},
		onShow() {
			this.getFollowById();
		},
		methods: {
			toIM(){
				var that=this;
				var userId=uni.getStorageSync('userId');
				var did='D' + this.doctor.doctorId;
				var conversationID=`si_D${this.doctor.doctorId}_U${userId}`;
				var ex={imType:2,orderId:this.follow.orderId,followId:this.follow.followId,type:"startFollow"}
				this.$store.commit("timStore/setType","startFollow");
				this.$store.commit("timStore/setOrderId",this.follow.orderId);
				this.$store.commit("timStore/setFollowId",this.follow.followId);
				this.$store.commit("timStore/setImType", 2);
				this.$store.commit("timStore/setConversationID", conversationID);
				navigateToDesignatedConversation(did,SessionType.Single,false).then((res) => {
					setConversation(conversationID,JSON.stringify(ex)).then(() => {
								
					}).catch(() => {});
				}).catch(() => uni.$u.toast("操作失败") );
			},
			doFollow(){
				var that=this;
				uni.showModal({
					title:"提示",
					content:"确认提交吗吗?",
					showCancel:true,
					cancelText:'取消',
					confirmText:'确定',
					success:res=>{
						if(res.confirm){
							// 用户点击确定
							var data={
								followId:this.followId,
								formJson:JSON.stringify(this.form)
							}
							doFollow(data).then(
								res => {
									if(res.code==200){
										uni.showToast({
											icon:'success',
											title: "操作成功",
										});
										setTimeout(function() {
											 uni.$emit('refreshFollowList');
											 uni.navigateBack({
												 delta: 1
											 })
										}, 500);
									}else{
										uni.showToast({
											icon:'none',
											title: res.msg,
										});
									}
								},
								rej => {}
							);
														
						}else{
							// 否则点击了取消  
						}
					}
				})
			},
			getFollowById(){
				var that=this;
				var data={followId:this.followId}
				getFollowById(data).then(
					res => {
						if(res.code==200){
							this.follow=res.follow;
							this.doctor=res.doctor;
							this.form=JSON.parse( this.follow.formJson);
							
						}
					},
					err => {
					}
				);
				
			},
		}
	}
</script>
<style lang="scss">
	page{
		background: #f6f6f6;
	}
</style>
<style scoped lang="scss">
	.content{
		position: relative;
		.cont-box{
			padding: 20rpx 20rpx 140rpx;
			.cont{
				padding: 20rpx;
				background-color: #fff;
				border-radius: 20upx;
				.doctor{
					display: flex;
					flex-direction: row;
					align-items: flex-start;
					justify-content: space-between;
					.left{
						display: flex;
						flex-direction: column;
						align-items: flex-start;
						justify-content: flex-start;
						.name{
							font-size: 28upx;
							font-family: PingFang SC;
							color: #9a9a9c;
						}
						.count{
							font-size: 28upx;
							font-family: PingFang SC;
							color: #9a9a9c;
						}
					}
					.right{
						font-size: 28upx;
						font-family: PingFang SC;
						color: #9a9a9c;
					}
				}
				.item-box{
					margin: 15rpx 0rpx;
					.item{
						.title{
							font-size: 28rpx;
							font-weight: bold;
						}
						.option{
							margin-left: 10rpx;
						}
					}
					
				}
			}
			
			
		}
		 
		
	}
	.btn-box{
		z-index: 999;
		bottom: 0;
		width: 100%;
		position: fixed;
		height: 120upx;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 0 30upx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		.btn{
			width: 155upx;
			height: 64upx;
			line-height: 64upx;
			font-size: 26upx;
			font-family: PingFang SC;
			font-weight: 500;
			text-align: center;
			border-radius: 32upx;
			margin-left: 15upx;
			&.cancel{
				border: 1px solid #DDDDDD;
				color: #666666;
			}
			&.pay{
				background: #078C9D;
				color: #FFFFFF;
			}
		}
	}
	 
</style>
