<template>
	<!-- 顶部导航栏 -->
	<custom-nav-bar :left="true" leftText="" @leftClick="" title="应用设置">
	</custom-nav-bar>
	<view class="setting-container" :style="{height: `${windowHeight}px`}">
		<view class="menu-list">
			<view class="list-cell list-cell-arrow" @click="handleToPwd">
				<view class="menu-item-box">
					<view class="iconfont icon-password menu-icon"></view>
					<view>修改密码</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" @click="handleCleanTmp">
				<view class="menu-item-box">
					<view class="iconfont icon-clean menu-icon"></view>
					<view>清理缓存</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" @click="handleToUpgrade">
				<view class="menu-item-box">
					<view class="iconfont icon-refresh menu-icon"></view>
					<view>检查更新</view>
					<view style="position: absolute;color: darkgray;right: 30px;" v-if="version.newV">
						发现新版本
					</view>
					<view style="position: absolute;color: darkgray;right: 30px;" v-else>
						{{version.oldV.versionName}}
					</view>
				</view>
			</view>
		</view>
		<view class="cu-list menu">
			<view class="item-box">
				<u-button class="bg-red" type="success" size="large" text="退出登录" @click="handleLogout" />
			</view>
		</view>
		<view style="position: absolute;bottom: 5px;width: 100vw;text-align: center;color: darkgray;">
			版本 {{version.oldV.versionName}}
		</view>
	</view>
	<view>
		<uni-popup ref="popup" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="退出" title="通知" content="确定注销并退出系统吗"
				@confirm="dialogConfirm" @close="dialogClose">
			</uni-popup-dialog>
		</uni-popup>
	</view>

	<custom-app-update ref="appUpdate" />
</template>

<script setup>
	import {
		ref
	} from "vue";
	import store from '@/store'
	import plugin from "@/plugins"
	import {
		getNewAppVersion
	} from '@/api/index.js'

	const windowHeight = ref(uni.getSystemInfoSync().windowHeight);
	const version = ref(getApp().version);
	const popup = ref(null);
	const appUpdate = ref(null)

	function handleToPwd() {
		uni.navigateTo({
			url: '/pages/mine/pwd/index'
		});
	};

	function handleToUpgrade() {
		getNewAppVersion().then(res => {
			getApp().setUpdateVersion(res.data);
			version.value = getApp().version;
			if (version.value.newV) {
				appUpdate.value.show();
			}else{
				plugin.modal.showToast("已是最新版本！");
			}
		})
	};

	function handleCleanTmp() {
		uni.showToast({
			title: '模块建设中~',
			mask: false,
			icon: "none",
			duration: 1000
		});
	};

	function handleLogout() {
		popup.value.open();
	};

	function dialogConfirm() {
		//console.log('----------------点击确认------------')
		store.dispatch('LogOut').then(() => {
			uni.reLaunch({
				// url: '/pages/login'
				url: '/pages/agreement'
			});
		})
	};

	function dialogClose() {
		//console.log('点击关闭')
	};
</script>

<style lang="scss" scoped>
	.page {
		background-color: #f8f8f8;
	}

	.item-box {

		margin: 30rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding: 10rpx;
		border-radius: 8rpx;
		color: #303133;
		font-size: 32rpx;
	}
</style>