<template>
	<view class="my">

		<view class="top-box">

			<view class="user-info">
				<image class="image" :src="userInfo.imgPath || defaultImg" lazy-load mode=""></image>
				<view class="info">
					<view class="user-name">{{userInfo.nickname ||'用户'}}</view>
					<view class="tel">{{userInfo.phoneNum ||'-'}}</view>
				</view>
				<image class="setting" src="../../static/setting.png" @click="setting" mode=""></image>
			</view>
			<view class="level-box">
				<view class="level-content">
					<image class="level" :src="`../../static/level${userInfo.setMealId || 0}.png`" mode=""></image>
					<view class="num" :style="{color:filterMeal(userInfo.setMealId)}">
						已为您节省0元
					</view>
				</view>
			</view>
		</view>
		<view class="btn-group">
			<view class="item" @click="jump('../../my/order/index')">

				<image class="icon" src="../../static/icon1.png" mode=""></image>
				<view class="label">
					全部订单
				</view>
			</view>
			<view class="item" @click="jump('../../my/order/index?type=WAIT_PAYMENT')">
				<image class="icon" src="../../static/icon2.png" mode=""></image>
				<view class="label">
					待付款
				</view>
			</view>
			<view class="item" @click="jump('../../my/order/index?type=WAIT_USE')">
				<image class="icon" src="../../static/icon3.png" mode=""></image>
				<view class="label">
					待使用
				</view>
			</view>
			<view class="item" @click="jump('../../my/order/index?type=APPLY_REFUND')">
				<image class="icon" src="../../static/icon4.png" mode=""></image>
				<view class="label">
					退款
				</view>
			</view>
		</view>

		<view class="type-box">
			<view class="type-item"  @click="jump('../../my/memberCenter/index')">
				<view class="left">
					<view class="title">
						会员中心
					</view>
					<view class="desc">
						会员享受更多优惠
					</view>
				</view>
				<image class="icon" src="../../static/type-icon1.png" mode=""></image>
			</view>
			<view class="type-item" @click="jump('/invite/index')">
				<view class="left">
					<view class="title">
						推广邀请
					</view>
					<view class="desc">
						百万佣金发放中
					</view>
				</view>
				<image class="icon" src="../../static/type-icon2.png" mode=""></image>
			</view>
		</view>

		<u-cell-group :border="false">
			<!-- <u-cell title="优惠券" @click="jump('../../my/coupon/index')" :border="false" :isLink="true" arrow-direction="right">
				<image slot="icon" class="cell-icon" src="../../static/icon7.png" mode=""></image>
			</u-cell> -->
			<u-cell title="研学MBTI测试"  @click="jump('../../study/test')" :border="false" :isLink="true" arrow-direction="right">
				<image slot="icon" class="cell-icon" src="../../static/icon8.png" mode=""></image>
			</u-cell>
		</u-cell-group>



	</view>
</template>

<script>
	import {
		getUserDetail
	} from '@/api/common.js'
	export default {
		data() {
			return {
				active: 1,
				keyword: '',
				userId: '',
				loading: false,
				status: 'more',
				defaultImg: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2Fc34b7b74-ba38-0456-982a-43c0f97522fe%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1693532127&t=a2e186c12aecaab7723611cb52a6778f',
				userInfo: {
					imgPath: null,
					lastLogin: "",
					level: null,
					nickname: null,
					openId: "",
					phoneNum: "",
					sex: 0,
					userId: "",
					valid: 0
				},

			}
		},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.getUserDetail()
			}else{
				this.userInfo = {
					imgPath: null,
					lastLogin: "",
					level: null,
					nickname: null,
					openId: "",
					phoneNum: "",
					sex: 0,
					userId: "",
					valid: 0
				},
				uni.showModal({
					title:'请登录',
					confirmText:'去登录',
					success(res){
						console.log(res);
						if(res.confirm){
							uni.navigateTo({
								url:'../../login/login/login'
							})
						}
					}
				})
			}

		},
		onLoad() {

		},
		
		methods: {
			filterMeal(val) {
				if(val == 1){
					return '#3E5C91'
				}else if(val == 2){
					return '#FF532A'
				}else if(val == 3){
					return '#F3CC90'
				}
			},
			// 点击设置
			setting() {
				if (uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '../../my/edit/edit'
					})
				} else {
					uni.showModal({
						title:'请登录',
						confirmText:'去登录',
						success(res){
							console.log(res);
							if(res.confirm){
								uni.navigateTo({
									url:'../../login/login/login?redirect=/pages/my/index'
								})
							}
						}
					})
				}
			},

			jump(url) {
				if(!uni.getStorageSync('token')){
					return uni.showModal({
						title:'请登录',
						confirmText:'去登录',
						success(res){
							console.log(res);
							if(res.confirm){
								uni.navigateTo({
									url:'../../login/login/login?redirect=/pages/my/index'
								})
							}
						}
					})
				}
				uni.navigateTo({
					url
				})
			},

			// 获取用户详情
			getUserDetail() {
				getUserDetail().then(res => {
					if(res.state == 'Success'){
						this.userInfo = res.content
						uni.setStorageSync('userInfo', JSON.stringify(this.userInfo))
					}
				})
			},
			
		}
	}
</script>

<style lang="scss">
	.my {
		height: 100vh;
		padding: 0 30rpx;
		background: #F9F9F9;

		.top-box {
			width: 750rpx;
			height: 460rpx;
			margin-left: -30rpx;
			padding: 150rpx 30rpx 0;
			box-sizing: border-box;
			background: url('../../static/top-bg.png') no-repeat;
			background-size: 100% 500rpx;
			position: relative;

			.user-info {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 15rpx 0;
				color: #222222;

				.image {
					width: 108rpx;
					height: 108rpx;
					background: #f1f1f1;
					border-radius: 50%;
				}

				.info {
					flex: 1;
					margin-left: 30rpx;

					.user-name {
						font-size: 32rpx;
						font-weight: bold;
					}

					.tel {
						font-size: 24rpx;
						margin-top: 10rpx;
					}
				}

				.setting {
					width: 60rpx;
					height: 60rpx;
				}
			}

			.level-box {
				position: absolute;
				left: 0;
				bottom: 0;
				padding: 0 35rpx 22rpx;
				width: 750rpx;
				box-sizing: border-box;
				
				.level-content {
					width: 686rpx;
					height: 100rpx;
					position: absolute;
					bottom: 0rpx;
					left: 50%;
					transform: translateX(-50%);

					.level {
						width: 100%;
						height: 100%;
					}

					.num {
						font-size: 28rpx;
						color: #F3CC90;
						position: absolute;
						right: 25rpx;
						top: 50%;
						transform: translateY(-50%);
					}
				}
			}

		}

		.btn-group {
			display: flex;
			align-items: center;
			padding: 30rpx 20rpx;
			margin-top: 20rpx;
			border-radius: 16rpx;
			background: #fff;
			width: 690rpx;
			box-sizing: border-box;

			.item {
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;

				.icon {
					width: 100rpx;
					height: 100rpx;
				}

				.label {
					font-size: 24rpx;
					color: #121212;
				}
			}
		}

		.type-box {
			display: flex;
			justify-content: space-between;

			.type-item {
				width: 335rpx;
				border-radius: 16rpx;
				background: #FFFFFF;
				padding: 32rpx 24rpx;
				margin-top: 20rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					.title {
						font-weight: bold;
						color: #181818;
						font-size: 32rpx;
					}

					.desc {
						color: #AAAAAA;
						font-size: 24rpx;
						margin-top: 16rpx;
					}
				}

				.icon {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}

		.cell-icon {
			width: 48rpx;
			height: 48rpx;
		}

		.u-cell-group {
			margin-top: 20rpx;
			background: #fff;
		}
	}
</style>