<template>
	<view class="content">
		<!-- 个人信息 -->
		<view class="user-info">
			<view class="info-box">
				<view class="left">
					<view class="head-box">
						<image class="img" :src="avatar" mode="aspectFill"></image>
					</view>
					<view class="info">
						<text class="name">{{nickName}}</text>
						<text class="title">{{postNames}}</text>
					</view>
				</view>
				<image  class="right" src="@/static/image/my/icon_edit.png" mode="aspectFill" @click="editInfo"></image>
			</view>
		
		</view>
		<!-- 详细信息 -->
		<view class="info-detail">
			<view class="item">
				<text class="label">姓名</text>
				<text class="text">{{nickName}}</text>
			</view>
			<view class="item" @click="callPhone(phonenumber)">
				<!-- <view class="left"> -->
					<text class="label">手机</text>
					<text class="text">{{phonenumber}}</text>
				<!-- </view>
				<image class="img" src="/static/images/icon_phone_left.png" mode="aspectFill"  ></image> -->
			</view>
			<view class="item">
				<text class="label">性别</text>
				<text class="text">{{sex}}</text>
			</view>
			<view class="item">
				<text class="label">邮箱</text>
				<text class="text">{{email}}</text>
			</view>

		</view>
	</view>
</template>

<script>
	import {getUserInfoByUserId,getUserInfo} from '@/api/user.js';
	export default {
		data() {
			return {
				avatar:"/static/images/detault_head.jpg", 
				nickName:"",
				deptName:"",
				postNames:"",
				phonenumber:"",
				email:"",
				sex:"",
				isShow:false,
				userId:undefined,
			}
		},
		onLoad(option) {
			// 修改顶部导航背景色
			// uni.setNavigationBarColor({
			// 	frontColor: '#ffffff',
			// 	backgroundColor: '#FF5C03',
			// 	animation: {
			// 		duration: 400,
			// 		timingFunc: 'easeIn'
			// 	}
			// });
			if(!this.$isEmpty(option.userId)){
				this.userId = option.userId;
				this.isShow=true;
			}
			
		},
		onShow() {
			this.getUserInfo();
		},
		methods: {
			bindUser(data){
				var that=this;
				that.nickName=data.user.nickName;
				that.phonenumber=data.user.phone;
				that.email=data.user.email;
				if(data.user.sex==0){
					that.sex="男";
				}
				else if(data.user.sex==1){
					that.sex="女";
				}
				else if(data.user.sex==2){
					that.sex="未知";
				}
				if(!that.$isEmpty(data.user.avatar)){
					that.avatar=data.user.avatar;
				}
			},
			getUserInfoByUserId(userId){
				var data = {userId:userId};
				var that=this;
				getUserInfoByUserId(data).then(
					res => {
						that.bindUser(res);
						
					},
					rej => {}
				);
			},
			getUserInfo(){
				var data = {};
				var that=this;
				getUserInfo(data).then(
					res => {
						that.bindUser(res);
					},
					rej => {}
				);
			},
			// 拨打电话
			callPhone(tel){
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			// 个人信息编辑
			editInfo() {
				uni.navigateTo({
					url: './editUser'
				})
			}
		}
	}
</script>


<style scoped lang="scss">
	page{
		background: #fff;
	}
	.content{
		background: #fff;
		// 个人信息
		.user-info{
			background: #f7f7f7;
			padding: 0 30upx;
			.info-box{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.left{
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 20upx 0;
					.head-box{
						width: 120upx;
						height: 120upx;
						line-height: 100upx;
						font-size: 30upx;
						text-align: center;
						margin-right: 20upx;
						.img{
							border-radius: 50%;
							width: 100%;
							height: 100%;
						}
					}
					.info{
						height: 80upx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						color: #333;
						.name{
							font-size: 30upx;
						}
						.title{
							font-size: 28upx;
						}
					}
				}
				.right{
					width: 40upx;
					height: 40upx;
				}
			}
			.comp-info{
				padding: 20upx 0 40upx;
				display: flex;
				align-items: center;
				.img{
					width: 30upx;
					height: 30upx;
					margin-right: 20upx;
				}
				.text{
					font-size: 30upx;
					color: #fff;
				}
			}
		}
		// 详细信息
		.info-detail{
			padding: 0 24upx;
			margin-top: 20rpx;
			.item{
				padding: 20upx 0;
				border-bottom: 1px solid #f7f7f7;
				.label{
					font-size: 30upx;
					color: #999;
					margin-right: 20upx;
				}
				.text{
					font-size: 30upx;
					color: #333;
				}
				&.column{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.img{
						width: 50upx;
						height: 50upx;
					}
				}
			}
		}
	}
</style>
