<template>
	<view class="settings-page">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-btn" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<text class="header-title">设置</text>
			<view class="placeholder"></view>
		</view>

		<scroll-view scroll-y class="content">
			<!-- 设置列表 -->
			<view class="settings-list">
			<view class="setting-item" @click="goToPage('bindPhone')">
				<view class="item-left">
					<text class="item-icon">📱</text>
					<text class="item-text">绑定手机号</text>
				</view>
				<view class="item-right">
					<text class="item-value">{{ phoneNumber }}</text>
					<text class="item-arrow">›</text>
				</view>
			</view>

			<view class="setting-item" @click="goToPage('bindIdCard')">
				<view class="item-left">
					<text class="item-icon">🪪</text>
					<text class="item-text">绑定身份证号</text>
				</view>
				<view class="item-right">
					<text class="item-value">{{ idCardNumber }}</text>
					<text class="item-arrow">›</text>
				</view>
			</view>

			<view class="setting-item" @click="goToPage('educationVerify')">
				<view class="item-left">
					<text class="item-icon">🎓</text>
					<text class="item-text">学历认证</text>
				</view>
				<view class="item-right">
					<text class="item-value">{{ educationStatus }}</text>
					<text class="item-arrow">›</text>
				</view>
			</view>

			<view class="setting-item" @click="goToPage('accountSecurity')">
					<view class="item-left">
						<text class="item-icon">🛡️</text>
						<text class="item-text">账号与安全</text>
					</view>
					<view class="item-right">
						<text class="item-value">已保护</text>
						<text class="item-arrow">›</text>
					</view>
				</view>

				<view class="setting-item" @click="goToPage('privacy')">
					<view class="item-left">
						<text class="item-icon">🔒</text>
						<text class="item-text">隐私设置</text>
					</view>
					<text class="item-arrow">›</text>
				</view>

				<view class="setting-item" @click="goToPage('about')">
					<view class="item-left">
						<text class="item-icon">ℹ️</text>
						<text class="item-text">关于我们</text>
					</view>
					<text class="item-arrow">›</text>
				</view>

				<view class="setting-item logout-item" @click="handleLogout">
					<view class="item-left">
						<text class="item-icon">🚪</text>
						<text class="item-text">退出登录</text>
					</view>
					<text class="item-arrow">›</text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phoneNumber: '未绑定',
				idCardNumber: '未绑定',
				educationStatus: '未认证'
			}
		},
		onLoad() {
			this.loadUserInfo()
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			
			loadUserInfo() {
				// 获取用户信息
				const userInfo = uni.getStorageSync('userInfo')
				
				// 加载手机号
				if (userInfo && userInfo.phone) {
					this.phoneNumber = this.maskPhone(userInfo.phone)
				} else {
					this.phoneNumber = '未绑定'
				}
				
				// 加载身份证号
				if (userInfo && userInfo.idCard) {
					this.idCardNumber = this.maskIdCard(userInfo.idCard)
				} else {
					this.idCardNumber = '未绑定'
				}
				
				// 加载学历认证状态
				if (userInfo && userInfo.isEducationVerified) {
					this.educationStatus = '已认证'
				} else {
					this.educationStatus = '未认证'
				}
			},
			
			maskPhone(phone) {
				if (!phone || phone.length < 11) return phone
				return phone.substring(0, 3) + '****' + phone.substring(7)
			},
			
			maskIdCard(idCard) {
				if (!idCard || idCard.length < 8) return idCard
				return idCard.substring(0, 6) + '********' + idCard.substring(idCard.length - 4)
			},
			
		goToPage(page) {
			console.log('跳转页面:', page)
			
			if (page === 'bindIdCard') {
				// 跳转到身份证绑定页面
				uni.navigateTo({
					url: '/pages/settings/id-verification'
				})
			} else if (page === 'bindPhone') {
				// 跳转到手机号绑定页面
				uni.showToast({
					title: '功能开发中',
					icon: 'none'
				})
			} else {
				// 其他功能
				uni.showToast({
					title: '功能开发中',
					icon: 'none'
				})
			}
		},
			
			handleLogout() {
				uni.showModal({
					title: '退出登录',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							// 清除登录信息
							uni.clearStorageSync()
							
							// 跳转到登录页
							uni.reLaunch({
								url: '/pages/page3/page3'
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.settings-page {
		min-height: 100vh;
		background: #F5F5F5;
		display: flex;
		flex-direction: column;
	}

	/* 顶部导航栏 */
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25rpx 30rpx;
		padding-top: calc(25rpx + env(safe-area-inset-top));
		background: #FFFFFF;
		border-bottom: 1rpx solid #F0F0F0;
		
		.back-btn {
			width: 60rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.back-icon {
				font-size: 40rpx;
				color: #333333;
				font-weight: bold;
			}
		}
		
		.header-title {
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;
		}
		
		.placeholder {
			width: 60rpx;
		}
	}

	.content {
		flex: 1;
		background: #F5F5F5;
	}

	/* 分组标题 */
	.group-title {
		padding: 30rpx 30rpx 20rpx;
		font-size: 28rpx;
		color: #999999;
	}

	/* 设置列表 */
	.settings-list {
		background: #FFFFFF;
		
		.setting-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 35rpx 30rpx;
			border-bottom: 1rpx solid #F5F5F5;
			transition: background-color 0.2s;
			
			&:active {
				background-color: #F8F8F8;
			}
			
			&:last-child {
				border-bottom: none;
			}
			
			.item-left {
				display: flex;
				align-items: center;
				flex: 1;
				
				.item-icon {
					font-size: 40rpx;
					margin-right: 20rpx;
				}
				
				.item-text {
					font-size: 32rpx;
					color: #333333;
				}
			}
			
			.item-right {
				display: flex;
				align-items: center;
				
				.item-value {
					font-size: 28rpx;
					color: #999999;
					margin-right: 15rpx;
				}
				
				.item-arrow {
					font-size: 40rpx;
					color: #CCCCCC;
					font-weight: 300;
				}
			}
			
			.item-arrow {
				font-size: 40rpx;
				color: #CCCCCC;
				font-weight: 300;
			}
		}
	}
</style>
