<template>
	<view class="page-container">
		<view class="my-top">
			<view class="icon-container">
				<u-image :src="userPicPath" width="46rpx" height="52rpx"></u-image>
			</view>
			<!-- <text class="my-top-text">尊敬的{{userInfo.name[0]+"**"}}</text> -->
			<u-text size="20" :text="userInfo.name" mode="name" format="encrypt" color="#FFFFFF"></u-text>
		</view>
		<view class="my-middle" v-for="area in list">
			<view class="info-item" v-for="item in area" @click="navigateTo(item.url)">
				<view class="info-item-left">
					<view class="left-img">
						<u-image :src="item.src" width="45rpx" height="45rpx" mode="aspectFit"></u-image>
					</view>
					<view class="tip">
						<text class="">{{item.text}}</text>
					</view>
				</view>
				<view class="info-item-right">
					<u-image :src="arrowPicPath" width="12rpx" height="20rpx"></u-image>
				</view>
			</view>
		</view>
		<view class="my-middle" v-if="userInfo.selectHotel">
			<view class="info-item" v-for="item in listDebug" @click="navigateTo(item.url)">
				<view class="info-item-left">
					<view class="left-img">
						<u-image :src="item.src" width="45rpx" height="45rpx" mode="aspectFit"></u-image>
					</view>
					<view class="tip">
						<text class="">{{item.text}}</text>
					</view>
				</view>
				<view class="info-item-right">
					<u-image :src="arrowPicPath" width="12rpx" height="20rpx"></u-image>
				</view>
			</view>
		</view>
		<view class="my-bottom">
			<u-button class="my-bottom-btn" text="退出登录" size="large" @click="logout"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				userPicPath: '/static/user.png',
				arrowPicPath: '/static/arrow.png',
				list: [
					[{
						src: "/static/user_info.png",
						text: "实名认证",
						url: '/subpkg/myAccount/myAccount'
					}, {
						src: "/static/my_order.png",
						text: "我的订单",
						url: '/pages/order/order'
					}],
					[{
						src: "/static/receipt.png",
						text: "预约开票",
						url: ''
					}, {
						src: "/static/front_desk.png",
						text: "联系前台",
						url: ''
					}]
				]
			};
		},
		computed: {
			...mapState('m_user', ['userInfo', 'token']),
			listDebug() {
				return [{
					src: "/static/change_hotel.png",
					text: "选择酒店",
					url: '/subpkg/changeHotel/changeHotel'
				}]
			}
		},
		methods: {
			...mapMutations('m_user', ['updateUserInfo', 'updateToken']),
			navigateTo(url) {
				if (url !== '' && url !== null && url !== undefined) {
					if (url === '/pages/order/order') {
						uni.switchTab({
							url: url
						})
					} else {
						uni.navigateTo({
							url: url
						})
					}
				} else {
					uni.$showMsg('功能开发中，敬请期待')
				}
			},
			async logout() {
				console.log(this.token)
				let res = await uni.$http.post('/logout')
				console.log(res)
				uni.navigateTo({
					url: '/pages/login/login'
				})
				this.updateUserInfo({})
				this.updateToken('')
			}
		},
		onLoad() {
			if (!this.token) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
		}
	}
</script>

<style lang="scss">
	.page-container {
		background-color: #F0EFF5;
		height: 1110rpx;

		.my-top {
			height: 200rpx;
			background-color: #7096F6;
			display: flex;
			align-items: center;

			.icon-container {
				width: 100rpx;
				height: 100rpx;
				margin: 40rpx 50rpx;
				background-color: white;
				border-radius: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.text-container {
				display: flex;
				justify-content: start;
			}

			.my-top-text {
				color: white;
			}
		}

		.my-middle {
			margin-top: 40rpx;
			background-color: white;

			.info-item {
				display: flex;
				justify-content: space-between;
				height: 120rpx;
				line-height: 160rpx;
				border-bottom: 1px solid #F0EFF5;
				margin: 0 40rpx;

				.info-item-left {
					display: flex;
					align-items: center;

					.left-img {
						padding-right: 20rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}

				.info-item-right {
					display: flex;
					align-items: center;
					color: #AFB2BA;
				}
			}
		}

		.my-bottom {
			bottom: 80rpx;
			left: 80rpx;
			right: 80rpx;
			position: fixed;
		}
	}

	.u-button__text {
		color: #789EF6;
	}
</style>