<template>
	<view class="container">
		<view class="header">
			<text class="title">我的</text>
		</view>
		
		<view class="user-info" v-if="userInfo">
			<image class="avatar" :src="userInfo.avatarUrl || '/static/default-avatar.png'" mode="aspectFill"></image>
			<text class="nickname">{{ userInfo.nickName || '未登录' }}</text>
		</view>
		
		<view class="login-section" v-if="!userInfo">
			<button class="login-btn" @click="wxLogin" open-type="getUserInfo" @getuserinfo="getUserInfo">
				微信登录
			</button>
		</view>
		
		<view class="menu-list">
			<view class="menu-item" @click="navigateTo('/pages/profile/settings')">
				<text class="menu-text">设置</text>
				<text class="menu-arrow">></text>
			</view>
			<view class="menu-item" @click="navigateTo('/pages/profile/about')">
				<text class="menu-text">关于我们</text>
				<text class="menu-arrow">></text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: null
		}
	},
	onLoad() {
		this.checkLogin()
	},
	methods: {
		checkLogin() {
			// 检查是否已登录
			const userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				this.userInfo = userInfo
			}
		},
		
		wxLogin() {
			uni.login({
				provider: 'weixin',
				success: (res) => {
					console.log('登录成功', res)
					// 这里应该调用后端接口获取用户信息
				},
				fail: (err) => {
					console.error('登录失败', err)
					uni.showToast({
						title: '登录失败',
						icon: 'none'
					})
				}
			})
		},
		
		getUserInfo(e) {
			if (e.detail.userInfo) {
				this.userInfo = e.detail.userInfo
				uni.setStorageSync('userInfo', e.detail.userInfo)
			}
		},
		
		navigateTo(url) {
			uni.navigateTo({ url })
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	background: linear-gradient(135deg, #FF8A80 0%, #FFB6C1 25%, #FECFEF 50%, #F8BBD9 100%);
	min-height: 100vh;
}

.user-info {
	background: rgba(255, 255, 255, 0.95);
	backdrop-filter: blur(20rpx);
	margin: 20rpx 30rpx;
	border-radius: 24rpx;
	padding: 40rpx 30rpx;
	display: flex;
	align-items: center;
	box-shadow: 0 8rpx 32rpx rgba(255, 138, 128, 0.2);
	border: 1rpx solid rgba(255, 255, 255, 0.3);

	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 60rpx;
		margin-right: 30rpx;
		box-shadow: 0 4rpx 16rpx rgba(255, 138, 128, 0.2);
	}

	.nickname {
		font-size: 32rpx;
		font-weight: 600;
		color: #FF8A80;
	}
}

.login-section {
	background: rgba(255, 255, 255, 0.95);
	backdrop-filter: blur(20rpx);
	margin: 20rpx 30rpx;
	border-radius: 24rpx;
	padding: 40rpx 30rpx;
	box-shadow: 0 8rpx 32rpx rgba(255, 138, 128, 0.2);
	border: 1rpx solid rgba(255, 255, 255, 0.3);

	.login-btn {
		background: linear-gradient(135deg, #FF8A80 0%, #FFB6C1 100%);
		color: white;
		border-radius: 24rpx;
		font-size: 32rpx;
		box-shadow: 0 4rpx 16rpx rgba(255, 138, 128, 0.4);
		border: none;
	}
}

.menu-list {
	background: rgba(255, 255, 255, 0.95);
	backdrop-filter: blur(20rpx);
	margin: 20rpx 30rpx;
	border-radius: 24rpx;
	box-shadow: 0 8rpx 32rpx rgba(255, 138, 128, 0.2);
	border: 1rpx solid rgba(255, 255, 255, 0.3);
	overflow: hidden;

	.menu-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 40rpx 30rpx;
		border-bottom: 1rpx solid rgba(255, 255, 255, 0.3);
		transition: all 0.3s ease;

		&:last-child {
			border-bottom: none;
		}

		&:active {
			background: rgba(255, 138, 128, 0.1);
		}

		.menu-text {
			font-size: 30rpx;
			color: #333333;
			font-weight: 500;
		}

		.menu-arrow {
			font-size: 28rpx;
			color: #FF8A80;
			font-weight: 600;
		}
	}
}
</style>
