<template>
	<view class="container">
		<view class="list">
			<view class="item" @click="linkTo('/pages/login/bind',true)">
				<view class="title">修改手机号</view>
				<up-icon name="arrow-right" />
			</view>
			<view class="item" @click="linkTo('/pages/me/help_center')">
				<view class="title">帮助中心</view>
				<up-icon name="arrow-right" />
			</view>
			<view class="item" @click="linkTo('/pages/me/feedback',true)">
				<view class="title">意见反馈</view>
				<up-icon name="arrow-right" />
			</view>
			<view class="item" @click="linkTo('/pages/me/agreement')">
				<view class="title">用户协议</view>
				<up-icon name="arrow-right" />
			</view>
			<view class="item" @click="linkTo('/pages/me/privacy')">
				<view class="title">隐私协议</view>
				<up-icon name="arrow-right" />
			</view>
			<view class="item" @click="outuser" v-if="token&&!isExamine">
				<view class="title">注销账号</view>
				<up-icon name="arrow-right" />
			</view>
			<view class="item" @click="logout" v-if="token">
				<view class="title">退出登录</view>
				<up-icon name="arrow-right" />
			</view>
		</view>
		<view class="version">{{ version }}</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		linkTo
	} from '@/utils/app.js';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		deleteUserByUserId
	} from '@/api/me/me.js'
	import {
		useCommonStore
	} from '@/store/common.js'
	const version = ref('');
	const token = ref('');
	let isExamine = ref(false)
	// 注销账号
	function outuser() {
		uni.showModal({
			title: '注意',
			content: '确定要注销账号吗？',
			success: async (res) => {
				if (res.confirm) {
					let userInfo = uni.getStorageSync('userInfo')
					let res = await deleteUserByUserId(userInfo.userId)
					if (res.code == 0) {
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
				}
			}
		});
	}
	// 退出登录
	function logout() {
		uni.showModal({
			title: '注意',
			content: '确定要退出登录吗？',
			success: (res) => {
				if (res.confirm) {
					uni.clearStorageSync();
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			}
		});
	}
	const $common = useCommonStore()
	onLoad(() => {
		token.value = uni.getStorageSync('token');
		const systemInfo = uni.getSystemInfoSync();
		//#ifdef APP-PLUS
		version.value = systemInfo.appWgtVersion;
		//#endif
		// #ifdef H5
		version.value = systemInfo.appVersion;
		// #endif
		$common.init()
		isExamine.value = $common.isIosExamine
	});
</script>

<style scoped lang="scss">
	.container {
		font-size: 28upx;
		color: #555;
	}

	.list {
		padding-bottom: 120upx;

		.item {
			padding: 32upx 28upx;
			border-bottom: 1upx solid #efefef;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}

	.version {
		width: 100%;
		height: 120upx;
		display: flex;
		justify-content: center;
		position: fixed;
		bottom: 0;
		left: 0;
		color: #999;
	}
</style>