<template>
	<view>
		<u-navbar :is-back="false" :border-bottom="false"><view class="navbar-tit">我的</view></u-navbar>
		<view class="userHead">
			<view class="userHead-left">
				<view class="userHead-name">
					<h2>{{personalInfo.realName}}</h2>
					<!-- <h2>注册/登录</h2> -->
					<view class="userHead-icon">
						<u-icon custom-prefix="custom-icon" name="shield-user-fill" color="#fff"></u-icon>
						<span v-show="personalInfo.status == 1">认证会员</span>
					</view>
				</view>
						
				<view @click="viewPersonalInfo"><p>查看/编辑个人资料</p></view>
				<!-- <view><p>登录后即可体验更多服务</p></view> -->
			</view>
			<u-avatar :src="personalInfo.faceImage" size="120"></u-avatar>
		</view>
		<view class="user-data">
			<view class="user-data-tit" @click="improvePersonalInfo">
				<h2>完善个人资料</h2><u-icon custom-prefix="custom-icon" name="youjiantou" color="#B3B3B3"></u-icon>
			</view>
			<p>添加您的个人资料、相亲简历和择偶条件，可以提高相亲成功率哦~</p>
			<u-line-progress active-color="#2979ff" :percent="personalInfoProgress" height="8" :show-percent="false"></u-line-progress>
		</view>
		<view class="user-cell">
			<view class="user-cell-item">
				<view class="user-cell-l">
					<u-icon custom-prefix="custom-icon" name="folder-user-fill" color="#FF695B" size="40"></u-icon>
					<h4>公开我的资料</h4>
				</view>
				<view class="user-cell-r">
					<u-switch v-model="personalInfo.publicNot"></u-switch>
				</view>
			</view>
			<view class="user-cell-item" @click="changePhone">
				<view class="user-cell-l">
					<u-icon custom-prefix="custom-icon" name="smartphone-fill" color="#FF695B" size="40"></u-icon>
					<h4>更换手机号</h4>
				</view>
				<view class="user-cell-r">
					<span>{{phone}}</span>
					<u-icon custom-prefix="custom-icon" name="youjiantou" color="#B3B3B3"></u-icon>
				</view>
			</view>
			<view class="user-cell-item">
				<view class="user-cell-l">
					<u-icon custom-prefix="custom-icon" name="customer-service-fill" color="#FF695B" size="40"></u-icon>
					<h4>联系客服</h4>
				</view>
				<view class="user-cell-r">
					<span>0716-8123456</span>
					<u-icon custom-prefix="custom-icon" name="youjiantou" color="#B3B3B3"></u-icon>
				</view>
			</view>
			<view class="user-cell-item" @click="agreement">
				<view class="user-cell-l">
					<u-icon custom-prefix="custom-icon" name="information-fill" color="#FF695B" size="40"></u-icon>
					<h4>服务条款</h4>
				</view>
				<view class="user-cell-r" >
					<span></span>
					<u-icon custom-prefix="custom-icon" name="youjiantou" color="#B3B3B3"></u-icon>
				</view>
			</view>
			<view class="user-cell-item" @click="logoff">
				<view class="user-cell-l">
					<u-icon custom-prefix="custom-icon" name="spam-3-fill" color="#FF695B" size="40"></u-icon>
					<h4>注销账号</h4>
				</view>
				<view class="user-cell-r">
					<p>注销后将无法使用该账号登录小程序</p>
					<u-icon custom-prefix="custom-icon" name="youjiantou" color="#B3B3B3"></u-icon>
				</view>
			</view>
			<view class="user-cell-item">
				<view class="user-cell-l" @click="logout">
					<u-icon custom-prefix="custom-icon" name="logout-box-r-fill" color="#FF695B" size="40"></u-icon>
					<h4>退出</h4>
				</view>
				<view class="user-cell-r">
					<span></span>
					<u-icon custom-prefix="custom-icon" name="youjiantou" color="#B3B3B3"></u-icon>
				</view>
			</view>
		</view>
 	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'13623239823',
				checked: false,
				personalInfo:{
					realName:'',
					publicNot:true,
					status : 0,
					faceImage:'/static/img/sexMan.png'
				},
				personalInfoProgress:0
			}
 

		},
		methods:{
			changePhone(){
				uni.navigateTo({
					url:'../../pagesA/pages/login/change'
				})
			},
			agreement(){
				uni.navigateTo({
					url:'../../pagesA/pages/login/agreement'
				})
			},
			logoff(){
				console.log('注销')
				uni.navigateTo({
					url:'./logout'
				})
			},
			logout(){
				this.carhelp.signOut()
				uni.navigateTo({
					url:'../../pagesA/pages/login/index'
				})
			},
			viewPersonalInfo(){
				uni.navigateTo({
					url:'../friend/personal?id='+this.personalInfo.id
				})
			},
			improvePersonalInfo(){
				console.log('完善个人资料')
				uni.navigateTo({
					url: '../../pagesB/pages/login/step1'
				})
			},
			calcPersonalInfoProgress(){
				if(this.personalInfo){
					let personal_info = this.personalInfo;
					let total_count = 0;
					let count = 0;
					if(personal_info)
					{
						total_count++;
						if(personal_info.birthday && personal_info.birthday.length>0){
//							console.log('已填写birthday')
							count++;
						}
						total_count++;
						if(personal_info.height != null){
//							console.log('已填写height')
							count++;
						}
						total_count++;
						if(personal_info.weight != null){
//							console.log('已填写weight')
							count++;
						}
						total_count++;
						if(personal_info.gender != null){
//							console.log('已填写gender')
							count++;
						}
						
						////
						total_count++;
						if(personal_info.birthplace && personal_info.birthplace.length>0)
						{ 
//							console.log('已填写birthplace')
							count++;
						}
						//
						total_count++;
						if(personal_info.registeredResidence  && personal_info.registeredResidence .length>0)
						{
//							console.log('已填写birthday')
							count++;
						}
						///
						total_count++;
						if(personal_info.workplace && personal_info.workplace.length>0)
						{ 
//							console.log('已填写workplace')
							count++;
						}
						
						total_count++;
						if(personal_info.education && personal_info.education.length>0)
						{ 
	//						console.log('已填写education')
							count++;
						}
						total_count++;
						if(personal_info.workUnit && personal_info.workUnit.length>0)
						{ 
//							console.log('已填写workUnit')
							count++;
						}
						total_count++;
						if(personal_info.post && personal_info.post.length>0)
						{						 		
//							console.log('已填写post')
							count++;
						}
						total_count++;
						if(personal_info.industry && personal_info.industry.length>0)
						{ 
//							console.log('已填写industry')
							count++;
						}
						total_count++;
						if(personal_info.salaryRange && personal_info.salaryRange.length>0)
						{ 
//							console.log('已填写salaryRange')
							count++;
						}
						total_count++;
						if(personal_info.housingSituation && personal_info.housingSituation.length>0)
						{ 
//							console.log('已填写housingSituation')
							count++;
						}
						total_count++;
						if(personal_info.maritalStatus && personal_info.maritalStatus.length>0)
						{ 
//							console.log('已填写maritalStatus')
							count++;
						}
						total_count++;
						if(personal_info.childStatus && personal_info.childStatus.length>0)
						{ 
//							console.log('已填写childStatus')
							count++;
						}
						total_count++;
						if(personal_info.selfEvaluation  && personal_info.selfEvaluation .length>0)
						{ 
//							console.log('已填写selfEvaluation')
							count++;
						}
						total_count++;
						if(personal_info.taAgeRange.length>0)
						{ 
//							console.log('已填写taAgeRange')
							count++;
						}
						total_count++;
						if(personal_info.taEdu && personal_info.taEdu.length>0)
						{ 				
//							console.log('已填写taEdu')
							count++;
						}
						total_count++;
						if(personal_info.taIncomeRange && personal_info.taIncomeRange.length>0)
						{ 
//							console.log('已填写taIncomeRange')
							count++;
						}
						///
						total_count++;
						if(personal_info.taWorkplace  && personal_info.taWorkplace .length>0)
						{ 
//							console.log('已填写taWorkplace')
							count++;
						}
						
						total_count++;
						if(personal_info.taOccupation && personal_info.taOccupation.length>0)
						{ 
//							console.log('已填写taOccupation')
							count++;
						}
						total_count++;
						if(personal_info.taOther && personal_info.taOther.length>0){ 
//							console.log('已填写taOther')
							count++;
						}
						total_count++;
						if(personal_info.faceImage && personal_info.faceImage.length>0)
						{
//							console.log('已填写faceImage')
							count++;
						}
//						console.log('计数'+JSON.stringify(count))
						this.personalInfoProgress = count/total_count*100;
					}
				} 
			}
			
		}, 
		onLoad(){
			 
		},
		onReady(){
			let personalInfo = this.carhelp.getPersonInfo();
			//console.log('个人信息'+JSON.stringify(personalInfo));
			this.personalInfo = personalInfo;
			if(this.personalInfo.phone != null)
			{
				let phone = this.personalInfo.phone;
				let prefix = phone.substr(0,3)
				let suffix = phone.substr(phone.length-4,4)
				this.phone = prefix +'****'+suffix;
			}
			this.calcPersonalInfoProgress();
//			console.log('xxx')
		}
	}
</script>

<style lang="scss" scoped>
	.navbar-tit{
		padding-left:15px;
		font-size: 24px;
	}
	.userHead{
		display: flex;
		justify-content: space-between;
		padding: 20px 15px;
		.userHead-left{
			.userHead-name{
				display: flex;
				align-items: center;
				h2{
					font-size: 20px;
					font-weight: normal;
				}
				.userHead-icon{
					display: flex;
					align-items: center;
					background-color: #4E8DF6;
					padding: 2px 6px;
					border-radius: 8px;
					margin-left: 20px;
					span{
						color:#fff;
						font-size: 12px;
						margin-left: 3px;
					}
				}
			}
			p{
				color:#847777;
				margin-top: 8px;
			}
		}
		
	}
	.user-data{
		margin: 15px;
		box-shadow: 0 0 6px 0 rgba(132,119,119,0.3);
		padding: 12px 16px;
		.user-data-tit{
			display: flex;
			justify-content: space-between;
			align-items: center;
			h2{
				font-weight: normal;
				font-size: 16px;
			}
		}
		p{
			color:#999;
			margin: 10px 0;
		}
	}
	.user-cell-item{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 14px 16px;
		.user-cell-l{
			display: flex;
			align-items: center;
			h4{
				font-weight: normal;
				margin-left: 8px;
			}
		}
		.user-cell-r{
			display: flex;
			align-items: center;
			span{
				color:#978E8E;
				margin-right: 4px;
			}
			p{
				font-size: 12px;
				color:#978E8E;
				margin-right: 4px;
			}
		}
	}
</style>
