<template>
	<view class="app">
		<view class="cards">
			<view class="item" style="background-color: #9E4DD0;" @tap='gouser'>
				<image src="../../static/user.png" mode=""></image>
				<view class="title">
					个人信息
				</view>
			</view>
			<view class=" item" style="background-color: #E1AE3C ;" @tap='goorder'>
				<image src="../../static/dingdan.png" mode=""></image>
				<view class="title">
					我的订单
				</view>
			</view>
			<!-- <view class="item" style="background-color: #00C176 ;">
				<image src="../../static/home.png" mode=""></image>
				<view class="title" style="font-size: 42rpx;">
					我的家庭
				</view>
			</view> -->
			<view class="item">
			</view>
			<view class="item">
			</view>
			<view class="item">
			</view>
			<view class="item">
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		existPatientInfo
	} from '@/api/startup/index.js'
	export default {
		data() {
			return {};
		},
		onLoad() {
			var that = this
			try {
				const value = uni.getStorageSync('openid');
				const value3 = uni.getStorageSync('token');
				if (value && value3) {
					const value2 = uni.getStorageSync('patientId');
					if (value2) {} else {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			} catch (e) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		},
		methods: {
			goorder() {
				var that = this
				try {
					const value = uni.getStorageSync('openid');
					if (value) {
						const value2 = uni.getStorageSync('patientId');
						if (value2) {
							uni.navigateTo({
								url: '/pages/order/order'
							})
						} else {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}
					} else {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				} catch (e) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			//跳转个人信息页面
			gouser() {
				try {
					const value = uni.getStorageSync('openid');
					const value3 = uni.getStorageSync('token');
					var that = this
					if (value && value3) {
						existPatientInfo(value).then(res => {
							if (res.code == 200 && res.msg == 'LOGIN') {
								const value2 = uni.getStorageSync('patientId');
								if (value2) {
									uni.navigateTo({
										url: '/pages/user/user'
									})
								} else {
									that.remove()
								}
							} else {
								that.remove()
							}
						})
					} else {
						that.remove()
					}
				} catch {
					that.remove()
				}
			},
			remove() {
				uni.removeStorageSync('patientId');
				uni.removeStorageSync('openid');
				uni.removeStorageSync('phone');
				uni.removeStorageSync('token');
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
		},
		//1.分享给朋友
		onShareAppMessage(res) {
			let pages = getCurrentPages();
			let url = pages[pages.length - 1].$page.fullPath
			return {
				title: '泉医到家',
				path: url,
			}
		},
		//2.分享到朋友圈
		onShareTimeline(res) {
			let pages = getCurrentPages();
			let url = pages[pages.length - 1].$page.fullPath
			return {
				title: '泉医到家',
				path: url,
			}
		},
	}
</script>

<style lang="scss">
	.app {
		.cards {
			padding: 22px 0 20px 0;

			.item {
				.title {
					width: 80%;
					top: 60%;
				}
			}
		}
	}
</style>
