<template>
	<view class="page">
		<view class="header">
			<view class="user">
				<image class="avatar" :src="headLogo || '../../static/head.png'" />
				<text> {{displayName}} </text>
			</view>
		</view>
		<view class="menu">
			<view class="item" @click="handleMenuClick">
				<img src="/static/appstore-add.png"></img>
				<view>编辑中心</view>
			</view>
			<view class="item" @click="dialogToggle('success')">
				<img src="/static/poweroff.png"></img>
				<view>退出登录</view>
			</view>
			<uni-popup ref="alertDialog" type="dialog">
				<uni-popup-dialog :type="msgType" cancelText="否" confirmText="是" title="提示" content="是否退出登录"
					@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				headLogo: '',
				nameList: ''
			}
		},
		created() {
			// this.wechatId = uni.getStorageSync('wechatId');
			this.headLogo = uni.getStorageSync('headLogo');
			// this.nameList = uni.getStorageSync('nameList');
			//this.getData()
		},
		computed: {
			displayName: function() {
				if (this.nameList) {
					return this.nameList;
				} else {
					return '编号00001';
				}
			}
		},
		onLoad() {

		},
		methods: {
			onPullDownRefresh() {
				this.getData();
				setTimeout(function() {
					uni.stopPullDownRefresh(); //停止下拉刷新动画
				}, 1000);
			},
			getData() {
				this.$http('homePage.information', {}, '加载中').then((res) => {
					this.nameList = res.data.userName;
				})
			},
			//退出登录
			dialogToggle(type) {
				this.msgType = type
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				uni.removeStorageSync('token'); // 清除缓存中的 token
				uni.removeStorageSync('headLogo');
				uni.removeStorageSync('wechatId');
				uni.removeStorageSync('nameList');
				uni.reLaunch({
					url: '/subpkg/pages/login/index',
					success: () => {
						setTimeout(() => {
							this.$refs.alertDialog.open();
						}, 1000);
					}
				});
			},
			dialogClose() {
				console.log('点击关闭')
			},
			handleMenuClick() {
				// uni.navigateTo({
				// 	url: '/pages/home/home'
				// });
			}
		}
	}
</script>

<style lang="scss">
	.page {
		background: #f5f5f5;
		min-height: 100vh;

		.header {
			background: #90ffe4;
			height: 300rpx;

			.user {
				display: flex;
				flex-direction: column;
				align-items: center;

				image {
					width: 150rpx;
					height: 150rpx;
					border-radius: 50%;
					margin: 10rpx;
					background: #ccc;
				}

				text {
					color: #000;
					font-size: 25rpx;
					margin-top: 15rpx;
				}
			}
		}


		.menu {
			background: #fff;

			.item {
				border-bottom: 1px solid #f0f0f0;
				display: flex;
				height: 80rpx;
				align-items: center;
				padding: 0 20rpx;
				box-sizing: border-box;
				width: 750rpx;

				&:active {
					background: #f0f0f0;
				}

				image {
					height: 40rpx;
					width: 40rpx;
				}

				view {
					font-size: 14px;
					color: #444;
					padding-left: 10rpx;
					box-sizing: border-box;
					width: calc(100% - 70rpx);
				}

				.arrow {
					width: 30rpx;
					height: 36rpx;
				}
			}
		}


	}
</style>