<template>
	<view class="section">
		<view class="title_header">
			<view>
				<view class="position_cicles"
					:style="{'background-image': `url( ${avatar == null || avatar == ''? no_avatar: avatar} )` }">
				</view>
				<view style="color: #fff;">
					{{nickname == null || nickname == ''?  '未登录': nickname }}
				</view>
			</view>
			<view class="position_recharge">
				<view>
					<view>账户余额</view>
					<view>
						<text style="font-weight: 600;">{{balance}}</text>
						<text style="margin-left: 8rpx">元</text>
					</view>
				</view>
				<view class="btn_recharge" v-if="isLogin" @click="handle_recharge">充值</view>
			</view>
		</view>
		<!--  -->
		<view class="cu-card " style="margin-top: 100rpx;">
			<view class="cu-item shadow padding-lr-sm">
				<view class="flex  padding-tb-sm justify-between" @click="accountBalance(1)"
					v-if="now_version == '个人版'">
					<view class="flex">
						<uv-icon name="level" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">个人账户</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view class="flex  padding-tb-sm justify-between" @click="accountBalance(2)"
					v-if="now_version == '车队版' ">
					<view class="flex">
						<uv-icon name="level" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">个人账户</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view class="flex  padding-tb-sm justify-between" @click="accountBalance(3)"
					v-if="now_version == '车队版' ">
					<view class="flex">
						<uv-icon name="level" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">车队账户</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view class="flex  padding-tb-sm justify-between" @click="personalDetails">
					<view class="flex">
						<uv-icon name="home" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">个人信息</view>
					</view>
					<view class="flex">
						<text class="lg text-gray cuIcon-right padding-top-xs"></text>
					</view>
				</view>
				<!-- 	<view class="flex  padding-tb-sm justify-between" @click="gobillingPage">
					<view class="flex">
						<uv-icon name="shopping-cart" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">套餐购买</view>
					</view>
					<view class="flex">
						<text class="lg text-gray cuIcon-right padding-top-xs"></text>
					</view>
				</view> -->
				<!-- <view class="flex padding-tb-sm justify-between" @click="gobillingPage_my">
					<view class="flex">
						<uv-icon name="folder" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">我的套餐</view>
					</view>
					<view class="flex">
						<text class="lg text-gray cuIcon-right padding-top-xs"></text>
					</view>
				</view> -->
				<view class="flex  padding-tb-sm justify-between" @click="vehicleCertification"
					v-if="now_version == '个人版' ">
					<view class="flex">
						<uv-icon name="car-fill" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">车辆认证</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view class="flex  padding-tb-sm justify-between" @click="personnelCertification">
					<view class="flex">
						<uv-icon name="file-text" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">个人身份认证</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<!-- solids-bottom -->
				<view :class="{'flex':true, 'padding-tb-sm':true, 'justify-between':true}" @click="gomotorCade"
					v-if="now_version == '个人版' ">
					<view class="flex">
						<uv-icon name="car" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">车队绑定</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view :class="{'flex':true, 'padding-tb-sm':true, 'justify-between':true}" @click="gomotorCade_mycar">
					<view class="flex">
						<uv-icon name="photo" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">{{ now_version == '车队版'? '车队车辆': '我的车辆'  }}</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<!--  -->
				<view class="flex padding-tb-sm justify-between" @click="goShiftTurnover">
					<view class="flex">
						<uv-icon name="attach" color="#2cc06c" size="20"></uv-icon>
						<view class="titleFont">修改密码</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view class="flex padding-tb-sm justify-between" @click="goAddinvoice">
					<view class="flex">
						<uv-icon name="setting" color="#2cc06c" size="20"></uv-icon>
						<!-- <view class="titleFont">其他设置</view> -->
						<view class="titleFont">开发票</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>
				<view class="flex padding-tb-sm justify-between" @click="goSetting">
					<view class="flex">
						<uv-icon name="setting" color="#2cc06c" size="20"></uv-icon>
						<!-- <view class="titleFont">其他设置</view> -->
						<view class="titleFont">联系我们</view>
					</view>
					<view><text class="lg text-gray cuIcon-right padding-top-xs"></text></view>
				</view>

			</view>
		</view>
		<!--  -->
		<view class="outLoginBtn" v-if="isLogin">
			<u-button @click="logOut" shape='circle'>退出登录</u-button>
		</view>
		<uv-notify ref="errornotify" message="当前无操作权限,请审核通过后再试" type="error"></uv-notify>
		<up-loading-page loading-text="退出中...请稍后" color="#666" :loading="version_loading"></up-loading-page>
	</view>
</template>

<script setup>
	import config from '@/common/config/config.js';
	import {
		reactive,
		ref,
	} from "vue";
	import {
		onLoad,
		onShow,
		onReachBottom
	} from "@dcloudio/uni-app";

	import {
		globalStore
	} from '../../stores/globalData.js';
	const loginStore = globalStore()
	const version_loading = ref(false)
	// 声明变量
	// const dataCode = ref()
	const isLogin = ref(false) //判断是否登录
	const nickname = ref(null)
	const phone = ref()
	const avatar = ref()
	const no_avatar = ref(
		'https://zzpower.net//admin-api/infra/file/4/get/6e642a15c0bad98793f342a5ca83317cfcd62ed8b84fa5fd4c5d6f4176bd3a14.png'
	)
	const balance = ref(0.00)
	const realNameAuthFlag = ref(0)


	const now_version = ref()

	onLoad(() => {

	})
	onShow(() => {
		isLogin.value = loginStore.isLogin
		now_version.value = uni.getStorageSync("version")
		if (isLogin.value == true) {
			// 展示头像与用户信息
			handle_user_info()
			if (now_version.value == '车队版') {
				handle_wallet_team()
			} else {
				handle_wallet_personnel()
			}
		}
	})

	const handle_wallet_team = async () => {
		let data = {
			bindType: 2
		}
		let config_url = 'app-api/pay/wallet/get'
		await uni.$request({
			url: config.baseUrl + config_url,
			data
		}).then(res => {
			balance.value = res.data.data.balance / 100
		})
	}

	const handle_wallet_personnel = async () => {
		let data = {
			bindType: 1
		}
		await uni.$request({
			url: config.baseUrl + "app-api/pay/wallet/get",
			data
		}).then(res => {
			balance.value = res.data.data.balance / 100
		})
	}

	const handle_user_info = async () => {
		await uni.$request({
			url: config.baseUrl + 'app-api/member/user/get',
		}).then((res) => {
			if (res.data.code == 0) {
				avatar.value = res.data.data.avatar
				nickname.value = res.data.data.nickname
				phone.value = res.data.data.mobile
				// realNameAuthFlag.value = res.data.data.realNameAuthFlag
				// uni.setStorageSync("realNameAuthFlag", res.data.data.realNameAuthFlag)
				uni.setStorageSync("teamId", res.data.data.teamId)
				uni.setStorageSync("mobile", res.data.data.mobile)
				uni.setStorageSync("captainOrNot", res.data.data.captainOrNot)

			}
		})
	}
	const errornotify = ref(null)
	// 去设置页面
	const goSetting = () => {
		uni.navigateTo({
			// url: './setting/setting'
			url: '/pages/userCenter/about/about'
		})
	}
	
	const goAddinvoice = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: '/pagesCenter/billingPage/addInvoice/addInvoice'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// }
	}
	
	const gologin = () => {
		uni.navigateTo({
			url: '../../pagesCenter/login/enter'
		})
	}
	const personalDetails = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: './personalDetails/personalDetails'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// }



	}
	const gobillingPage = () => {
		// console.log('点击了')
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: '../../pagesCenter/billingPage/billingPage'
			})
		}
		//  else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// }

	}

	const gobillingPage_my = () => {
		// console.log('点击了')
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: '/pagesCenter/billingPage/billingMean/billingMean'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// } 

	}
	const vehicleCertification = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: './carIdentification/carIdentification'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// } 

	}

	const personnelCertification = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: './personneldentification/personneldentification'
			})
		}

	}
	const accountBalance = (type) => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			let url_push = ''
			if (type == 1) {
				url_push = '/pagesCenter/accountBalance/accountBalance'
			} else if (type == 2) {
				url_push = '/pagesCenter/accountBalancePersonnelCar/accountBalancePersonnelCar'
			} else {
				url_push = '/pagesCenter/accountBalanceTeam/accountBalanceTeam'
			}
			uni.navigateTo({
				url: url_push
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// } 

	}
	const goAbout = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: './about/about'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// } 


	}
	const gomotorCade = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: '../../pagesCenter/motorCade/motorCade'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// } 

	}

	const gomotorCade_mycar = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: '../../pagesCenter/motorCadeMy/motorCadeMy'
			})
		}
		// else if (realNameAuthFlag.value != 1) {
		// 	errornotify.value.show()
		// 	return
		// } 

	}
	const goShiftTurnover = () => {
		if (!uni.getStorageSync("userInfo")) {
			uni.showToast({
				title: '请先完成登录',
				duration: 2000,
				icon: 'error'
			});
			return;
		} else {
			uni.navigateTo({
				url: `/pagesCenter/login/changepassword?mobile=123`
			})
		}
	}

	const logOut = () => {
		uni.hideTabBar()
		version_loading.value = true
		uni.removeStorageSync("userInfo");
		uni.removeStorageSync("token");
		uni.removeStorageSync("refreshToken");
		uni.removeStorageSync("teamId");
		uni.removeStorageSync("realNameAuthFlag");
		uni.removeStorageSync("version");
		loginStore.isLogin = false
		setTimeout(() => {
			uni.showTabBar()
			version_loading.value = false
			uni.reLaunch({
				url: '/pages/index/index'
			})
		}, 2000)

	}

	const handle_recharge = () => {
		if (now_version.value == '车队版') {
			uni.setStorageSync("ispersonnel", 1);
		}
		uni.navigateTo({
			url: '/pages/index/recharge/recharge'
		})
	}
</script>

<style lang='scss' scoped>
	.png {
		width: 50rpx;
		height: 50rpx;
	}

	.section {
		width: 100%;
		height: 100vh;
		/* background: linear-gradient(180deg, #E4EFFF 0%, rgba(228, 239, 255, 0) 100%); */
		background: #f3f7fa;
		position: relative;
	}

	.titleImg {
		width: 50rpx;
		height: 50rpx;
	}

	.titleFont {
		font-size: 28rpx;
		color: #000;
		/* margin-top: 8rpx; */
		margin-left: 20rpx;
	}

	.cu-card>.cu-item {
		margin: 0 30rpx 30rpx 30rpx;
	}

	.tops_view {
		width: 100%;
		height: 200rpx;
		border-bottom-left-radius: 60rpx;
		border-bottom-right-radius: 60rpx;
		background: #2cc06c;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 16px;
		color: #fff;
		font-weight: bold;
	}

	.position_cicles {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		background-size: 100% 100%;
		box-shadow: 1px 1px 1px #ccc;
	}

	.setting_position {
		position: absolute;
		top: 20rpx;
		right: 20rpx;
	}

	.title_header {
		display: flex;
		align-items: start;
		/* justify-content: space-between; */
		width: 100%;
		height: 440rpx;
		border-bottom-left-radius: 60rpx;
		border-bottom-right-radius: 60rpx;
		/* background: #2cc06c; */
		background-image: url('https://zzpower.net//admin-api/infra/file/4/get/99bd21413e53b2474f01e40a76d41b103a72db8aab106b2af6ffa59e3016ff80.jpg');
		/* background-image: url('https://zzpower.net//admin-api/infra/file/4/get/9e7cdfed4eb3775bf248cd0ac7496cedea7a2af21a9ab384d3819dc5944dd0a1.jpg'); */
		/* background-image: url('https://zzpower.net//admin-api/infra/file/4/get/dc0d69995b79fb13fe1baf61d6e2570fcabdd3e47cce7ae302d6d8e51f260834.jpg'); */
		background-repeat: no-repeat;
		background-position: center;
		background-size: 100% 100%;
		padding: 200rpx 30rpx 0 30rpx;
		box-sizing: border-box;
		position: relative;

		>view:first-child {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.position_recharge {
			width: calc(100% - 60rpx);
			height: 130rpx;
			background: #fff;
			position: absolute;
			bottom: -60rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			box-sizing: border-box;

			>view:first-child {
				color: #000;
			}

			.btn_recharge {
				padding: 10rpx 20rpx;
				background: linear-gradient(to right, #72ef3f, #41ce2d);
				color: #fff;
				border-radius: 10rpx;
				font-size: 14px;
			}
		}
	}

	.outLoginBtn {
		width: calc(100% - 60rpx);
		position: absolute;
		bottom: 50rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>