<template>
	<view>
		<uni-list>
			<uni-list-item :show-extra-icon="true" :showArrow="info.authentication !== '已认证'" :extra-icon="accountIcon" title="姓名" :rightText="info.userName" clickable @click="toEditUserName" />
			<uni-list-item :show-extra-icon="true" showArrow :extra-icon="phoneIcon" title="手机号" :rightText="info.phone" clickable @click="toPage('../phone/phone')" />
		</uni-list>
		
		<view class="logout" @click="logout">退出登录</view>
	</view>
</template>

<script>
	import { viewUserDetails } from '@/apis/modules/user.js'
	export default {
		data() {
			return {
				openId: uni.getStorageSync('openId'),
				phoneIcon: {
					color: '#007eff',
					size: '22',
					type: 'phone'
				},
				accountIcon: {
					color: '#007eff',
					size: '22',
					type: 'person'
				},
				realName: '',
				info: {
					account: '',
					phone: '',
					email: ''
				},
			}
		},
		onShow() {
			this.getInfo()
		},
		methods: {
			// 个人信息
			async getInfo() {
				const { result } = await viewUserDetails({
					openId: this.openId
				})
				if (result.hrUserInfo) {
					this.info = result.hrUserInfo
				}
			},
			// 修改姓名
			toEditUserName() {
				this.info.authentication !== '已认证' && this.toPage('/team/userName/userName')
			},
			toPage(path) {
				this.$util.to(path)
			},
			// 退出登录
			logout() {
				const that = this
				uni.showModal({
					title: '提示',
					content: '确定要退出账号吗？',
					success(res) {
						if (res.confirm) {
							uni.clearStorageSync()
							that.$util.to('/pages/login/login')
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.logout {
	padding: 30rpx 0;
	margin-top: 30rpx;
	font-size: 28rpx;
	color: #333;
	text-align: center;
	background-color: #fff;
}
</style>
