<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="addressitem" v-if="appPersonallist.streetName">
				<view class="" style="padding-left: 5%;">
					区域：
				</view>
				<view class="address" style="">
					{{appPersonallist.provinceName}}-{{appPersonallist.cityName}}-{{appPersonallist.regionName}}-{{appPersonallist.streetName}}
				</view>
			</view>
			<view class="addressitem" v-if="appPersonallist.regionName">
				<view class="" style="padding-left: 5%;">
					区域：
				</view>
				<view class="address" style="">
					{{appPersonallist.provinceName}}-{{appPersonallist.cityName}}-{{appPersonallist.regionName}}
				</view>
			</view>
			<view class="addressitem" v-else>
				<view class="" style="padding-left: 5%;">
					区域：
				</view>
			</view>
			<view class="addressitem" style="height:100%" v-if="appPersonallist.address">
				<view class="" style="padding-left: 5%;">
					地址：
				</view>
				<view class="address" style="">
					{{appPersonallist.address}}
				</view>
			</view>
			<view class="item" style="height:100%" v-else>
				<view class="" style="padding-left: 5%;">
					地址：
				</view>
			</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 baseurl from '@/api/baseurl.js'
	import {
		getExistPatientByPatientId
	} from '@/api/startup/index.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) {
							that.removeS();
						} else if (res.cancel) {
							that.$refs.uToast.show({
								title: '取消退出账号',
								type: 'error',
								duration: '1000'
							})
						}
					}
				});
			},
			//获取个人信息
			myInfo() {
				var that = this
				try {
					const value = uni.getStorageSync('patientId');
					if (value) {
						getExistPatientByPatientId(value).then(res => {
							if (res.code == 200 && res.msg == 'LOGIN') {
								appPersonal(value).then(response => {
									if (response.code == 200) {
										that.appPersonallist = response.data
									} else {
										that.$refs.uToast.show({
											title: '账号异常,请重新登录',
											type: 'error',
											duration: '1500'
										})
										that.removeS()
									}
								})
							} else {
								that.$refs.uToast.show({
									title: '登录异常,请重新登录',
									type: 'error',
									duration: '1500'
								})
								that.removeS()
							}
						})
					}
				} catch (e) {
					// error
				}
				// uni.getStorage({
				// 	key: 'patientId',
				// 	success: function(res) {
				// 		appPersonal(res.data).then(res => {
				// 			that.appPersonallist = res.data
				// 		})
				// 	}
				// });
			},
			removeS() {
				var that = this
				uni.removeStorageSync('patientId');
				uni.removeStorageSync('phone');
				uni.removeStorageSync('password');
				uni.removeStorageSync('token');
				if (that.timer) {
					clearTimeout(that.timer)
				}
				that.timer = setTimeout(e => {
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}, 1500)
			},
			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>
