<template>
	<view class="content">
		<view class="banner">
			<view class="avatar">
				<!-- #ifdef MP-WEIXIN -->
				<open-data type="userAvatarUrl"></open-data>
				<!-- #endif -->	
				<!-- #ifdef H5 -->
				<image src="../../static/images/avatar.png" mode="widthFix"></image>
				<!-- #endif -->
				
			</view>
			<view class="bottom">
				<view class="name">
				<!-- #ifdef MP-WEIXIN -->
					<open-data type="userNickName"></open-data>
				<!-- #endif -->				
				<!-- #ifdef H5 -->
					<text>{{name}}</text>
				<!-- #endif -->
				</view>
				<view class="edit" @click="editHandle">
					<text class="zhcx-icon-bianji zhcx-iconfont"></text>
				</view>				
			</view>
		</view>
		<view class="zhcx-table">
			<view class="zhcx-table-row">				  
				<view class="name">
					<text>姓名</text>
				</view>
				<view class="text" >
					<input type="text" v-model="name" disabled />
				</view>
			</view>		
			<view class="zhcx-table-row">
				<view class="name">
					<text>电话号码</text>
				</view>
				<view class="text" >
					<input type="text" v-model="phoneNumber" disabled  />
				</view>
			</view>	
			<view class="zhcx-table-row">
				<view class="name">
					<text>身份证</text>
				</view>
				<view class="text" >
					<input type="text" v-model="idCard" disabled />
				</view>
			</view>	
			<view class="zhcx-table-row">
				<view class="name">
					<text>性别</text>
				</view>
				<view class="text" >
					<text>{{gender==='0'?'男':'女'}}</text>
				</view>
			</view>		
			<view class="zhcx-table-row">
				<view class="name">
					<text>住址</text>
				</view>
				<view class="text" >
					<input type="text" v-model="address" disabled />
				</view>
			</view>	
			<view class="zhcx-table-row">
				<view class="name">
					<text>积分</text>
				</view>
				<view class="text" >
					<input type="text" :value="integral" disabled />
				</view>
			</view>			
			<view class="zhcx-table-row drop-down" @click="handle">
				<view class="name">
					<text>修改密码</text>
				</view>
				<view class="text" ></view>				
			</view>	
			<view class="zhcx-table-row" @click="logoutHandle">
				<view class="name">
					<text>退出登录</text>
				</view>
				<view class="text" ></view>
			</view>					
		</view>	
	</view>
</template>

<script>
	import {getInfo,logout} from '@/api/user';
	import {MyWebSokcet} from '@/libs/websocket';
	
	export default{
		data(){
			return{
				name:"",
				phoneNumber:"",
				idCard:"",
				gender:"",
				address:"",
				tabBars:[],
				integral:""
			}
		},
		created() {
			this.init();
		},
		methods:{
			init(){
				this.getUserInfo();	
			},
			getUserInfo(){
				let accountInfo=uni.getStorageSync("accountInfo");
				let userType=accountInfo.userType;				
				this.userType=userType;
				getInfo().then((res)=>{
					let info=res.data;
					if(userType==1){
						this.userId=info.doctorId;
						this.name=info.doctorName;
						this.gender=info.doctorSex;
						this.phoneNumber=info.accountTel;
						this.idCard=info.doctorIdCard;
						this.address=info.doctorAddress;
						this.integral=info.doctorPoints;
					}
					else if(userType==2){
						this.userId=info.patientId;
						this.name=info.patientName;
						this.gender=info.patientSex;
						this.phoneNumber=info.accountTel;
						this.idCard=info.patientIdCard;
						this.address=info.patientAddress;
						this.integral=info.patientPoints;//积分
					}
				})
			},		
			handle(){
				uni.navigateTo({
					url:'/pages/updateUserInfo/index?type=password',
					fail(res) {
						console.log(res)
					}
				})			
			},
			editHandle(){
				uni.navigateTo({
					url:'/pages/updateUserInfo/index?type=edit'
				})
			},
			logoutHandle(){
				let userType=this.userType;
				let self=this;
				uni.showModal({
					title:"温馨提示！",
					content:"是否要退出登录",
					success(res) {
						if (res.confirm) {
							logout().then(()=>{
								uni.clearStorageSync();
								if(userType==1){
									MyWebSokcet.stop();
								}
								uni.reLaunch({
									url:'/pages/login/index',
									fail(res) {
										console.log(res)
									}
								})						
							})
						}					
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		.banner{
			height: 327upx;
			background-color: var(--sysblue);
			padding-top:46upx;
			.avatar{
				width: 150upx;
				height: 150upx;
				border-radius: 50%;
				overflow: hidden;
				image{
					display: block;
					width: 150upx;
					height: 150upx;
					border-radius: 50%;
				}
				margin:0 auto;
			}
			.bottom{
				position: relative;
				.name{
					font-size: 40upx;
					text-align: center;
					color: #fff;
					padding-top: 15upx;
				}
				.edit{
					position: absolute;
					right:48upx;
					bottom: 0;
					.zhcx-iconfont{
						font-size: 50upx;
						color: #fff;						
					}
				}				
			}
		}
	}
</style>
