<template>
	<view class="_select">
		<view class="list">
			<view class="li" @click="touser">
				<view class="title">
					个人中心
				</view>
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
			<view class="li" @click="topass">
				<view class="title">
					修改密码
				</view>
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
			<!-- <view class="li">
				<view class="title">
					聊天
				</view>
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
			<view class="li">
				<view class="title">
					通用
				</view>
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
			<view class="li">
				<view class="title">
					帮助与反馈
				</view>

				<u-icon name="arrow-right" size="20"></u-icon>
			</view> -->

			<view class="li" @click="todetail()">
				<view class="title">
					关于我们
				</view>
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
			<view class="li" @click="toGenxin" v-if='isApp'>
				<view class="title">
					当前版本
				</view>
				<view :class="update?'update':''">
					{{version}}
				</view>
			</view>
		</view>
		<view class="logout" @click="logout">
			退出登录
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				version: "1.0.50",
				update: false,
				isApp: false
			}
		},
		onShow() {
			//#ifdef APP-PLUS
			this.isApp = true
			let that = this
			this.getVersion()
			that.$api.to_http(`/basic/zhkjsysappversion/latestVersion`,
				"GET").then((res) => {
				let a = res.data.data.version.split('.')
				let b = that.version.split('.')
				console.log(a, b);
				console.log(a[0] > b[0] || a[1] > b[1] || a[2] > b[2]);
				if (a[0] > b[0] || a[1] > b[1] || a[2] > b[2]) {
					that.update = true
				}
			})
			//#endif

		},
		methods: {
			toGenxin() {
				if (!this.update) {
					return this.$refs.uToast.show({
						message: '已经是最新版本了',
						type: 'success',
					})
				}
				uni.navigateTo({
					url: '/pages/genxin/genxin'
				})
			},
			getVersion() {
				// 获取本地应用资源版本号
				plus.runtime.getProperty(plus.runtime.appid, (info) => {
					this.version = info.version;
					console.log(this.version);
				})
			},
			todetail(e) {
				uni.navigateTo({
					url: '/pages/main/set/aboutUs/aboutUs'
				})
			},
			topass() {
				uni.navigateTo({
					url: '/pages/main/set/changePassword'
				})
			},
			touser() {
				uni.navigateTo({
					url: '/pages/main/set/userinfo/userinfo'
				})
			},
			logout() {
				this.$api.to_http(`/logout`, {}, "POST").then((res) => {
					console.log(res);
					if (res.data.code == 0) {
						uni.removeStorageSync('token');
						this.$refs.uToast.show({
							message: '退出成功',
							type: 'success',
						})
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}, 800)
					}
				})
			}
		}
	}
</script>

<style scoped lang='less'>
	.logout {
		background-color: #fff;
		margin-top: 20rpx;
		text-align: center;
		padding: 10rpx;
	}

	._select {
		background: #F2F6FF;
		position: absolute;
		min-height: 100%;
		width: 100%;
		box-sizing: border-box;
	}

	._select .list {
		background-color: #fff;
		padding: 40rpx;
	}

	._select .li {
		display: flex;
		justify-content: space-between;
		margin-bottom: 40rpx;
		position: relative;

		.update::after {
			content: '';
			width: 15rpx;
			height: 15rpx;
			background: red;
			border-radius: 50%;
			position: absolute;
		}
	}
</style>