<template>
	<navBar title="九州ETC" :scrollTop="scrollTop" :isBack="isBack" navbgClass="nav-bgXin" fontColor='#fff'></navBar>
	<filter>
		<view class="wrapper">
			<image :src="`${$imgUrl}myImage/headbg.png`" class="bg-head" mode="widthFix"></image>
			<view class="content" :style="{ top: margin + 'px' }">
				<view class="head" :style="{ marinTop: margin + 'px' }">
					<view class="avatar">
						<image :src="`${$imgUrl}myImage/touxiang.png`" :class="!state.data.opId ? 'unlogin' : ''"
							@click="goLogin">
						</image>

						<view v-if="!state.data.opId" class="name" @click="$util.navTo('/login/login')">
							<view class="nickname">登录/注册</view>
						</view>
						<view v-else class="name">
							<view class="nickname">{{state.accountInfoVo.userName || state.accountInfoVo.nickName}}
							</view>
							<view class="user-id">
								<view class="phone">{{state.accountInfoVo.mobile}}</view>
								<view v-if="false"
									@click="$util.navTo('/subpackage/personal-center/setting/change-phone', true)"
									class="btn-change">已关联</view>
							</view>
							<view v-if="!isSm" class="btn-change-two">已实名认证</view>
						</view>
					</view>
					<view class="r-setting" @click="$util.navTo('/subpackage/personal-center/setting/setting', true)">
						<image :src="`${$imgUrl}myImage/shezhi.png`" class="img" mode="widthFix"></image>
					</view>
				</view>
				<view class="my-equity" :style="{'--bgimg':`url(${$imgUrl}myImage/quanuyikuang.png)`}"
					@click="myEtcAccount">
					<view class="l-con">
						<image :src="`${$imgUrl}myImage/myETC.png`" class="equity-icon" mode="widthFix"></image>
						<view class="txt">
							我的ETC账户
						</view>
					</view>
					<view class="r-icon1">
						<image :src="`${$imgUrl}myImage/quanyixiayi.png`" class="r-img1" mode="widthFix"></image>
					</view>
				</view>
				<view class="my-equity userName" :style="{'--bgimg':`url(${$imgUrl}myImage/loginBg.png)`,'height': '120rpx' ,'margin-top':' -30rpx',
		 'z-index': -1,'padding-top': '17rpx','boxSizing':'border-box' }" v-if="state.customerObj">
					<view class="l-con">
						<image :src="`${$imgUrl}myImage/person.png`" class="equity-icon" mode="widthFix"></image>
						<view class="txt">
							{{state.customerObj.userName}}
						</view>
					</view>
					<view style="margin-right: 26rpx;">
						{{state.customerObj.vehicleCount?state.customerObj.vehicleCount:'无'}}辆车
					</view>
				</view>

				<view class="info-content">
					<view class="order box">
						<view class="list_item"
							@click="$util.navTo('/subpackage/personal-center/real-name-authentication', true)">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/basicInformation.png`" class="equity-icon"
									mode="widthFix"></image>
								<view class="txt">
									基本信息
								</view>
							</view>
							<view class="r-icon">
								<text v-if="isSm">请进行实名认证</text>
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
						<view class="list_item"
							@click="$util.navTo(`/subpackage/after-sale/activation-once-again/select-car?type=38`, true)">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/myCar.png`" class="equity-icon" mode="widthFix"></image>
								<view class="txt">
									我的车辆
								</view>
							</view>
							<view class="r-icon">
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
						<view class="list_item" @click="goOrder(0)">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/etcOrder.png`" class="equity-icon" mode="widthFix">
								</image>
								<view class="txt">
									ETC订单
								</view>
							</view>
							<view class="r-icon">
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
						<view class="list_item">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/afterOrder.png`" class="equity-icon" mode="widthFix">
								</image>
								<view class="txt">
									售后订单
								</view>
							</view>
							<view class="r-icon">
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
						<view class="list_item" @click="goEquity()">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/quanyi.png`" class="equity-icon" mode="widthFix">
								</image>
								<view class="txt">
									我的权益
								</view>
							</view>
							<view class="r-icon">
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
						<view class="list_item"
							@click="$util.navTo(`/subpackage/orders/invoiceApply/invoice-header-list?manage=1`, true)">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/invoiceHeader.png`" class="equity-icon" mode="widthFix">
								</image>
								<view class="txt">
									发票抬头
								</view>
							</view>
							<view class="r-icon">
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
						<view class="list_item"
							@click="$util.navTo(`/subpackage/personal-center/setting/addressManager`, true)">
							<view class="l-con">
								<image :src="`${$imgUrl}myImage/addressManager.png`" class="equity-icon"
									mode="widthFix"></image>
								<view class="txt">
									收货地址
								</view>
							</view>
							<view class="r-icon">
								<image :src="`${$imgUrl}myImage/myIcon.png`" class="r-img" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</filter>
</template>
<script lang="ts" setup>
	import { reactive } from "vue";
	import { msg, navTo } from "@/utils/utils";
	import { onMounted, ref } from "vue";
	import { getItem, StorageKeys } from "@/utils/storage";
	import navBar from "../../components/nav-bar/nav-bar2.vue";
	import { onLoad, onShow, onPageScroll } from "@dcloudio/uni-app";
	import {
		userInfoIndex, queryVehicleBind, vehicleUnBind, showEquityListApi, orderinfosumquery, getUserMsg
	} from "@/utils/network/api.js";
	import {
		request, requestNew
	} from "@/utils/network/request.js";
	import filter from '@/components/filter/filter.vue';
	import { source } from "@/utils/network/difference";
	import { vehiclePlateColor, vehiclePlateColorPai, getVehiclePlateColorPaiShow } from "@/datas/vehiclePlateColor.js";
	import { useUserStore } from "@/stores/user";
	const userStore = useUserStore();
	const { saveUserInfo } = userStore;
	
	const height = ref(null);
	const top = ref(null);
	const margin = ref(null);
	const mobile = ref(null);
	const scrollTop = ref(0);
	const isBack = ref(false);
	const isSm = ref(true);
	const state = reactive({
		data: {
			opId: "",
		},
		accountInfoVo: {
			nickName: '',
			mobile: '',
			userName: ''
		},
		equityNumber: 0,
		customerObj: {}
	});
	onMounted(() => {
		const res = uni.getMenuButtonBoundingClientRect();
		height.value = res.height + "px";
		top.value = res.top + "px";
		margin.value = res.height + res.top;
	});

	onLoad((option : any) => {
		state.data.opId = getItem(StorageKeys.OpenId);
		console.log("state.data.opId", state.data.opId)
		mobile.value = getItem("mobile");
		getAuthInfo();
	});
	const carDetails = (vehicleId) => {
		uni.navigateTo({
			url: `/subpackage/personal-center/vehicle-change/car-details?vehicleId=${vehicleId}`
		})
	}
	const myEtcAccount = () => {
		navTo(`/subpackage/personal-center/my-etc-account`)
	}
	//监听页面滚动
	onPageScroll((e) => {
		scrollTop.value = e.scrollTop;
	});
	onShow((option : any) => {
		state.data.opId = getItem(StorageKeys.OpenId);
		console.log("state.data.opId", state.data.opId)
		if (state.data.opId) {
			getUserInfo();
			getAuthInfo();
		}
		state.customerObj = getItem('customerObj')
	});
	const getAuthInfo = () => {
		const options = {
			type: 2,
			data: { openId: getItem('openId') },
			method: "POST",
			showLoading: true,
		};
		requestNew(getUserMsg, options).then((res) => {
			const data = res;
			console.log(data, "用户信息"); //|| !data.userNegImgUrl || !data.userPosImgUrl
			if (!data.userIdNum || !data.userNegImgUrl || !data.userPosImgUrl) {
				isSm.value = true
			} else {
				isSm.value = false
			}
		});
	}
	const getUserInfo = () => {
		const options = {
			type: 2,
			data: {},
			method: "POST",
			showLoading: true,
		};
		//调用方式
		requestNew(userInfoIndex, options)
			.then((res) => {
				console.log('用户信息', res)
				let data = res
				saveUserInfo(data)
				state.accountInfoVo = data;
				console.log("获取用户信息", getItem('userInfo'));
			})
			.catch((err) => {
				console.log(err);
			});
	}

	const goOrder = (index) => {
		navTo(`../order/order?index=${index}`)
	}
	const goLogin = () => {
		if (!getItem('openId')) {
			uni.navigateTo({
				url: "/login/login"
			})
		}
	}
	const goEquity = () => {
		navTo('/subpackage/service/equityList/equityList')
	}
</script>
<style>
	page {
		background: #eef7f7;
	}
</style>
<style scoped lang='scss'>
	.unlogin {
		filter: grayscale(100%);
		opacity: 0.7;
	}

	.bgVar {
		background-image: var(--bgimg);
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}

	.wrapper {
		position: relative;
		background-color: #f6f9fc;
	}

	.bar {
		width: 100%;
		position: fixed;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
	}

	.bg-head {
		width: 100%;
		position: absolute;
		z-index: 1;
		top: 0;
		left: 0;
	}

	.content {
		position: relative;
		display: flex;
		flex-direction: column;
		width: 100%;
		z-index: 2;
	}

	.head {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		box-sizing: border-box;
		padding: 40rpx 0 46rpx;
	}

	.head .avatar {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.head .avatar image {
		width: 141rpx;
		height: 141rpx;
		/* border-radius: 80rpx; */
		margin: 0 20rpx 0 30rpx;
	}

	.head .setting {
		display: flex;
		align-items: center;
		background: rgba(0, 179, 139, .1);
		border: 1px solid #fff;
		height: 60rpx;
		border-radius: 30rpx;
		padding: 0 34rpx;
		color: #fff;
		font-size: 28rpx;
		margin-right: 30rpx;
	}

	.head .setting image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 6rpx;
	}

	.head .r-setting {
		width: 80rpx;
		height: 80rpx;
		background: #345061;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
		margin-right: 50rpx;

		.img {
			width: 40rpx;
			height: 39rpx;
		}
	}

	.head .nickname {
		font-size: 36rpx;
		color: #fff;
	}

	.head .user-id {
		font-size: 26rpx;
		color: #fff;
		padding-top: 20rpx;
		display: flex;
		align-items: center;
	}

	.head .btn-change {
		font-size: 22rpx;
		height: 40rpx;
		padding: 0 20rpx;
		border: 1px solid #fff;
		color: #fff;
		box-sizing: border-box;
		border-radius: 20rpx;
		margin-left: 16rpx;
		background: rgba(0, 179, 139, .1);
	}
	
	.btn-change-two {
		font-size: 22rpx;
		height: 40rpx;
		padding: 0 40rpx;
		border: 1px solid #CCB375;
		color: #CCB375;
		box-sizing: border-box;
		border-radius: 20rpx;
		margin-top: 10rpx;
		background: rgba(0, 179, 139, .1);
	}

	.list_item {
		position: relative;
		z-index: 20;
		margin: 0 30rpx;
		height: 94rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #DFDFDF;

		.l-con {
			display: flex;
			align-items: center;

			.equity-icon {
				width: 46rpx;
				height: 46rpx;
			}

			.txt {
				font-family: NotoSansHans, NotoSansHans;
				font-size: 28rpx;
				color: #01253C;
				margin-left: 19rpx;
			}
		}

		.r-icon {
			height: 32rpx;
			display: flex;
			align-items: center;
			color: rgb(177, 177, 177);
			font-size: 28rpx;

			.r-img {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}

	.box>view:last-child {
		border: none;
	}

	.my-equity {
		position: relative;
		z-index: 20;
		margin: 0 auto;
		background-image: var(--bgimg);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 700rpx;
		height: 94rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.l-con {
			margin-left: 30rpx;
			display: flex;
			align-items: center;

			.equity-icon {
				width: 54rpx;
				height: 54rpx;
			}

			.txt {
				font-family: NotoSansHans, NotoSansHans;
				font-size: 28rpx;
				color: #01253C;
				margin-left: 19rpx;
			}
		}

		.r-icon {
			margin-right: 30rpx;
			width: 36rpx;
			height: 36rpx;

			.r-img {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.r-icon1 {
			margin-right: 30rpx;
			width: 32rpx;
			height: 32rpx;

			.r-img1 {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}

	.info-content {
		transform: translateY(-10rpx);
		margin-top: 30rpx;
	}

	.box .arrow {
		width: 10rpx;
		height: 18rpx;
	}

	.box {
		background: #ffffff;
		margin: 0 30rpx 30rpx;
		border-radius: 20rpx;
		box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(223, 223, 223, 0.9);
	}

	.box .more {
		display: flex;
		align-items: center;
		font-family: NotoSansHans, NotoSansHans;
		font-size: 24rpx;
		color: #004576;
	}

	.box .more .more-text {
		padding-right: 12rpx;
	}

	.box .right-head {
		display: flex;
		justify-content: space-between;
	}

	.box .right-head .tit {
		font-size: 32rpx;
		font-family: MicrosoftYaHei;
	}

	.rights .rights-items {
		display: flex;
		justify-content: space-evenly;
		padding: 30rpx 0;
	}

	.rights .item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.rights .item .tit {
		font-size: 26rpx;
		color: #333;
		padding: 20rpx 0 10rpx 0;
	}

	.rights .item .sub-tit {
		font-size: 22rpx;
		color: #999;
	}

	.order .order-items {
		display: flex;
		justify-content: space-around;
		padding: 30rpx 0 10rpx;

		.rtop-badge {
			position: absolute;
			right: 0;
			width: 34rpx;
			height: 34rpx;
			top: 0;
			transform: translate(50%, -50%);
			line-height: 34rpx;
			text-align: center;
			font-family: SourceHanSansSC, SourceHanSansSC;
			font-weight: 400;
			font-size: 20rpx;
			color: #FFFFFF;
		}
	}

	.order .item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.order .item .tit {
		font-size: 26rpx;
		color: #333;
		padding: 20rpx 0 10rpx 0;
	}

	.box .icon {
		width: 50rpx;
		height: 50rpx;
	}

	.go-through .pass {
		display: flex;
		flex-direction: column;
	}

	.go-through .total {
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		color: #666;
	}

	.go-through .amount {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-family: NotoSansHans, NotoSansHans;
		font-size: 32rpx;
		color: #333333;
		font-weight: 400;
	}

	.go-through .line {
		display: flex;
	}

	.go-through .line1 {
		height: 14rpx;
		background: #005B9C;
		border-radius: 7rpx;
	}

	.go-through .line2 {
		height: 14rpx;
		background: #E5ECEF;
		border-radius: 7rpx;
		flex: 1;
	}

	.go-through .mileage {
		display: flex;
		justify-content: space-around;
		align-items: center;
		text-align: center;
		margin: 32rpx 0;

		.box-items {
			background-image: var(--bgimg);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 20rpx 30rpx;

			.t-name {
				display: flex;

				.tongxing-icon {
					width: 29rpx;
					height: 29rpx;
				}

				.tit {
					font-size: 26rpx;
					color: #666666;
					line-height: 29rpx;
					margin-left: 5rpx;
				}
			}

			.b-info {
				padding-top: 20rpx;

				.val {
					font-size: 32rpx;
					color: #333333;
				}

				.unit {
					font-size: 24rpx;
					color: #666666;
					margin-left: 5rpx;
				}
			}
		}
	}

	.go-through .mileage .txt {
		display: flex;
		flex-direction: column;
	}

	.go-through .mileage .tit {
		font-size: 26rpx;
		color: #999;
	}

	.go-through .mileage .val {
		font-size: 28rpx;
		color: #333;
		margin-top: 16rpx;
	}

	.go-through .m-top {
		margin-top: 16rpx;
	}

	.go-through .detail {
		width: 100%;
		text-align: center;
		color: #00B38B;
		font-size: 24rpx;
		border-top: 1px solid #DCDCDC;
		padding-top: 24rpx;
	}

	.cars .car-item {
		display: flex;
		align-items: center;
		padding-top: 36rpx;
	}

	.cars .car-item .btn-unbind {
		font-weight: 400;
		border-radius: 30rpx;
		font-family: NotoSansHans, NotoSansHans;
		line-height: 60rpx;
		text-align: center;
		font-size: 24rpx;
		width: 130rpx;
		height: 60rpx;
		background: #004372;
		color: #fff;
		margin-bottom: 10rpx;
	}

	.cars .car-pic {
		width: 120rpx;
		height: 110rpx;
		margin-right: 20rpx;
	}

	.cars .car-info {
		display: flex;
		flex-direction: column;
		color: #999;
		font-size: 22rpx;
		width: 56%;
	}

	.cars .car-no {
		font-size: 30rpx;
		color: #333;
	}

	.cars .card-no {
		margin-top: 10rpx;
		font-size: 22rpx;
		color: #999999;
	}

	.cars .add-related {
		background-image: var(--bgimg);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: NotoSansHans, NotoSansHans;
		font-weight: 400;
		font-size: 26rpx;
		color: #CCB375;
		margin-top: 30rpx;

		.add-img {
			margin-right: 10rpx;
			width: 36rpx;
			height: 36rpx;
		}
	}


	.color {
		padding: 4rpx 8rpx;
		border-radius: 10rpx;
		color: white;
		display: inline-block;
		margin-left: 20rpx;
		font-size: 24rpx;
	}

	.loading-more {
		text-align: center;
		font-size: 28rpx;
		margin-bottom: 20rpx;
		color: #999;
	}
</style>
<style>
	page {
		background-color: #f6f9fc;
	}
</style>