<template>
	<view>
		<view class="navBar fixed" style="background-image: none;">
			<uni-nav-bar class="flex_start" :fixed="true" :status-bar="true" color="#000"
				background-color="rgba(0,0,0,0)">
				<view style="width:95%;text-align: center;" class="map-top-text flex_center">个人中心</view>
			</uni-nav-bar>
		</view>
		<view class="mine-top">
			<image :src="topimg" class="mine-top-img"></image>
		</view>
		<view class="mine-box">
			<view class="mine-box-user">
				<view class="user_avator">
					<u-avatar :src="info.headimgurl" size="61"></u-avatar>
				</view>
				<view class="user_info">
					<view class="user_name">
						{{info.nickname||"暂未授权"}}
					</view>
					<view class="user_phone">
						{{info.mobile||"暂未设置"}}
					</view>
				</view>
			</view>
			<view class="mine-box-nav">
				<view class="mine-box-navtitle">
					预约记录
				</view>
				<view class="mine-box-navlist">
					<view class="mine-box-navitem" @click="toPage(1)">
						<image src="../../static/img/icon_visit.png" class="mine-box-navitemimg"
							style="width: 60rpx;height: 54rpx;"></image>
						<text class="mine-box-navitemtxt">参观预约</text>
					</view>
					<view class="mine-box-navitem" @click="toPage(2)">
						<image src="../../static/img/icon_activity.png" class="mine-box-navitemimg"
							style="width: 51rpx;height: 56rpx;"></image>
						<text class="mine-box-navitemtxt">活动预约</text>
					</view>
					<view class="mine-box-navitem" @click="toPage(3)">
						<image src="../../static/img/icon_park.png" style="width: 51rpx;height: 52rpx;"
							class="mine-box-navitemimg"></image>
						<text class="mine-box-navitemtxt">停车场预约</text>
					</view>
				</view>
			</view>
			<view class="mine-box-list">
				<view class="list-item" style="position: relative;">
					<button open-type="feedback" class="hideBtn"
						style="width: 100%;height: 100%;top:0rpx;left: 0rpx;"></button>
					<view class="list-item-left">
						<text class="iconfont icon-yijianfankui"></text>
						<text class="list-item-lefttxt">意见反馈</text>
					</view>
					<view class="list-item-right">
						<u-icon name="arrow-right" color="#ccc"></u-icon>
					</view>
				</view>
				<view class="list-item" @click="toPage(4)">
					<view class="list-item-left">
						<text class="iconfont icon-fenxiang"></text>
						<text class="list-item-lefttxt">推荐预约管理系统</text>
					</view>
					<view class="list-item-right">
						<u-icon name="arrow-right" color="#ccc"></u-icon>
					</view>
				</view>
			</view>
		</view>

		<u-popup :show="showAuthorization" mode="bottom" @close="closeInfo" :round="10">
			<view class="box">
				<view class="box-title" style="text-align: center;padding: 20rpx 0;font-size: 32rpx;">
					请授权您的微信头像和昵称
				</view>
				<view class="box-content" style="padding: 20px;">
					<u-button type="primary" @click="getUserProfile">微信用户一键登录</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topimg: "",
				info: {},
				showAuthorization: false
			}
		},
		onReady() {
			this.topimg = this.util.HOST + "/top_bg.png";
		},
		onShow() {

			var that = this;
			this.loadInfo(function(res) {
				if (that.util.isNull(res.headimgurl) || that.util.isNull(res.nickname)) {
					that.showAuthorization = true;
				} else {
					that.showAuthorization = false;
				}
			});
		},
		methods: {
			closeInfo() {
				that.showAuthorization = false;
			},
			loadInfo(cb) {
				var that = this;
				this.util.getOpenidInfo(function(res) {
					that.util.getUserInfo(function(r) {
						that.info = r;
						cb(r);
					}, true)
				}, true);

			},
			getUserProfile() {
				var that = this;
				this.util.getUserProfile((res) => {
					console.log(res)
					that.util.request({
						api: '/api/mobile/user/save',
						method: 'POST',
						data: {
							headimgurl: res.avatarUrl,
							nickname: res.nickName
						},
						utilSuccess: function(r) {
							that.loadInfo(function() {
								that.showAuthorization = false;

							})
						}

					})
				})
			},
			toPage(type) {
				var url = "";
				switch (type) {
					case 1:
						url = "../order/visitorder"
						break;
					case 2:
						url = "../order/activityorder"
						break;
					case 3:
						url = "../order/parkorder"
						break;
					case 4:
						url = "recommend"
						break;
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.uni-navbar--border {
		border-bottom-width: 0 !important;
	}

	page {
		background: #d8ac75;
	}

	.mine-box-user {
		margin-bottom: 65rpx;
	}

	.mine-top-img {
		width: 100%;
	}

	.map-top-text {
		width: 124px;
		font-family: PingFangSC-Medium;
		font-size: 32rpx;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;

	}

	.mine-box {
		width: 100%;
		border-top-left-radius: 30rpx;
		border-top-right-radius: 30rpx;
		background-color: #fff;
		position: relative;
		z-index: 1024;
		padding: 55rpx 25rpx;
		box-sizing: border-box;
		margin-top: -288rpx;
		height: calc(100vh);
	}

	.mine-box-nav {
		background: url("../../static/img/nav_bg.png") no-repeat;
		background-size: cover;
		width: 100%;
		height: 273rpx;
	}

	.mine-box-user {
		display: flex;
		align-items: center;

	}

	.user_info {
		margin-left: 33rpx;
	}

	.user_name {
		font-size: 32rpx;
		font-family: PingFang SC;
		color: #4E4E4E;
	}

	.user_phone {
		font-size: 24rpx;
		color: #828282;
		line-height: 40rpx;
	}

	.mine-box-nav {
		padding: 39rpx;
		box-sizing: border-box;
	}

	.mine-box-navtitle {
		font-size: 32rpx;
		font-family: PingFang SC;
		color: #4E4E4E;
	}

	.hideBtn {
		width: 170rpx;
		height: 170rpx;
		opacity: 0;
		border-radius: 50%;
		position: absolute;
		top: 30rpx;
		left: 30rpx;
		z-index: 9999;
	}

	.mine-box-navlist {
		display: flex;
		justify-content: space-around;
		margin-top: 40rpx;
	}

	.mine-box-navitem {
		display: flex;
		flex-direction: column;
		justify-content: center;
		text-align: center;
		align-items: center;
	}

	.mine-box-navitemtxt {
		font-size: 24rpx;
		font-family: PingFang SC;
		color: #4E4E4E;
		margin-top: 30rpx;
	}

	.mine-box-list {
		display: flex;
		margin-top: 27rpx;
		font-size: 32rpx;
		color: #4E4E4E;
		flex-direction: column;
	}

	.list-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding-top: 32rpx;
		padding-bottom: 32rpx;
		border-bottom: 2rpx solid #F7F6F4;
	}

	.list-item-lefttxt {
		margin-left: 41rpx;
	}
</style>
