<template>
	<view class="container">
		<view class="user-box">
			<view class="icon-name-box">
				<view class="icon-box">
					<cover-image class="icon" :src="`/static/chat-icon/${user.icon}.png`"></cover-image>
				</view>
				<view class="name-box">
					<view class="name" v-if="isLogin">
						<view class="text">
							{{user.username}}
						</view>
						<view class="iconfont icon-xiugai"></view>
					</view>
					<view class="function" v-else>
						<view class="function-item">
							登录
						</view>/
						<view class="function-item">
							注册
						</view>
					</view>
				</view>
			</view>
			<view class="info-box">
				<view class="info-item-box">
					<view class="label">
						任职机构:
					</view>
					<view class="text">
						{{isLogin ? user.employment : ''}}
					</view>
				</view>
				<view class="info-item-box">
					<view class="label">
						机构备案证号:
					</view>
					<view class="text">
						{{isLogin ? user.recordCertificateNumber : ''}}
					</view>
				</view>
			</view>
		</view>
		<view class="certificate-box">
			<view class="title-box">
				我的证明
			</view>
			<view class="list-box">
				<view class="list-item-box" @click="onShowCreditCard(creditCard.id)">
					<CreditCard :isLogin="isLogin" :data="creditCard" @guide="onCreditCardGuideClick()"></CreditCard>
				</view>
				<view class="list-item-box" :class="[isLogin ? (user.zhongjierenzheng ? 'zhongjie-back' : 'zhongjie-back-zhiyin') : 'zhongjie-back-login']" @click="onZhongJieRenZhengClick(user.zhongjierenzheng)">
				</view>
				<view class="list-item-box" :class="[isLogin ? (user.anjierenzheng ? 'anjie-back' : 'anjie-back-zhiyin') : 'anjie-back-login']" @click="onAnJieRenZhengClick(user.anjierenzheng)">
				</view>
			</view>
		</view>
		<u-popup v-model="showCreditCard" mode="center">
			<view class="certificate-preview-box">
				<CreditCard :isLogin="isLogin" size="normal red" :data="creditCard"></CreditCard>
			</view>
		</u-popup>
		<view class="menu-box">
			<view class="menu-item-box" @click="onHuiFeiJiaoJiao()">
				<view class="icon-box">
					<view class="iconfont icon-qianbi"></view>
				</view>
				<view class="content-box">
					会缴缴交
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
			<view class="menu-item-box" @click="onWoDeDingDan()">
				<view class="icon-box">
					<view class="iconfont icon-dingdan"></view>
				</view>
				<view class="content-box">
					我的订单
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
			<view class="menu-item-box">
				<view class="icon-box">
					<view class="iconfont icon-xiazai"></view>
				</view>
				<view class="content-box">
					视频缓存
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
			<view class="menu-item-box">
				<view class="icon-box">
					<view class="iconfont icon-shoucang"></view>
				</view>
				<view class="content-box" @click="onWoDeShouChang()">
					我的收藏
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
			<view class="menu-item-box" @click="onChangJianWenTi()">
				<view class="icon-box">
					<view class="iconfont icon-anquan"></view>
				</view>
				<view class="content-box">
					常见问题
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
			<view class="menu-item-box" @click="onLianXiWoMen()">
				<view class="icon-box">
					<view class="iconfont icon-yonghuzu"></view>
				</view>
				<view class="content-box">
					联系我们
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
			<view class="menu-item-box">
				<view class="icon-box">
					<view class="iconfont icon-shezhi"></view>
				</view>
				<view class="content-box">
					退出/切换账号
				</view>
				<view class="suffix-box">
					<view class="iconfont icon-chevron-right"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import CreditCard from '@/components/creditCard.vue'
	
	import { ref, computed } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import { getToken } from '@/utils/auth.js'
	
	// 用户信息
	const user = ref({
		icon: 'jiaoyu',
		username: '某某某',
		employment: '广州市xx地产有限公司',
		recordCertificateNumber: '123xxxx',
		zhongjierenzheng: true, // 中介认证
		anjierenzheng: true // 按揭认证
	})
	
	// 是否预览信用信息卡
	const showCreditCard = ref(false)
	// 信用信息卡
	const creditCard = ref({
		id: '1',
		number: 'GZ2028000001',
		name: '彭于晏',
		time: '2018年6月22日',
		publisher: '广州市住房和城乡建设委员会',
		photo: 'https://ok.166.net/reunionpub/1_20210628_17a5105e667995566.jpeg',
		qrCode: '/static/images/zhengshu/qrCode.png'
	})
	function onShowCreditCard(valid) {
		showCreditCard.value = false
		if (isLogin.value &&  valid) {
			showCreditCard.value = true
		}
	}
	// 信息信用卡-点击指引
	function onCreditCardGuideClick() {
		console.log('点击-信息信用卡指引');
	}
	// 中介认证点击
	function onZhongJieRenZhengClick(valid) {
		if (!isLogin.value) {
			return
		}
		if (valid) {
			uni.navigateTo({
				url: '/pages/certificateDetail/certificateDetail?type=zhongjie&title=广州市房地产中介从业人员水平认证证书'
			})
		} else {
			console.log('跳转中介认证报名指引');
		}
	}
	// 按揭认证点击
	function onAnJieRenZhengClick(valid) {
		if (!isLogin.value) {
			return
		}
		if (valid) {
			uni.navigateTo({
				url: '/pages/certificateDetail/certificateDetail?type=anjie&title=广州市房地产按揭从业人员水平认证证书'
			})
		} else {
			
		}
	}
	
	// 点击-会费缴交
	function onHuiFeiJiaoJiao() {
		uni.navigateTo({
			url: '/pages/huiFeiJiaoJiao/huiFeiJiaoJiao'
		})
	}
	// 点击-我的订单
	function onWoDeDingDan() {
		uni.navigateTo({
			url: '/pages/order/order'
		})
	}
	// 点击-我的收藏
	function onWoDeShouChang() {
		uni.navigateTo({
			url: '/pages/collect/collect'
		})
	}
	// 点击-常见问题
	function onChangJianWenTi() {
		console.log('点击-常见问题');
	}
	// 点击-联系我们
	function onLianXiWoMen() {
		console.log('点击-联系我们');
	}
	
	const isLogin = computed(() => {
		return true
		// return getToken() ? true : false
	})
	
	onLoad(() => {
	})
</script>

<style lang="scss" scoped>
	$certificate-width: 220rpx;
	$certificate-height: 300rpx;
	.container {
		height: 100vh;
		width: 100vw;
		padding: 0 20rpx;
		background: rgb(141, 204, 255);
		background: -moz-linear-gradient(   90deg, rgb(141, 204, 255) 10%, rgb(247, 247, 247) 30%);
		background: -webkit-linear-gradient(90deg, rgb(141, 204, 255) 10%, rgb(247, 247, 247) 30%);
		background: -o-linear-gradient(     90deg, rgb(141, 204, 255) 10%, rgb(247, 247, 247) 30%);
		background: -ms-linear-gradient(    90deg, rgb(141, 204, 255) 10%, rgb(247, 247, 247) 30%);
		background: linear-gradient(       180deg, rgb(141, 204, 255) 10%, rgb(247, 247, 247) 30%);
		
		.user-box { 
			padding: 0 40rpx;
			.icon-name-box {
				display: flex;
				align-items: center;
				gap: 30rpx;
				margin-bottom: 15rpx;
				.icon-box {
					width: 90rpx;
					height: 90rpx;
					background-color: #fff;
					border-radius: 50%;
					overflow: hidden;
					-webkit-box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(168, 221, 239, 0.75);
					-moz-box-shadow:    0rpx 0rpx 10rpx 0rpx rgba(168, 221, 239, 0.75);
					box-shadow:         0rpx 0rpx 10rpx 0rpx rgba(168, 221, 239, 0.75);
					.icon {
						height: 100%;
						width: 100%;
						object-fit: cover;
					}
				}
				.name-box {
					font-size: $uni-title-font-size-1;
					letter-spacing: 5rpx;
					
					.name {
						display: flex;
						gap: 5rpx;
						.iconfont {
							font-size: $uni-font-size-3;
						}
					}
					.function {
						display: flex;
						gap: 5rpx;
					}
				}
			}
			.info-box {
				.info-item-box {
					display: flex;
					align-items: center;
					gap: 10rpx;
					margin-bottom: 10rpx;
					font-size: $uni-font-size-1;
					font-weight: bold;
					letter-spacing: 3rpx;
				}
			}
		}
		
		.certificate-box {
			padding: 0 20rpx;
			margin-top: 20rpx;
			.title-box {
				font-size: $uni-title-font-size-3;
				font-weight: bold;
			}
			.list-box {
				padding: 20rpx 50rpx;
				width: 100%;
				display: flex;
				gap: 130rpx;
				
				overflow-x: scroll;
				overflow-y: hidden;
				white-space:nowrap;
				
				.list-item-box {
					flex-shrink: 0;
					height: $certificate-height;
					width: $certificate-width;
					background-color: #fff;
					
					&:nth-child(1) {
						background-color: #fff;
					}
				}
				
				.zhongjie-back {
					@include backgroundImg('/static/images/zhengshu/zhongjie-back.png')
				}
				.zhongjie-back-login {
					@include backgroundImg('/static/images/zhengshu/zhongjie-back-login.png')
				}
				.zhongjie-back-zhiyin {
					@include backgroundImg('/static/images/zhengshu/zhongjie-back-zhiyin.png')
				}
				.anjie-back {
					@include backgroundImg('/static/images/zhengshu/anjie-back.png')
				}
				.anjie-back-login {
					@include backgroundImg('/static/images/zhengshu/anjie-back-login.png')
				}
				.anjie-back-zhiyin {
					@include backgroundImg('/static/images/zhengshu/anjie-back-zhiyin.png')
				}
			}
		}
		
		.certificate-preview-box {
			height: 65vh;
			width: 75vw;
		}
		
		.menu-box {
			padding: 20rpx 20rpx;
			margin: 10rpx 0;
			background-color: #fff;
			width: 100%;
			border-radius: $uni-card-border-radius;
			
			-webkit-box-shadow: 0px 0px 12rpx 0px rgba(50, 50, 50, 0.25);
			-moz-box-shadow:    0px 0px 12rpx 0px rgba(50, 50, 50, 0.25);
			box-shadow:         0px 0px 12rpx 0px rgba(50, 50, 50, 0.25);
			
			.menu-item-box {
				height: 100rpx;
				font-size: $uni-font-size-1;
				padding:  10rpx;
				display: flex;
				gap: 10rpx;
				align-items: center;
				border-radius: $uni-card-border-radius;
				&:active {
					background-color: $uni-bg-color-hover;
				}
				.icon-box {
					width: 5%;
					font-weight: bold;
				}
				.content-box {
					width: 75%;
					letter-spacing: 3rpx;
				}
				.suffix-box {
					width: 20%;
					text-align: right;
				}
			}
		}
	}
</style>
