<template>
	<view class="shareindexStyle" :style="{'height':contentHeight}">
		<view class="shareadd" v-if=" sharestatus.Status==1">
			<u-empty text=" " mode="data"></u-empty>
			<Text style='margin: 10px 0;'>{{sharestatus.Msg}}</Text>
			<view class="shareadd_b" :style="{background:mainColor}" @click="goaddurl">
				<Text>{{sharestatus.ApplyForName}}</Text>
			</view>
		</view>
		<view v-if="sharestatus.Status==2" style="width: 100%;display: flex;flex-direction: column;align-items: center;">
			<image src="../../../static/images/icon/img-share-status.png" style="width: 100%;height: 165px;"></image>
			<Text style='margin-top: 70px;'>谢谢您的支持，请等待审核</Text>
			<view style="display: flex;align-items: center;justify-content: center;margin-top: 60rpx;">
				<u-button  shape="circle" type="error" size="medium" @click='goshoping'>去商城逛逛</u-button>
			</view>
		</view>
		<view v-if="sharestatus.Status==4" style="width: 100%;display: flex;flex-direction: column;align-items: center;">
			<image src="../../../static/images/icon/img-share-status.png" style="width: 100%;height: 165px;"></image>
			<Text style='margin-top: 70px;'>{{sharestatus.Msg}}</Text>
			<!-- <view style="display: flex;align-items: center;justify-content: center;margin-top: 60rpx;">
				<u-button  shape="circle" type="error" size="medium" @click='goshoping'>去商城逛逛</u-button>
			</view> -->
		</view>
		<view style="width: 100%;height: 100%;" v-if="sharestatus.Status==3">
			<view class="sharebox_top" :style="{background:mainColor}">
				<view class="sharebox_top_t">
					<view class="top_t_l">
						
						<u-avatar :src="sharedata.UserInfo.Photo" size="120"></u-avatar>
						<view style="display: flex;flex-direction: column;color: #fff;margin-left: 5px;">
							<Text style='font-size: 16px;'>{{sharedata.UserInfo.UserName}}</Text>
							<Text>{{sharedata.CustomModel.ReferrerName}}：{{sharedata.UserInfo.SuperiorName}}</Text>
							<Text>分销等级：{{sharedata.UserInfo.GradeName}}</Text>
						</view>
					</view>
					<view v-if='sharedata.UserInfo.DistributorGradeEntrance==1' style="display: flex;flex-direction: row;align-items: center;color: #fff;" @click="goUrl('/pages/share/level/level')">
						<Text>升级条件</Text>
						<u-icon name="arrow" color='#fff'></u-icon>
					</view>
				</view>
				<view style="width: 100%;height: 1px;background: #fff;margin: 10px 0;"></view>
				
				<view class="sharebox_top_t">
					<view style="display: flex;flex-direction: column;color: #fff;">
						<Text>{{sharedata.CustomModel.CommissionForWithdrawalName}}</Text>
						<Text style='font-size: 22px;'>{{sharedata.UserInfo.CommissionWithdrawal!=null ?sharedata.UserInfo.CommissionWithdrawal:0}} <Text  style='font-size: 14px;'>元</Text> </Text>
					</view>
					<view style="width: 55px;height: 30px;border-radius: 15px;border:1px solid #fff;display: flex;align-items: center;justify-content: center;color: #fff;"
						@click="goUrl2('/pages/share/cash/cash')"
					>
						<Text>{{sharedata.CustomModel.WithdrawDepositName}}</Text>
					</view>
				</view>
			</view>
			<view class="sharebox_c">
				<view class="center_item">
					<Text style='color: #57AC4F;font-size: 14px;'>{{sharedata.CustomModel.CommissionWithdrawnName}}</Text>
					<Text>{{sharedata.UserInfo.TXCommission!=null ?sharedata.UserInfo.TXCommission:0}}元</Text>
				</view>
				<view style="width: 2px;height: 60px;background: #f5f5f5;"></view>
				<view class="center_item">
					<Text :style="{color:secondary,fontSize:'14px'}">{{sharedata.CustomModel.OutstandingCommissionName}}</Text>
					<Text>{{sharedata.UserInfo.WJSCommission!=null ?sharedata.UserInfo.WJSCommission:0}}元</Text>
				</view>
			</view>
			<view class="sharebox_menus" >
				<view class="menus_item" @click="goUrl('/pages/share-money/share-money')">
					<image :src="sharedata.CustomModel.DistributionCommissionImage" style="width: 30px;height: 30px;" mode='widthFix'></image>
					<Text class='item_text'>{{sharedata.CustomModel.DistributionCommissionName}}</Text>
					<Text><Text :style="{color:mainColor}">{{sharedata.UserInfo.TotalCommission!=null ?sharedata.UserInfo.TotalCommission:0}}</Text>元</Text>
				</view>
				
				<view class="menus_item" @click="goUrl('/pages/share-order/share-order')">
					<image :src="sharedata.CustomModel.DistributionOrderImage" style="width: 30px;height: 30px" mode='widthFix'></image>
					<Text class='item_text'>{{sharedata.CustomModel.DistributionOrderName}}</Text>
					<Text><Text :style="{color:mainColor}">{{sharedata.UserInfo.OrderCommission!=null ?sharedata.UserInfo.OrderCommission:0}}</Text>元</Text>
				</view>
				
				<view class="menus_item" @click="goUrl('/pages/cash-detail/cash-detail')">
					<image :src="sharedata.CustomModel.WithdrawDetialsImage" style="width: 30px;height: 30px" mode='widthFix'></image>
					<Text class='item_text'>{{sharedata.CustomModel.WithdrawDetialsName}}</Text>
					<Text><Text :style="{color:mainColor}">{{sharedata.UserInfo.RemitMoney!=null ?sharedata.UserInfo.RemitMoney:0}}</Text>元</Text>
				</view>
				<view class="menus_item" @click="goUrl('/pages/share-team/share-team')">
					<image :src="sharedata.CustomModel.MyTeamImage" style="width: 30px;height: 30px" mode='widthFix'></image>
					<Text class='item_text'>{{sharedata.CustomModel.MyTeamName}}</Text>
					<Text><Text :style="{color:mainColor}">{{sharedata.UserInfo.ReferralsNum!=null ?sharedata.UserInfo.ReferralsNum:0}}</Text>人</Text>
				</view>
				<view class="menus_item" @click="goUrl('/pages/share-qrcode/share-qrcode')">
				
					<image :src="sharedata.CustomModel.PromoteQRCodeImage" style="width: 30px;height: 30px" mode='widthFix'></image>
					<Text class='item_text'>{{sharedata.CustomModel.PromoteQRCodeName}}</Text>
					
				</view>
				<view class="menus_item" @click="goUrl('/pages/share/examine')" v-if='sharedata.UserInfo.HpReferralsGradeAudit==1'>
					<!-- <image :src="sharedata.CustomModel.PromoteQRCodeImage" style="width: 30px;height: 30px" mode='widthFix'></image> -->
					<Text class='item_text'>分销商审核</Text>
					
				</view>
			</view>
		</view>
		
		
		<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'goback'></auth>
	</view>
</template>

<script>
	import auth from "../../../components/auth/index.vue";
	export default {
		components:{
			auth,
		},
		data() {
			return {
				 pageTitle: "分销中心",
				 contentHeight:0,
				 mainColor:'',
				 secondary:'',
				 sharestatus:{},
				 userinfo:{},
				 sharedata:{},
				 
				 showAuth:false
			}
		},
		created(){
			 this.contentHeight = this.$utils.calcContentHeight(-40)+'px';
			 this.mainColor = this.$uiConfig.mainColor;
			 this.secondary = this.$uiConfig.secondary;
			 
			 
		},
		mounted() {
			let currentPages = getCurrentPages();
			 let u = "/" + currentPages[currentPages.length-1].route;
			 let pages = wx.getStorageSync("basedata")
			   ? wx.getStorageSync("basedata").bar_title
			   : [];
			   
			
		  
			 pages.forEach((x) => {
			   if (x.value == u) {
			     this.pageTitle = x.new_name ? x.new_name : x.name;
			   }
			 });
			 uni.setNavigationBarTitle({
			   title: this.pageTitle,
			 });
		},
		onLoad(){
			this.u = uni.getStorageSync("mall_UserInfo");
			if (!this.u) {
			  this.u = {
				nickName: "未登录",
				avatarUrl: ""
			  };
			  this.showAuth = true;
			}else{
				this.init()
				// this.getuserinfo()
			}
		},
		methods: {
			reloadUserinfo() {
			  this.u = uni.getStorageSync("mall_UserInfo");
			  this.showAuth=false;
			  this.init()
			  // this.getuserinfo()
			},
			goback(){
				uni.navigateBack()
			},
			init(){
				uni.showNavigationBarLoading();
				
				this.request2(
				 {
				 	url: '/api/AppletUser/GetUserDistrbutorStatus',
				 	data: {}
				 },	
			  (res) => {
				uni.hideNavigationBarLoading()
				this.sharestatus = res.data
				// if(res.data.is_can_apply==false && res.data.status==1){
				// 	this.getorder()
				// }
				if(res.data.Status==3){
					this.getUserCenter()
				}
			  }
			);
		  },
		  goshoping(){
		  	uni.redirectTo({ url: "/pages/index/index" });
		  },
		  
		  getUserCenter(){
			  uni.showNavigationBarLoading();
			  	
			  	this.request2(
					{
						url: '/api/AppletUser/GetUserDistrbutorCenter',
						data: {}
					},		
			    (res) => {
			  	uni.hideNavigationBarLoading()
			  	this.sharedata = res.data
			    }
			  );
		  },
		  goaddurl(){
			  if(this.sharestatus.Status==1 && (this.sharestatus.ApplyFor==1 || this.sharestatus.ApplyFor==2)){
				  uni.navigateTo({
				    url: "/pages/share/add/add",
				  });
			  }else if(this.sharestatus.Status==1 && (this.sharestatus.ApplyFor==3 || this.sharestatus.ApplyFor==4)){
				  this.request2(
				   {
				  	url: '/api/AppletUser/SetUserApplyForBeDistrbutor',
				  	data: {
							Name:'',
							Mobile:'',
						}
				   },	
				    (res) => {
						this.init()
						
				    }
				  );
			  }
			
		  },
		  goUrl(url){
			  console.log(url)
			  uni.navigateTo({
			    url: url
			  });
		  },
		  goUrl2(url){
			  
			  uni.navigateTo({
			    url: url
			  });
		  }
		  
		}
	}
</script>

<style>
	.shareindexStyle{
		background: #f3f4f6;
	}
	.shareindexStyle .shareadd{
		width: 100%;
		display: flex;
		flex-direction: column;align-items: center;
		padding-top: 50px;
	}
	.shareindexStyle .shareadd .shareadd_b{
		width: 60%;height: 45px;border-radius: 22.5px;display: flex;align-items: center;justify-content: center;color: #fff;margin-top: 20px;
	}
	.shareindexStyle .sharebox_top{
		width: 100%;
		padding: 10px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.shareindexStyle .sharebox_top .sharebox_top_t{
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 5px 0;
	}
	.shareindexStyle .sharebox_top .sharebox_top_t .top_t_l{
		display: flex;
		flex-direction: row;
		align-items: center;
		
	}
	.shareindexStyle .sharebox_c{
		width: 94%;
		margin-left: 3%;
		height: 90px;
		border-radius: 10rpx;
		background: #fff;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-around;
		padding: 10px 20px;
		margin-top: 10px;
		
	}
	.shareindexStyle .center_item{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
	}
	.shareindexStyle .sharebox_menus{
		width: 94%;
		margin-left: 3%;
		border-radius: 10rpx;
		background: #fff;
		display: flex;
		flex-direction: row;
		align-items: center;
		flex-wrap: wrap;
		padding: 10px 0;
		margin-top: 10px;
	}
	.sharebox_menus .menus_item{
		width: 33%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 15px 0;
	}
	.sharebox_menus .menus_item .item_text{
		font-size: 13px;
		margin: 5px 0;
	}
</style>
