<template>
	<view>
		
		<u-picker mode="selector" v-model="isswitchshow" :range="columns" range-key="label" :default-selector="columnsindex" @confirm="switchBtn" ></u-picker>
		<view class="userHead" :style="isswitch?'padding-top:40px':''" >
			
			<view class="userHead-img">
				<u-avatar src="../../assets/img/head.png" size="140"></u-avatar>
			</view>
			<view class="userHead-text">
				<h3>{{info.merchantAccountName}}</h3>
				<view class="userHead-text-position">
					<u-icon name="account-pin-box-fill" custom-prefix="custom-icon" color="#fff" size="32"></u-icon>
					<p>{{getPhone(info.phone)}}</p>
					<p 
					v-if="isswitch" @click="isswitchshow=true" 
					style="border: 1px solid rgba(255, 255, 255, 1);
					border-radius: 10px;
				
					padding: 0 10px;">
					
					<img src="../../assets/img/userswitch.svg" style="height: 32rpx;width: 32rpx;" alt="">
					
					切换账号</p>
				</view>
			</view>
		</view>
		
	
		
		<view class="userInfo" v-if="home">
			
			<template v-if="accountType">
				<view class="userInfo-head"><p>可提现金额<span v-if="info.accountType==3">（T+4）</span></p></view>
				<view class="userInfo-main">
					<h2>{{showNumJP(home.accountBalance)}}元 
					
					 
								<view class="withdraw"   v-if="info.status&&(info.accountType!=3&&info.accountType!=1)"  @click="gotoUrl('pagesFinance/user/withdrawal/withdrawRecord')" >
									账户提现
								</view>
								
								<view class="withdraw"  v-if="info.accountType==3"  @click="gotoUrl('pagesFinance/user/withdrawal/cashoutList')" >
									账户提现
								</view>
								
					</h2>
					<!-- <view class="userInfo-btn" >帐户提现</view> -->
				</view>
				<view class="userInfo-foot">
					<!-- <view class="userInfo-item">
						<p>今日收益</p>
						<h4>{{home.todayAmount}}</h4>
					</view> -->
					<view class="userInfo-item">
						<p>冻结金额(提现中)</p>
						<h4>{{showNumJP(home.waitingAmount)}}元</h4>
					</view>
					<view class="userInfo-item">
						<p>已提现</p>
						<h4>{{showNumJP(home.withdrawnAmount)}}元</h4>
					</view>
				</view>
			</template>
			<template v-for="(item,i ) in vipPlatformList" v-if="item.entAccountId">
				<view class="userInfo-head" style="margin-top: 20rpx;"  :key="i+'a'" ><p>企业可充电金额
				<span v-if="vipPlatformList1.length>1">[{{item.name}}]</span>
				
				</p></view>
				<view class="userInfo-main"  :key="i+'b'">
					<h2 :style="accountType?'font-size: 32rpx;':''">{{showNumJP(item.entAccountBalance)}}元</h2>
					<!-- <view class="userInfo-btn" >帐户提现</view> -->
				</view>
			</template>
		</view>
		<!-- 功能菜单 -->
		<view class="function-menu" >
			<template v-if="accountType">
			<view class="item"  @click="gotoUrl('pagesFinance/user/stationsList')"  >
			
				
				<view class="item-icon">
					<img src="../../assets/img/riLine-user-settings-line.svg" alt="">
				</view>
				<view class="item-name">
					
					
					我的充电桩
						
				</view>
				<view class="position" v-if="home&&home.deviceNumbers" >
					<view id="talkbubble" :style="home.deviceNumbers>=100?'padding: 2px 16rpx;':''" >{{home.deviceNumbers}}桩{{home.gunNumbers?home.gunNumbers+'枪':''}}</view>
				</view>
			
			</view>
		 
			<view class="item"  v-if="info.accountType==2"  @click="gotoUrl('pagesFinance/user/withdrawal/businessList')">
				<view class="item-icon">
					<img src="../../assets/img/riLine-file-list-3-line.svg" alt="">
				</view>
				<view class="item-name">
					收益核算
				</view>		
			</view>
		
			
				
			
			<view class="item"  v-if="info.accountType==3"  @click="gotoUrl('pagesFinance/user/withdrawal/cashoutList')">
				<view class="item-icon"> <!--个人 -->
					<i data-v-7e5aa06e="" class="ri-todo-line"></i>
				</view>
				<view class="item-name">
					提现记录
				</view>		
			</view>
			<view class="item" v-else @click="gotoUrl('pagesFinance/user/withdrawal/withdrawRecord')">
				<view class="item-icon">
					<i data-v-7e5aa06e="" class="ri-todo-line"></i>
				</view>
				<view class="item-name">
					提现记录
				</view>		
			</view>
			<view class="item" @click="gotoUrl('pagesFinance/preengaged/preengaged')">
				<view class="item-icon">
					<i data-v-137d5072="" class="ri-map-pin-time-line"></i>
				</view>
				<view class="item-name">
					我被预约
				</view>
				
			</view>
			<view class="item" @click="gotoUrl('pagesFinance/recordOfInvoice/recordOfInvoice')">
				<view class="item-icon">
					<i data-v-137d5072="" class="ri-ticket-line"></i>
				</view>
				<view class="item-name">
					开票记录
				</view>
				
			</view>
			<view class="item"  @click="gotoUrl('pagesFinance/user/stationsListLine')">
				<view class="item-icon">
					<i class="ri-webcam-line"></i>
				</view>
				<view class="item-name">
					摄像头
				</view>
				
			</view>
			</template>
			<view class="item" 
			 v-for="(item,i) in vipPlatformList" :key="i" v-if="!item.entAccountId" 
			 @click="gotoUrl('pagesFinance/user/ownManagement?id='+item.id)" >
				<view class="item-icon">
					<i class="ri-folder-user-line"></i>
				</view>
				<view class="item-name">
					{{vipPlatformList.length==1?'车主管理':item.name}}
				</view>
				
			</view>
			
			<view class="item" @click="gotoUrl('pagesFinance/user/help')"  v-if="false" >
				<view class="item-icon">
					<i data-v-137d5072="" class="ri-compass-3-line"></i>
				</view>
				<view class="item-name">
					帮助中心
				</view>
				
			</view>
			<view class="item" @click="phone()" >
				<view class="item-icon">
					<i data-v-137d5072="" class="ri-customer-service-2-line"></i>
				</view>
				<view class="item-name">
					联系客服
				</view>
				
			</view>
			
			<view class="item" @click="gotoUrl('pagesFinance/coupon/index?c=0')" v-if="info.accountType==1" >
				<view class="item-icon">
					<i data-v-137d5072="" class="ri-account-pin-box-line"></i>
				</view>
				<view class="item-name">
					停车优惠劵
				</view>
				
			</view>
			</view>
			
			
			
			
		
		<view class="function-menu2" >
			<template v-for="(item,i ) in vipPlatformList" v-if="item.entAccountId" >
				<view style="padding-top: 6px;font-size: 15px;" :key="'d'+i" >{{item.name}}</view>
				<view  class="function-menu3"  :key="'c'+i" >
					
					<view class="item"  :key="'b'+i" 
					
					 @click="gotoUrl('pagesFinance/accountType8/personmanage/index?id='+item.id+'&pid='+item.entAccountId)" >
						<view class="item-icon">
							<i class="ri-folder-user-line"></i>
						</view>
						<view class="item-name">
							企业员工
						</view>
						
					</view>
					<view class="item"  :key="'ac'+i"
					
					 @click="gotoUrl('pagesFinance/accountType8/carmanage/index?id='+item.entAccountId)" >
						<view class="item-icon">
							<img src="../../assets/img/riLine-bus-line.svg" alt="">
						</view>
						<view class="item-name">
							企业车辆
						</view>
						
					</view>
					
					<view class="item"  v-if="item.entAccountId&&info.accountTopics!=2" :key="'a'+i"
					
					 @click="gotoUrl('pagesFinance/accountType8/chagingrecord/index?id='+item.entAccountId)" >
						<view class="item-icon">
							
							<u-icon name="coupon" style="    margin-bottom: 4px;" size="24px"></u-icon>
			
						</view>
						<view class="item-name">
							企业充电记录
						</view>
						
					</view>
					</view>
			</template>
		</view>
		
		<button class="logout-btn" @click="logout">退出账号</button>
		
	
		
		<Tabbar :current="3"  ref="tabbarMain" ></Tabbar>
 	</view>
</template>

<script>
	import Tabbar from '@/components/TabbarFinance.vue'
	
	import * as API from '@/apis/finance.js'
	import {
		substrMb
	} from '@/utils'
	
	export default {
		data() {
			return {
				columns:[],
				isWithdrawal:false,
				isswitchshow:false,
				isswitch:false,
				tel:'400-8899-619',
				role:{},
				info:{},
				home:null,
				current: 0,
				vipPlatformList:[],
				vipPlatformList1:[],
				vipPlatformList2:[],
				columnsindex:[0],
				background:{
					background: 'none'
				},
			}
		},
		components: {
			Tabbar
		},
		computed:{
			accountType(){
				if(this.accountType8){
					return false
				}
					
				return true
			},
			accountType8(){
				if(this.info&&(this.info.accountTopics==2||this.info.accountTopics==3)){
					return true
				}else
					return false
			}
		},
		onLoad() {
			this.info=this.carhelp.getPersonInfo()
			if(process.env.NODE_ENV === "development"){
				this.isWithdrawal=true
			}
			
		},
		onReady() {
			//this.getHomePage()
			
		},
		onShow() {
			if(this.$refs.tabbarMain){
				
				this.$refs.tabbarMain.setcount();
			}
			this.query()
			this.getHomePage()
		},
		methods: {
			switchBtn(e){
				
				var obj=this.columns[e[0]]
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.switchUser({
					newUserId:obj.value
					
				}).then((response) => {
					uni.hideLoading();
					this.query(true)
					
				}).catch(error => {
					uni.hideLoading();
					
				})
				//
			},
			query(bl){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				
				API.findByOpenId({
					
					openId: this.carhelp.getOpenId(),
					
				}).then((response) => {
					//this.loginset(response)
					var token = response ? response.data.token : '';
					this.carhelp.setToken(token);
					this.carhelp.setPersonInfo(response.data.user);
					this.carhelp.setPersonInfoPlus(response.data)
					this.info=response.data.user
					this.isswitch=response.data.haveOtherUser;
					if(this.isswitch){
						this.allUserList()
					}
					if(bl){
						this.getHomePage()
					}
					if(this.$refs.tabbarMain){
						
						this.$refs.tabbarMain.relist();
					}
					
					uni.hideLoading();
				}).catch(error => {
					uni.hideLoading();
					
				})
			},
			allUserList(){
				API.allUserList({
					
					
				}).then((response) => {
					var  list=response.data.allUserList;
						this.columns=[]
					
					for(var i in list){
						var obj=list[i]
						if(obj.isCurrentUser){
							this.columnsindex=[i]
						}
						this.columns.push({
							value:obj.id,
							label:obj.merchantAccountName
						})
					}
				
				}).catch(error => {
					uni.hideLoading();
					
				})
			},
			getPhone(phone){
				var backphone="";
				if(phone){
					backphone=substrMb(phone,0,3)+"****"+substrMb(phone,7,4)
				}
				
				return backphone;
			},
			showModel(){
				var bankCard="";
				var sss=""
				if(this.home.bankCard){
					
					bankCard=substrMb(this.home.bankCard,0,4)+"****"+substrMb(this.home.bankCard,this.home.bankCard.length-4,4)
				}
				var code=this.home.bank+":"+bankCard;
				if(this.home.bank==null&&this.home.bankCard==null){
					code="未绑定"
				}
				uni.showModal({
					showCancel:false,
					content:code,
					
				})
			},
			logoutApi(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				var data = {
					
				};
				 
				API.logout(data).then((res) => {
					this.carhelp.setToken("");
					this.carhelp.set("merchantUser_token_tdate","")
					this.carhelp.setPersonInfo("");
					this.carhelp.setPersonInfoPlus(""  )
					
					uni.reLaunch({
						url:"/pagesFinance/login/index?phone="+this.info.phone
					})
					
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
			},
			logout(){
				uni.showModal({
				    title: '提示',
				    content: '确认是否退出？',
				    success: res=> {
				        if (res.confirm) {
				           //付钱  改为组件
				           this.logoutApi();
				           
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			phone(){
				uni.makePhoneCall({
				    phoneNumber:this.tel //仅为示例
				});
			},
			getHomePage(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.homePage().then((res) => {
					this.home = res.data
				if(res.data.vipPlatformList){
					this.vipPlatformList=res.data.vipPlatformList
					//this.vipPlatformList1
					this.vipPlatformList.forEach(item=>{
						if(item.entAccountId){
							this.vipPlatformList1.push(item)
						}else{
							this.vipPlatformList2.push(item)
						}
					})
				}
					
					uni.hideLoading()
					
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
			}
		}
	}
</script>
<style>
	page{
		background:url(../../assets/img/index_header_bg.png) no-repeat top center #f7f7f7;
		background-size: 100%;
	}
</style>
<style lang="scss" scoped>
	.navbar-tit {
		color: #fff;
		font-size: 18px;
		
		 text-align: right;
		 width: 100%;
		padding-top: 3px;
		padding-right: 3px;
	}
	.userCell{
		background-color: #fff;
		border-radius: 8px;
		margin: 16px;
		.userCell-item{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 16px;
			.userCell-title{
				display: flex;
				align-items: center;
				p{
					margin-left: 8px;
				}
			}
			span{
				color:#999;
			}
		}
	}
	.userInfo{
		// background-color: #fff;
		background: linear-gradient(#fff2eb,#ffffff);
		margin: 16px;
		padding: 16px;
		border-radius: 8px;
		p{
			color:#637AA2;
		}
		.userInfo-main2{
			width: 100%;
		
			margin-top: 4px;
			align-items: center;
			h2{
				flex: 1;
				font-size: 44rpx;
			
			}
		}
		.userInfo-main{
			display: flex;
			justify-content: space-between;
			margin-top: 4px;
			align-items: center;
			h2{ 
				flex: 1;
				font-size: 64rpx;
				display: flex;
				justify-content: space-between;
				.withdraw{
					margin: auto 0;
					width: 80px;
					height:30px;
					line-height: 28px;
					border-radius: 20px;
					background-color: rgba(255, 133, 1, 100);
					color: rgba(255, 255, 255, 100);
					font-size: 14px;
					text-align: center;
				}
			}
		}
		.userInfo-btn{
			padding: 6px 10px;
			background-color: #FF8501;
			color:#fff;
			border-radius: 15px;
		}
		.userInfo-foot{
			display: flex;
			justify-content: space-between;
			margin-top: 12px;
			.userInfo-item{
				flex: 1;
				h4{
					font-size: 16px;
					margin-top: 4px;
				}
			}
		}
	}
	.userHead{
		display: flex;
		align-items: center;
		padding:40px 20px 0;
		.userHead-img{
		}
		.userHead-text{
			margin-left: 12px;
			h3{
				font-size: 24px;
				color:#fff;
				font-weight: normal;
			}
			.userHead-text-position{
				display: flex;
				align-items: center;
				margin-top: 5px;
				p{
					color:#fff;
					margin-left: 4px;
				}
			}
		}
	}
	.userData{
		background-color: #fff;
		margin: 16px;
		padding: 16px;
		border-radius: 8px;
		display: flex;
	}
	.userData-item{
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content:space-between;
		.userData-data{
			font-size: 24px;
			font-weight: bold;
		}
		.userData-name{
			font-size: 16px;
		}
		.userData-foot{
			margin-top: 4px;
			color:#637AA2;	
		}
	}
	
	
	//功能菜单
	.function-menu{
		margin: 12px 16px;
		background-color: #fff;
		border-radius: 8px;
		padding: 0 13px;
		display: flex;
		flex-wrap: wrap;
	}
	//功能菜单
	.function-menu2{
		 background-color: #fff;
		margin: 12px 16px;
		
		border-radius: 8px;
		padding: 0 13px;
	
	}
	.function-menu3{
		display: flex;
		flex-wrap: wrap;
	
	}
	@media screen and (max-width: 375px) {
	  		.item {
	    		width: 33% !important;
	  		}
		}
	.item{
		min-width: 25%;
		margin-top: 20px;
		margin-bottom: 11px;
		    display: flex;
		    flex-direction: column;
		    align-items: center;
			color: rgba(119, 119, 119, 100);
			i{
				font-size: 24px
			}
			.item-name{
				font-size: 14px;
				margin-top: 8px;
			}
	}
	.logout-btn{
		background-color: #fff;
		margin: 12px 16px;
		border: 8px;
		color: rgba(238, 49, 56, 100);
		font-size: 16px;
		line-height: 40px;
	}
	
	.position {
		position: relative;
		top: -75px;
		//left: 24%;
		height: 0px;
		z-index: 999;
	}
	
	#talkbubble {
		position: absolute;
		top: 0;
		left: 0;
		padding: 1px 20rpx;
		
		line-height: 40rpx;
		font-size: 24rpx;
		color: #fff;
		background: red;
		position: relative;
		border-radius: 10px;
		text-align: center;
	}
	
	#talkbubble:before {
		content: "";
		position: absolute;
		top: 100%;
		right: 20%;
		border-top: 5px solid red;
		border-right: 5px solid transparent;
		border-left: 5px solid transparent;
	}
</style>
