<template>
	<view class="container">
		<!-- 页面标题 -->
		<view class="title" :style="{ height: customBarH * 2 + 'rpx', top: statusBarH * 2 + 'rpx' }" v-if="!headerType">我的</view>

		<view class="title" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx', backgroundColor: '#fff', color: '#000' }" v-else>我的</view>

		<!-- 顶部用户信息区域 -->
		<view class="header">
			<img src="https://chtech.ncjti.edu.cn/hotelReservation/image/18.png" />
			<!-- 头像区域 -->
			<img class="img" mode="aspectFill" v-if="flag" :src="userInfo.headPhoto" @click="handleGoPageHome" />
			<img class="img" v-else src="../../static/my/portrait.png" @click="handleGoPageHome" />
			<!-- 姓名区域 -->
			<view class="name" v-if="flag" @click="handleGoPageHome">{{ userInfo.user_name }}</view>
			<!-- 用户id区域 -->
			<view class="number" v-if="flag" @click="handleGoPageHome">ID：{{ userInfo.id }}</view>
			<!-- 是否实名认证区域 -->
			<!-- <view class="real" v-if="userInfo.card_number">
				<img src="../../static/my/true.png" />
				已实名认证
			</view>
			<view class="real2" v-if="flag" v-else>
				去认证
				<img src="../../static/my/right2.png" />
			</view> -->

			<view class="login" v-if="!flag" @click="goPageLogin">去登录</view>
		</view>

		<!-- 内容区域 -->
		<view class="body">
			<!-- 订单管理区域 -->
			<view class="body_item" @click="handleGoPage('/pages/orderManage/orderManage')">
				<img class="img" src="../../static/my/order.png" />
				订单管理
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>

			<!-- 我的评价区域 -->
			<view class="body_item" @click="handleGoPage('/pages/myEvaluate/myEvaluate')">
				<img class="img" src="../../static/my/evaluate.png" />
				我的评价
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>

			<!-- 收藏/住过区域 -->
			<view class="body_item" @click="handleGoPage('/pages/collect/collect')">
				<img class="img" src="../../static/my/collect.png" />
				收藏/住过
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>

			<!-- 我的卡券区域 -->
			<view class="body_item" @click="handleGoPage('/pages/myCoupon/myCoupon')">
				<img class="img" src="../../static/my/coupon.png" />
				我的卡券
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>

			<!-- 投诉进度区域 -->
			<view class="body_item" @click="handleGoPage('/pages/myComplaint/myComplaint')">
				<img class="img" src="../../static/my/complaint.png" />
				投诉进度
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>

			<!-- 常用旅客区域 -->
			<view class="body_item" @click="handleGoPage('/pages/common/common')">
				<img class="img2" src="../../static/my/people.png" />
				常用旅客
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>

			<!-- 设置区域 -->
			<view class="body_item" @click="handleGoPage('/pages/set/set')">
				<img class="img3" src="../../static/my/set.png" />
				设置
				<img class="img_icon" src="../../static/my/right3.png" />
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 是否登录标识
			flag: false,
			// 用户信息
			userInfo: {},
			// 状态栏高度
			statusBarH: 0,
			// 胶囊按钮栏高度
			customBarH: 0,
			// 顶部页面标题栏显示隐藏控制
			headerType: false
		}
	},
	created() {
		// 获取系统信息
		uni.getSystemInfo({
			success: (e) => {
				// 获取状态栏高度
				this.statusBarH = e.statusBarHeight + 10
				// // 获取菜单按钮栏高度
				let custom = uni.getMenuButtonBoundingClientRect()
				this.customBarH = custom.height + 10
			}
		})
	},
	onPageScroll(e) {
		if (e.scrollTop > 50) {
			this.headerType = true
		} else {
			this.headerType = false
		}
	},
	onLoad() {
		uni.$on('changeFlag', this.changeFlag)
	},
	onShow() {
		let openid = uni.getStorageSync('openid')
		if (openid) {
			this.flag = true
			this.userInfo = uni.getStorageSync('userInfo')
		} else {
			this.flag = false
		}
	},
	methods: {
		// 跳转页面回调
		handleGoPage(url) {
			if (this.isLogin()) {
				uni.navigateTo({
					url
				})
			}
		},
		changeFlag(e) {
			// console.log(e)
			this.flag = e.data
			this.userInfo = uni.getStorageSync('userInfo')
		},
		// 去登录文字回调
		goPageLogin() {
			uni.navigateTo({
				url: '/pages/login/login'
			})
		},
		isLogin() {
			if (this.flag) {
				return true
			} else {
				uni.showToast({
					title: '请先登录',
					icon: 'none',
					mask: true
				})
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}, 1500)
			}
		},
		handleGoPageHome() {
			let userId = uni.getStorageSync('userInfo').id
			uni.navigateTo({
				url: `/pages/myHome/myHome?userId=${userId}`
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	position: relative;
	min-height: 100vh;

	.title {
		z-index: 999;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		font-size: 28rpx;
		color: #fff;
		text-align: center;
	}

	.header {
		position: relative;
		height: 480rpx;
		color: #fff;
		overflow: hidden;

		img {
			width: 100%;
		}

		.img {
			position: absolute;
			top: 190rpx;
			left: 32rpx;
			width: 140rpx;
			height: 140rpx;
			border-radius: 50%;
		}

		.name {
			position: absolute;
			top: 200rpx;
			left: 202rpx;
			font-size: 40rpx;
			font-weight: bold;
		}

		.number {
			position: absolute;
			top: 265rpx;
			left: 202rpx;
			font-size: 24rpx;
			opacity: 0.5;
		}

		.real {
			position: absolute;
			top: 285rpx;
			left: 202rpx;
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding-left: 13rpx;
			width: 179rpx;
			height: 42rpx;
			font-size: 24rpx;
			border-radius: 113rpx;
			background-color: rgba(255, 255, 255, 0.2);

			img {
				margin-right: 7rpx;
				width: 24rpx;
				height: 24rpx;
			}
		}

		.real2 {
			position: absolute;
			top: 285rpx;
			left: 202rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			box-sizing: border-box;
			padding-left: 13rpx;
			padding-bottom: 5rpx;
			width: 179rpx;
			height: 42rpx;
			font-size: 24rpx;
			border-radius: 113rpx;
			background-color: rgba(255, 255, 255, 0.2);

			img {
				margin-left: 12rpx;
				width: 24rpx;
				height: 24rpx;
			}
		}

		.login {
			position: absolute;
			top: 235rpx;
			left: 202rpx;
			font-size: 40rpx;
			font-weight: bold;
		}
	}

	.body {
		position: absolute;
		top: 360rpx;
		box-sizing: border-box;
		padding: 0 30rpx;
		width: 100%;
		min-height: calc(100vh - 360rpx);
		border-radius: 20rpx 20rpx 0 0;
		background-color: #fff;

		.body_item {
			display: flex;
			align-items: center;
			height: 121rpx;
			font-size: 28rpx;
			border-bottom: 1rpx solid #e6e6e6;

			.img {
				margin-right: 17rpx;
				width: 53rpx;
				height: 53rpx;
			}

			.img2 {
				margin-right: 22rpx;
				width: 42rpx;
				height: 42rpx;
			}

			.img3 {
				margin-right: 18rpx;
				width: 50rpx;
				height: 50rpx;
			}

			.img_icon {
				margin-left: auto;
				width: 49rpx;
				height: 49rpx;
			}
		}
	}
}
</style>
