<template>
	<view :style="{'height':contentHeight}" class="levelStyle">
		<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/no-level-bg.png" v-if="level=='' " style="width: 100%;height: 100%;"></image>
		<view  class="imgbg">
			<Text class='leveltop'>满足以下条件即可升级</Text>
			<view class='levelc'>
				<Text>{{level.GradeInfo.UpGradeConditionName?level.GradeInfo.UpGradeConditionName:''}}{{level.GradeInfo.ReferralsNumber?level.GradeInfo.ReferralsNumber:0}}人</Text>
				<view style="display: flex;flex-direction: row;align-items: center;" @click="show=true">
					<Text style='font-size: 14px;color:#c8c9cc ;'>等级说明</Text>
					<u-icon name="arrow" color='#c8c9cc'></u-icon>
				</view>
			</view>
			<view class="level_b" @click="Upgrade">
				<Text>立即升级</Text>
			</view>
		</view>
	
		<u-popup v-model="show"
				mode="center"
				length="80%"
				
		>
				<view class="popup">
					<view class="popup_t">
						<Text>等级说明</Text>
					</view>
					<view class="popup_c">
						<Text>{{level.GradeInfo.GradeExplain}}</Text>
					</view>
					<view class="popup_t" style="border-top: 1px solid #f5f5f5;" @click="show=false">
						<Text>我知道了</Text>
					</view>
				</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "升级条件",
				contentHeight:0,
				show:false,
				mainColor:'',
				secondary:'',
				level:'',
				level_bg:'',
				level_bg2:'',
			}
		},
		created(){
			 this.contentHeight = this.$utils.calcContentHeight(-40)+'px';
			 this.mainColor = this.$uiConfig.mainColor;
			 this.secondary = this.$uiConfig.secondary;
			 this.init()
		},
		mounted() {
			let currentPages = getCurrentPages();
			 let u = "/" + currentPages[currentPages.length-1].route;
			 let pages = wx.getStorageSync("basedata")
			   ? wx.getStorageSync("basedata").bar_title
			   : [];
			 uni.setNavigationBarTitle({
			   title: this.pageTitle,
			 });
		},
		methods: {
			init(){
				uni.showNavigationBarLoading();
				
				this.request2(
				  {
				  	url: '/api/AppletUser/GetUserDistrbutorUpgradeConditions',
				  	data: {}
				  },	
							
				  (res) => {
					uni.hideNavigationBarLoading()
						this.level = res.data
				  }
				);
			},
			Upgrade(){
				uni.showNavigationBarLoading();
				
				this.request2(
				  {
				  	url: '/api/AppletUser/SetUserDistrbutorUpgrade',
				  	data: {
						Id:this.level.GradeInfo.Id
					}
				  },	
							
				  (res) => {
					uni.hideNavigationBarLoading()
						uni.showToast({
							title:res.message,
							icon:'none'
							
						})
						this.init()
				  }
				);
			}
		}
	}
</script>

<style>
	.levelStyle .imgbg{
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.levelStyle .leveltop{
		font-size: 26px;
		
		margin-top: 50px;
	}
	.levelStyle .levelc{
		width: 94%;
		height:70px ;
		border-radius: 8px;
		background: #fff;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 0 15px;
		margin-top:50px ;
	}
	.levelStyle .popup{
		width: 100%;
		height: 285px;
		background: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
		border-radius: 8px;
		overflow: hidden;
		justify-content: space-between;
	}
	.levelStyle .popup_c{
		width: 94%;
		height: 160px;
		padding: 10px;
		border-radius: 5px;
		border: 1px solid #f5f5f5;
	}
	.levelStyle .popup_t{
		width: 100%;
		height:50px ;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.levelStyle .level_b{
		width: 70%;
		height: 50px;
		border-radius: 25px;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #F8DBAF;
		color: #825E4F;
		font-size: 18px;
		margin-top: 40px;
		font-weight: 500;
	}
</style>
