<template>
	<view class="content">
		<view class="banner custom_status_bar">
			<div class="custom-nav">个人中心</div>	
			<div class="user-container">
				<view class="avatar">
					<image v-if="user.userAvatar" class="photo" :src="user.userAvatar" mode="widthFix" @error="userAvatar=defaultAvatar"></image>
					<image v-else class="photo" :src="defaultAvatar" mode="widthFix"></image>
				</view>
				<view class="bottom">
					<view class="name">
						<text>{{user.userName}}</text>
					</view>	
					<div class="phone">{{user.userPhone}}</div>
				</view>						
			</div>
		</view>
		<view class="handle-container">
			<view class="list">
				<view class="item">
					<div class="lf">
						<image class="icon" src="/static/center/dollar-circle.png" mode="widthFix"></image>
						<text class="name">联系电话</text>
					</div>
					<view class="rt">
						<text class="cont">{{user.userPhone}}</text>
						<uni-icons type="right" size="20" color="#B3B3B3"></uni-icons>						
					</view>
				</view>
				<view class="item">
					<div class="lf">
						<image class="icon" src="/static/center/timer.png" mode="widthFix"></image>
						<text class="name">部门</text>
					</div>
					<view class="rt">
						<text class="cont">{{user.groupName}}</text>
						<uni-icons type="right" size="20" color="#B3B3B3"></uni-icons>						
					</view>
				</view>
				<view class="item">
					<div class="lf">
						<image class="icon" src="/static/center/heart.png" mode="widthFix"></image>
						<text class="name">企业通讯录</text>
					</div>
					<view class="rt">
						<text class="cont"></text>
						<uni-icons type="right" size="20" color="#B3B3B3"></uni-icons>						
					</view>
				</view>
				<view class="item">
					<div class="lf">
						<image class="icon" src="/static/center/archive-tick.png" mode="widthFix"></image>
						<text class="name">修改密码</text>
					</div>
					<view class="rt">
						<text class="cont"></text>
						<uni-icons type="right" size="20" color="#B3B3B3"></uni-icons>						
					</view>
				</view>
				<view class="item">
					<div class="lf">
						<image class="icon" src="/static/center/setting.png" mode="widthFix"></image>
						<text class="name">版本升级</text>
					</div>
					<view class="rt">
						<text class="cont">1.0.0</text>
						<uni-icons type="right" size="20" color="#B3B3B3"></uni-icons>						
					</view>
				</view>
			</view>
			<div class="logoutBt" @click="logout">退出登录</div>				
		</view>	
	</view>
</template>

<script>
	import {logout} from '@/api/system/user.js'	
	export default{
		data(){
			return{
				defaultAvatar:"/static/components/avatar.png",
				user:{
					groupName: "",
					ocName: "",
					positionName: "",
					roleName: "",
					userAvatar: "",
					userIntro: "",
					userName: "",
					userPhone: "",
					userPhoto: "",
					userRealName: ""					
				}
			}
		},	
		onShow() {
			this.init();
		},	
		methods:{			
			init(){
				let user=uni.getStorageSync('accountInfo');
				if(user){
					user=JSON.parse(user)	
					this.user=user
				}			
			},
			logout(){
				uni.showModal({
					title:'提示！',
					content:"是否要退出登录",
					success(res) {
						if (res.confirm) {
							logout().then(()=>{
								uni.clearStorageSync()
								uni.reLaunch({
									url:'/pages/login/index'
								})							
							})
						}					
					}
				})
			}			
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		 background-color: rgba(243, 244, 247, 1);
		 min-height: 100vh;
		 box-sizing: border-box;
		.banner{
			height: 422rpx;
			background-image: url('/static/center/bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			.custom-nav{
				font-size: 40rpx;
				color: #fff;
				padding-top: 24rpx;
				text-indent: 32rpx;
				/* #ifdef MP-WEIXIN */
					margin-top: 28px;
				/* #endif */
			}			
			.user-container{
				&{
					display: flex;
					justify-content: flex-start;
					align-items: center;
					padding: 46rpx 0 0 32rpx;
				}
				.avatar{
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					display: block;
					overflow: hidden;
					background: rgba(255,255,255,0.39);
					border: 2rpx solid #707070;
					.photo{
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;						
					}
				}
				.bottom{
					&{
						padding-left: 20rpx;
					}
					.name{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: bold;
						line-height: 50rpx;
						color: #FFFFFF;					
					}
					.phone{
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						line-height: 40rpx;
						color: #FFFFFF;	
						padding-top: 14rpx;
					}
				}
			}
		}
		.handle-container{
			padding: 30rpx 24rpx;
			.logoutBt{
				width: 700rpx;
				height: 72rpx;
				line-height: 72rpx;	
				text-align: center;								
				background:#fff;	
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color:rgba(110, 116, 128, 1);
				margin-top: 30rpx;
			}
			.list{
				.item{
					height: 98rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					background-color: #fff;
					padding: 0 24rpx;
					border-bottom: 1px solid rgba(238, 238, 238, 1);
					.lf{
						display: flex;
						align-items: center;
						.icon{
							width: 48rpx;
							height: 48rpx;
						}	
						.name{
							padding-left: 20rpx;
							font-size: 32rpx;
							font-family: PingFang SC;
							color: rgba(45, 49, 51, 1);
						}
					}
					.rt{
						flex: 1;
						display: flex;
						align-items: center;
						justify-content: flex-end;
						.cont{
							padding-right: 30rpx;
							font-size: 32rpx;
							font-family: PingFang SC;
							color: rgba(45, 49, 51, 1);
						}
					}
				}
			}
		}
	}
</style>
