<template>
	<view class="app">
		<view class="user">
			<view v-if="appPersonallist.headPictureUrl">
				<image class="img" :src="baseurl+appPersonallist.headPictureUrl" mode=""></image>
			</view>
			<view class="img" v-else>
				<image src="../../static/users.png" mode=""></image>
			</view>
			<view class="phone" v-if="appPersonallist.patientName!=null">
				{{appPersonallist.patientName}}
			</view>
			<view class="nickname">
				<!-- {{appPersonallist.phone}} -->
			</view>
			<view class="modify" @tap='updatainfo()'>
				修改信息
				<u-icon name="arrow-right" color="#ffffff" size="32"></u-icon>
			</view>
		</view>
		<view class="information">
			<view class="item" v-if="appPersonallist.patientName!=null">
				姓名：{{appPersonallist.patientName}}
			</view>
			<view class="item" v-else>
				姓名：
			</view>
			<view class="item" v-if="appPersonallist.phone!=null">
				电话：{{appPersonallist.phone}}
			</view>
			<view class="item" v-else>
				电话：
			</view>
			<view class="item" v-if="appPersonallist.cardNo!=null">
				身份证：{{appPersonallist.cardNo}}
			</view>
			<view class="item" v-else>
				身份证：
			</view>
			<view class="item" v-if="appPersonallist.streetName">
				区域：{{appPersonallist.regionName}}-{{appPersonallist.streetName}}
			</view>
			<view class="item" v-else>
				区域：
			</view>
			<view class="item" style="height:100%" v-if="appPersonallist.address">
				地址:
				{{appPersonallist.address}}
			</view>
			<view class="item" style="height:100%" v-else>
				地址:
			</view>
			<!-- <view class="item" style="height:100%">
				<view class="" style="display: inline-block;">
					位置:
				</view>
				<view class="address" v-if="appPersonallist.homeLatitude&&appPersonallist.homeLongitude">
					东经:{{appPersonallist.homeLongitude}}--北纬:{{ appPersonallist.homeLatitude}}
				</view>
			</view> -->
			<view class="disease" style="border:none;">
				<view class="" style="line-height: 110rpx;">
					疾病类型:
				</view>
				<span style="padding-right: 15rpx;font-size: 32rpx;"
					v-for="(item,index) in appPersonallist.patientDiseaseInfoList"
					:key="index">{{item.diseaseName}}</span>
			</view>
			<view class="signout" @tap='remove'>
				退出账号
			</view>
		</view>
		<!-- 		<view class="External" style="margin: 200rpx auto 0;">
			<view class="lefttext">
				积分:
			</view>
			<view class="righttext">
				{{appPersonallist.integral}}
			</view>
			<image src="../../static/jiantou.png" mode=""></image>
		</view>
		<view class="External">
			<view class="lefttext">
				健康档案
			</view>
			<view class="righttext">
			</view>
			<image src="../../static/jiantou.png" mode=""></image>
		</view>
		<view class="External">
			<view class="lefttext">
				我的设备
			</view>
			<view class="righttext">
			</view>
			<image src="../../static/jiantou.png" mode=""></image>
		</view> -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		appPersonal,
	} from '@/api/user/user.js';
	import {
		existPatientInfo
	} from '@/api/startup/index.js'
	import baseurl from '@/api/baseurl.js'
	export default {
		data() {
			return {
				baseurl: '',
				appPersonallist: [], //获取个人信息
				timer: null,
			}
		},
		onShow() {
			this.baseurl = baseurl
			this.myInfo()
		},
		onLoad(options) {},
		methods: {
			remove() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认要退出此账号吗',
					success: function(res) {
						if (res.confirm) {
							uni.removeStorageSync('patientId');
							uni.removeStorageSync('openid');
							uni.removeStorageSync('phone');
							uni.removeStorageSync('token');
							that.$refs.uToast.show({
								title: '退出账号成功',
								type: 'success',
								duration: '1000'
							})
							if (that.timer) {
								clearTimeout(that.timer)
							}
							that.timer = setTimeout(e => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000)
						} else if (res.cancel) {
							that.$refs.uToast.show({
								title: '退出账号失败',
								type: 'error',
								duration: '1000'
							})
						}
					}
				});
			},
			removes() {
				uni.removeStorageSync('patientId');
				uni.removeStorageSync('openid');
				uni.removeStorageSync('phone');
				uni.removeStorageSync('Refresh');
				uni.removeStorageSync('token');
				uni.navigateBack({
					delta: 1
				})
			},
			//获取个人信息
			myInfo() {
				var that = this
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					existPatientInfo(value).then(res => {
						if (res.code == 200 && res.msg == 'LOGIN') {
							appPersonal(value2).then(Response => {
								if (Response.code == 200) {
									that.appPersonallist = Response.data
								} else if (Response.code == 9999) {} else {
									that.removes();
								}
							})
						} else {
							that.removes();
						}
					})
				} else {
					that.removes();
				}
			},
			updatainfo() {
				uni.navigateTo({
					url: `/pages/modify/modify?appPersonallist=${JSON.stringify(this.appPersonallist)}`
				})
			}
		},
		onBackPress(options) {
			// if (options.from === 'navigateBack') {
			// return false;
			// }
			// this.back();
			// return true;
		},
	}
</script>
<style lang="scss">
	@import "./user.scss";
</style>
