<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" :style="{color:filterMeal(userInfo.setMealCode).color,backgroundColor:filterMeal(userInfo.setMealCode).bgColor}">{{filterMeal(userInfo.setMealCode).setMealName ||'开通会员'}}</view>
				</view>
				<image class="setting" src="../../static/edit-icon.png" @click="setting" mode=""></image>
			</view>
			<view class="level-box"  @click="jump('../../my/memberCenter/index')">
				<view class="level-content">
					<image class="level" :src="`../../static/level${levelImgNameObj[userInfo.setMealCode]|| 0}.png`" mode=""></image>
				<!-- 	<view class="num" v-if="userInfo.setMealCode&&(userInfo.setMealCode!=0)" :style="{color:filterMeal(userInfo.setMealCode).bgColor}">
						已为您节省99元
					</view> -->
				</view>
			</view>
		</view>
		<view class="box">
			<view class="box-title">
				我的订单
			</view>
			<view class="btn-group">
				<view class="item" @click="jump('../../my/order/index')">

					<image class="icon" src="../../static/my/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/my/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/my/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/my/icon4.png" mode=""></image>
					<view class="label">
						退款
					</view>
				</view>
			</view>
		</view>
		
		
		<view class="type-box">
			<view class="type-item"  @click="jump('/my/coupon/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 title="设置"  @click="jump('../../my/edit/edit')" :border="false" :isLink="true" arrow-direction="right">
				<image slot="icon" class="cell-icon" src="../../static/setting-icon.png" mode=""></image>
			</u-cell>
			<u-cell title="客服"  @click="jump('../../my/service/index')" :border="false" :isLink="true" arrow-direction="right">
				<image slot="icon" class="cell-icon" src="../../static/service-icon.png" mode=""></image>
			</u-cell>
	<!-- 		<u-cell title="订阅"  @click="Subscribe" :border="false" :isLink="true" arrow-direction="right">
				<image slot="icon" class="cell-icon" src="../../static/service-icon.png" mode=""></image>
			</u-cell> -->
		</u-cell-group>



	</view>
</template>

<script>
	import {
		getUserDetail
	} from '@/api/common.js'
	import {mealList} from '@/api/combo.js'
	import {levelImgName} from '@/utils/config.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,
					setMealCode:0
				},
				levelImgNameObj:levelImgName,
				list:[],//套餐列表
			}
		},
		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){
						if(res.confirm){
							uni.navigateTo({
								url:'../../login/login/login?redirect=/pages/my/index'
							})
						}
					}
				})
			}

		},
		onLoad() {
			this.mealList()
			
		},
		
		methods: {
			Subscribe(){
				wx.requestSubscribeMessage({
				  tmplIds: ['2MWtGXO1dOgEieVbIoBicAdLUj945Nv__4K2vh-Pk9Q'],
				  success (res) { 
					  console.log(res);
					  uni.showToast({
					  	title:'订阅成功'
					  })
				  },
				  fail(){
					  uni.showToast({
					  	title:'订阅失败'
					  })
				  }
				})
			},
			
			
			filterMeal(val) {
				let color
				let bgColor
				let setMealName
				this.list.filter(item=>{
					if(item.setMealCode == val){
						color = item.colour
						bgColor = item.backColour
						setMealName = item.setMealName
					}
				})
				return {
					color,bgColor,setMealName
				}
			},
			// 点击设置
			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))
					}
				})
			},
			// 获取套餐列表
			mealList(){
				mealList({currentPage:1,pageSize:99,status:1}).then(res=>{
					if (res.state == 'Success') {
						this.list = res.content.records
					}
				})
			},
			
		}
	}
</script>

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

		.top-box {
			width: 750rpx;
			height: 460rpx;
			margin-left: -24rpx;
			padding: 150rpx 30rpx 0;
			box-sizing: border-box;
			background: url('https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/CXvU8kSyyCxUe83c049e4ddb2b66e0c80f6cb5c6b4b1.png/1.png') no-repeat;
			background-size: 100% 460rpx;
			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: 20rpx;
						margin-top: 10rpx;
						display: inline-block;
						padding: 0 12rpx;
						line-height: 36rpx;
						border-radius: 18rpx 18rpx 18rpx 18rpx;
						box-sizing: border-box;
						background: #423625;
						color: #F3CC90;
					}
				}

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

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

					.level {
						width: 702rpx;
						height: 134rpx;
					}

					.num {
						font-size: 28rpx;
						color: #F3CC90;
						position: absolute;
						right: 25rpx;
						top: 30rpx;
					}
				}
			}

		}
		
		.box{
			background: #fff;
			padding-top: 10rpx;
			.box-title{
				font-size: 32rpx;
				font-weight: bold;
				color: #222222;
				padding-top: 20rpx;
				margin-left: 24rpx;
			}
			.btn-group {
				display: flex;
				align-items: center;
				padding: 30rpx 20rpx;
				// margin-top: 20rpx;
				border-radius: 0 0 16rpx 16rpx;
				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+.type-item{
				background: linear-gradient( 91deg, rgba(132,176,255,0.2) 0%, #FFFFFF 100%);
			}
			.type-item {
				width: 335rpx;
				border-radius: 16rpx;
				background: linear-gradient( 91deg, rgba(254,198,92,0.3) 0%, #FFFFFF 100%);
				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>