<template>
	<view class="content">
		<!-- 个人信息 -->
		<view class="user-info">
			<view class="info-box">
				<view class="left justify-center align-center">
					<view class="head-box center">
						<u-avatar :src="avatar" size="50"></u-avatar>
					</view>
					<view class="info">
						<text class="name">{{nickName}}</text>
						<text class="title">{{phonenumber}}</text>
					</view>
				</view>
				<image class="right" :src="imgPath+'/app/images/icon_edit.png'" mode="aspectFill'" @click="editInfo"></image>
			</view>
			<!-- 公司 -->
			<view class="comp-info">
				<image class="img" :src="imgPath+'/app/images/icon_comp_white.png'" mode="aspectFill"></image>
				<text class="text">{{deptName}}</text>
			</view>
		</view>
		<!-- 详细信息 -->
		<view class="info-detail">
			<view class="item">
				<text class="label">姓名</text>
				<text class="text">{{nickName}}</text>
			</view>
			<view class="item">
				<text class="label">性别</text>
				<text class="text">{{sex}}</text>
			</view>
			<view class="item column" @click="callPhone(phonenumber)">
				<view class="left">
					<text class="label">手机</text>
					<text class="text">{{phonenumber}}</text>
				</view>
			</view>
			<view class="item">
				<text class="label">邮箱</text>
				<text class="text">{{email}}</text>
			</view>
			<view class="item">
				<text class="label">部门</text>
				<text class="text">{{deptName}}</text>
			</view>
			<view class="item">
				<text class="label">岗位</text>
				<text class="text">{{postNames}}</text>
			</view>
			<view class="item">
				<text class="label">角色</text>
				<text class="text">{{roleNames}}</text>
			</view>
			<view class="item justify-start align-center">
				<text class="label">二维码</text>
				<!-- <text class="text">{{postNames}}</text> -->
				<image :src="qrCodeWeixin" class="w120 h120" mode="aspectFill"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {getCompanyUser} from '@/api/manageCompany.js';
	export default {
		data() {
			return {
				avatar:this.$store.state.imgpath+"/app/images/detault_head.jpg", 
				nickName:"",
				deptName:"",
				postNames:"",
				phonenumber:"",
				email:"",
				sex:"",
				qrCodeWeixin:"",
				isShow:false,
				userId:undefined,
				roleNames:''
			}
		},
		onLoad(option) {
			// 修改顶部导航背景色
			// uni.setNavigationBarColor({
			// 	frontColor: '#ffffff',
			// 	backgroundColor: '#4BC9B1',
			// 	animation: {
			// 		duration: 400,
			// 		timingFunc: 'easeIn'
			// 	}
			// })
			
		},
		computed: {
		    imgPath() {
		      return this.$store.state.imgpath
		    }
		},
		onShow() {
			this.getCompanyUser();
		},
		methods: {
			bindUser(data){
				var that=this;
				that.nickName=data.nickName;
				that.deptName=data.companyName?data.companyName:'暂无';
				that.phonenumber=data.phonenumber?data.phonenumber:'暂无';
				if(data.posts){
					that.postNames=data.posts.map(item=>item.postName).join(",")
				}
				if(data.roles){
					this.roleNames=data.roles.map(item=>item.roleName).join(",")
				}
				// this.postNames=data.posts.map(item=>item.postName).join(",")||'暂无'
				// this.roleNames=data.roles.map(item=>item.roleName).join(",")||'暂无'
				that.email=data.email?data.email:'暂无';
				if(data.sex==0){
					that.sex="男";
				}
				else if(data.sex==1){
					that.sex="女";
				}
				else if(data.sex==2){
					that.sex="未知";
				}
				that.qrCodeWeixin=uni.getStorageSync('requestPath')+data.qrCodeWeixin
				if(data.avatar){
					that.avatar=uni.getStorageSync('requestPath')+data.avatar;
				}
			},
			getCompanyUser(){
				var data = {};
				var that=this;
				getCompanyUser(data).then(
					res => {
						that.bindUser(res.user);
					},
					rej => {}
				);
			},
			// 拨打电话
			callPhone(tel){
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			// 个人信息编辑
			editInfo() {
				uni.navigateTo({
					url: 'editUser'
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #fff;
	}
</style>
<style scoped lang="scss">
	.content{
		// 个人信息
		.user-info{
			// background: #115296;
			background: linear-gradient(to right, #dae9ff, #e1e1fd);
			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;
						color: #fff;
						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;
						.name{
							font-size: 30upx;
							color: #878787;
						}
						.title{
							font-size: 28upx;
							color: #878787;
						}
					}
				}
				.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: #878787;
				}
			}
		}
		// 详细信息
		.info-detail{
			padding: 0 24upx;
			.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: flex-start;
					align-items: flex-start;
					flex-direction: row;
					.img{
						width: 50upx;
						height: 50upx;
						margin-right: 20rpx;
					}
				}
			}
		}
	}
</style>
