<template>
	<view>
		<!-- 非H5撑高元素 -->
		<!-- <view class="status_bar"></view> -->
		<!-- 头部背景 -->
		<view class="user"></view>
		<!-- 账户信息 -->
		<view class="account">
			<view class="flex account-ava">
				<image :src="avatar" mode="aspectFill" v-if="loginState"></image>
				<view class="no-ava" v-else @click="toLogin"></view>
				<view class="account-ava-name" v-if="loginState">{{ userInfo.nickName }}</view>
				<view class="account-ava-no" @click="toLogin" v-else>登录</view>
			</view>
			<view class="flex account-info" v-if="loginState">
				<navigator url="/packagePrize/prize/index" class="flex account-info-item" hover-class="navigator-hover">
					<view>{{ initData.prizeNum }}</view>
					<view>我的奖品库</view>
				</navigator>
				<navigator url="/packagePrize/ticket/index" class="flex account-info-item" hover-class="navigator-hover">
					<view>{{ initData.ticketNum }}</view>
					<view>我的盲票</view>
				</navigator>
				<navigator url="/packagePrize/bean/index" class="flex account-info-item" hover-class="navigator-hover">
					<view>{{ initData.coinNum }}</view>
					<view>我的盲豆</view>
				</navigator>
			</view>
			<view class="flex account-info" v-else @click="notLogin">
				<view class="flex account-info-item">
					<view>-</view>
					<view>我的奖品库</view>
				</view>
				<view class="flex account-info-item">
					<view>-</view>
					<view>我的盲票</view>
				</view>
				<view class="flex account-info-item">
					<view>-</view>
					<view>我的盲豆</view>
				</view>
			</view>
		</view>
		<!-- 操作项 -->
		<view class="action">
			<u-cell-group :border="false">
				<u-cell icon="order" title="我的订单" :isLink="true" @click="toOrder" />
				<u-cell icon="map" title="我的地址" :isLink="true" @click="toAddress" />
				<u-cell icon="kefu-ermai" title="联系我们" :isLink="true" @click="contactService" />
				<u-cell icon="info-circle" title="关于我们" :border="false" :isLink="true" :url="'/packageOther/about/index'" />
				<u-cell icon="info-circle" title="奖品滚动" :border="false" :isLink="true" :url="'/packagePrize/rolling/index'" />
			</u-cell-group>
		</view>
		<view class="cancel">
			<u-cell icon="close-circle" title="退出登录" :isLink="true" :border="false" @click="logout" />
		</view>
		<custom-tab-bar :activeValue="'user'" />
	</view>
</template>

<script>
	import env from '../../config/env.js'
	import $http from '@/utils/request.js'
	import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
	import Auth from '../../components/auth/auth.vue'
	export default {
		components: {
			CustomTabBar,
			Auth,
		},
		data() {
			return {
				loginState: false, // 判断是否登录
				authState: false,
				userInfo: {}, //
				avatar: '',
				certifyStatus: {},
				info: {},
				authShow: false,
				initData: {},
			};
		},

		onShow() {
			this.loginState = uni.getStorageSync('token') ? true : false
			if (this.loginState) {
				this.getInit()
				this.getBaseInfo()
			}
		},

		methods: {
			// 我的数据
			getInit() {
				uni.showLoading({
					title: '加载中'
				});
				$http.post('/api/v1/mp/user/mine/init', {}).then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						this.initData = res.data
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},

			getBaseInfo() {
				$http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
					if (res.code == 0) {
						this.userInfo = res.data
						this.avatar = env.filePublic + res.data.avatar
					}
				}).catch(() => {

				})
			},

			// 跳转登录
			toLogin() {
				uni.navigateTo({
					url: "/pages/login/index"
				})
			},

			// 我的订单
			toOrder() {
				if (!this.loginState) {
					uni.$u.toast('请登录！');
					return
				}
				uni.navigateTo({
					url: '/packageGoods/order/index'
				})
			},

			// 我的地址
			toAddress() {
				if (!this.loginState) {
					uni.$u.toast('请登录！');
					return
				}
				uni.navigateTo({
					url: '/packageOperate/address/index'
				})
			},

			// 没有登录
			notLogin() {
				uni.$u.toast('请登录！');
			},

			// 注销登录
			logout() {
				let _this = this
				if (!this.loginState) {
					uni.$u.toast('已退出登录！');
					return
				}
				uni.showModal({
					title: '退出登录',
					content: '确定要退出登录吗？',
					success(res) {
						if (res.confirm) {
							uni.clearStorage()
							_this.loginState = false
							_this.authState = false
						}
					}
				})
			},

			// 联系客服
			contactService() {
				// #ifdef MP-WEIXIN
				wx.openCustomerServiceChat({
					extInfo: {
						url: 'https://work.weixin.qq.com/kfid/kfc36c0d90028adbd24'
					},
					corpId: 'ww02da63d80c66284b',
				})
				// #endif
			},
		},
		onShareAppMessage(res) {
			return {
				title: '盲票，玩的就是有趣',
				path: '/pages/index/index'
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/ .u-cell__body {
		padding: 20rpx 0;
	}

	.status_bar {
		width: 100%;
		height: var(--status-bar-height);
	}
</style>

<style lang="scss" scoped>
	.user {
		display: flex;
		align-items: center;
		height: 300rpx;
		padding: 0 36rpx;
		// background: linear-gradient(to right, #a1c4fd 0%, #c2e9fb 100%);
		background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/my-bkgd.png) center center;
	}

	.account {
		margin: 0 20rpx;
		padding: 34rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin-top: -90rpx;
		margin-bottom: 40rpx;

		&-ava {
			justify-content: flex-start;
			margin-bottom: 46rpx;

			image {
				width: 106rpx;
				height: 106rpx;
				border-radius: 50%;
				overflow: hidden;
			}

			.no-ava {
				width: 106rpx;
				height: 106rpx;
				border-radius: 50%;
				overflow: hidden;
				background: #C0C0C0;
			}

			&-name {
				margin-left: 20rpx;
				font-size: 32rpx;
			}

			&-no {
				margin-left: 20rpx;
				color: #C0C0C0;
				font-size: 32rpx;
			}
		}

		&-info {
			justify-content: space-around;

			&-item {
				flex-direction: column;

				view {
					line-height: 40rpx;
				}

				view:first-child {
					line-height: 56rpx;
					font-size: 40rpx;
				}
			}
		}
	}

	.action {
		margin: 0 20rpx;
		padding: 10rpx 20rpx 0;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin-bottom: 40rpx;
	}

	.cancel {
		margin: 0 20rpx;
		padding: 10rpx 20rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
	}
</style>
