<template>
	<view class="setting-page">
		<view class="content">
			<view class="info-item" @click="toChangePassword">
				<view class="label">修改密码</view>
				<view class="right">
					<image class="w36 h36" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_my_more.png" mode=""></image>
				</view>
			</view>
			<view class="info-item">
				<view class="label">版本号</view>
				<view class="right">v{{ version }}</view>
			</view>
		</view>
		<view class="btn-box">
			<view class="logout-btn" @click="handleLogout">退出登录</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				version: "1.0"
			}
		},
		onLoad() {
			this.getVersion()
		},
		methods: {
			getVersion() {
				try {
					const accountInfo = wx.getAccountInfoSync()
					this.version = accountInfo.miniProgram.version || "1.0"
				} catch (error) {
					console.warn('获取版本号失败:', error)
				}
			},
			
			handleLogout() {
				uni.showModal({
					title: "提示",
					content: "确认退出登录吗?",
					confirmText: '确定',
					success: (res) => {
						if (res.confirm) {
							this.logout()
						}
					}
				})
			},
			toChangePassword(){
				uni.navigateTo({
					url: '/pages/auth/changePassword'
				})
			},
			logout() {
				// 清除登录相关存储
				uni.removeStorageSync('CompanyUserToken')
				uni.removeStorageSync('AppToken')
				uni.removeStorageSync('userInfo')
				
				// 通知其他页面更新登录状态
				uni.$emit('refreshLogin')
				
				// 跳转到登录页
				uni.navigateTo({
					url: '/pages/auth/login'
				})
			}
		}
	}
</script>

<style lang="scss">
	.setting-page {
		background: #ffffff;
		min-height: 100vh;
		
		.content {
			background: #ffffff;
		}
		
		.info-item {
			height: 104upx;
			padding: 0 30upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1px solid #F5F6FA;
			
			&:last-child {
				border-bottom: none;
			}
			
			.label {
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #0F1826;
			}
			
			.right {
				display: flex;
				align-items: center;
				justify-content: center;
			}
			
			.w36 {
				width: 36upx;
				height: 36upx;
			}
		}
		
		.btn-box {
			padding: 40upx 30upx;
			
			.logout-btn {
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-family: PingFang SC;
				font-size: 32upx;
				color: #333333;
				background: #F7F8FA;
				border-radius: 44upx;
			}
		}
	}
</style>