<template>
	<view class="content">
		<view class="pro-head">
			promotion
			<view class="pro-hea-rig">
				 	<image src="../../../static/promo/nav_icon_des@2x.png" mode="aspectFit" class="img1"></image>
				 	<image src="../../../static/promo/nav_icon_more@2x.png" mode="aspectFit" class="img2" @click="invMore=true,msShow=true"></image>
				
			</view>
		</view>
		<view class="pro-body">
			<view class="pro-body-p1">
				bonus: <span class="category-sigh">₦</span><span class="s1">{{inviteRule.bonusCapital}}</span>
			</view>
			
			<view class="pro-body-btn1" @click="appl=true,msShow=true">
				Apply to balance
			</view>
			
			<view class="pro-body-lea">
				<view class="lea-item" v-for="(item,index) in proLeav" :key="item.id" @click=" leaIdChange(index)">
				   <p :class="['p1', leaId==index?'on':'']">{{item.lea}}</p>
				    <p class="p2">{{item.lea2}}</p>
					<p class="p3">{{item.leanum}}</p>
				</view>  
			</view>
			
			<view class="pro-body-code">
				<view class="code-item1">
					<p class="p1" ref="">My Promotion Code</p>
					<p class="p2">{{inviteRule.inviteCode}}</p>
				</view>
				<view class="code-item1">
					<p class="p1">My Promotion Link</p>
					<p class="p2">{{copyText}}</p>
				</view>
				
				<view class="code-btn" @click="copyTextMethod()">
					Copy
				</view>

			
			</view>
				<cont></cont>
		</view>
		
		<view class="invite-more" v-show="invMore">
			<view class="invite-con">
			<view class="more-a" @click="goProRe">
				promotion record
			</view>
			<view class="more-a"  @click="goBouns">
				bonus record
			</view>
			<view class="more-a" @click="applyRecord">
				apply record
			</view>
						</view>
						<view class="invite-con2">
							<view class="more-a" @click="invMore=false,msShow=false">
								cancel
							</view>
						</view>
		</view>
		
		
		<view class="appl_Ba" v-show="appl">
			<view class="top">
				
		
			<view class="title">
				apply to balance
			</view>
			<view class="input">
				<input type="text" value=""  placeholder="bonus" v-model="tranAmt"  placeholder-style="color: #BFC2CCFF;font-size:28rpx;text-transform: capitalize"/>
			</view>
			<view class="all" @click="applyAll()">
				Apply all
			</view>
				</view>
			
			<view class="btn_con">
				<view class="btn1" @click="appl=false,msShow=false">
					cancel
				</view>
				<view class="btn1 puple" @click="bountOut()">
					confirm
				</view>
			</view>
		</view>
		<view class="msg-box-bg"  v-show="msShow">
		</view>
	</view>
	
	
</template>

<script>
	import cont from "@/components/cont/cont.vue"
	export default {
		data() {
			return {
			leaId:0,
			inviteRule:[],
			tranAmt:'',
			proLeav:[
				{
					id:0,
					lea:'level1',
					lea2:'Total people',
					leanum:0
				},
				{
					id:1,
					lea:'level2',
					lea2:'Contribution',
					leanum:0.00
				},
			],
			  copyText:'',
			  invMore:false,
			  appl:false,
			  msShow:false,
			}
		},
		onLoad() {
			 uni.request({
			 	url: '/start/api/user/inviteCode',
			 	data: {
			 		"ticket": uni.getStorageSync('logInfo').data,
			 	},
			 	header: {
			 		'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' //自定义请求头信息
			 	},
			 	method: 'POST', //请求方式  或GET，必须为大写
			 	success: (res) => {
			 		this.inviteRule=res.data.data
					this.copyText='http://www.ngnclub.vip/#/register?r_code='+this.inviteRule.inviteCode;
					// this.copyText=this.inviteRule.qrcodeUrl+this.inviteRule.inviteCode;
			       console.log(res.data,9999);
			 	},
			 	fail: (res) => {
			 	console.log(res.errMsg);
			 	}
			 });
			 
			 
			 
			 
			 
			 
			 
		},
		methods: {
			applyAll(){
				this.tranAmt=this.inviteRule.bonusCapital;
			},
			bountOut(){
				uni.request({
					url: '/start/api/summary/bonusOut',
					data: {
						"ticket": uni.getStorageSync('logInfo').data,
						"tranAmt":this.tranAmt,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' //自定义请求头信息
					},
					method: 'POST', //请求方式  或GET，必须为大写
					
					success: (res) => {
					  if(res.data!=''){
						  if(res.data.success==true){
							  uni.showToast({
							  	title: 'Commission successfully transferred out to balance',
							  	 icon: 'success',
							  	duration: 1500
							  })
						  }else{
							  uni.showToast({
							  	title:res.data.errMsg ,
							  	 icon: 'none',
							  	duration: 1500
							  })
						  }
					  }
				    
					  
					},
					fail: (res) => {
					uni.showToast({
						title:res.data.errMsg ,
						 icon: 'none',
						duration: 1500
					})
					}
				});
			},
			goProRe(){
				uni.reLaunch({
					url:'./promotionRecord/index'
				})
			},
			goBouns(){
				uni.reLaunch({
					url:'./bounsRecord/index'
				})
			},
			applyRecord(){
				uni.reLaunch({
					url:'./applyRecord/index'
				})
			},
			copyTextMethod(){
				
					this.$copyText(this.copyText).then(res => {
						uni.showToast({
							title: 'Copy succeeded',
							icon: 'success'
						})
					})
			},
      leaIdChange(index){
		  this.leaId=index;
	  }
		}
	}
</script>

<style>
	@import url("./index.css");
</style>
