<template>
	<view class="main">
		<view class="list" v-for="(item, index) in menuList" :key="index" @click="toCommon(item.route)">
			<view class="left">
				<text class="title">{{item.title||'暂无'}}</text>
			</view>
			<view class="right">
				<text class="t-icon t-icon-tiaozhuan"></text>
			</view>
		</view>
		<view class="button">
			<button type="warn" v-if="user&&user.id" @click="toLogin('1')">退出登录</button>
			<button type="warn" v-else @click="toLogin('2')">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				user: {},
				menuList: [{
						title: "账号信息",
						route: "pagesMy/account/basic",
					},
					{
						title: "修改密码",
						route: "pagesMy/account/password",
					}
				],
			}
		},
		onLoad: async function(e) {
			const that = this;
			await that.searchToken();
		},
		methods: {
			// 用户信息
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						const user = that.$jwt(res);
						that.$set(that, `user`, user);
					}
				} catch (e) {}
			},
			// 公共跳转
			toCommon(e) {
				uni.navigateTo({
					url: `/${e}`
				})
			},
			// 登录或注销
			toLogin(type) {
				if (type == '1') {
					uni.showModal({
						title: '提示',
						content: '确定要退出登录？',
						success: function(res) {
							if (res.confirm) {
								try {
									uni.removeStorageSync('token');
								} catch (e) {}
								uni.navigateBack({
									delta: 1
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					uni.reLaunch({
						url: `/pagesHome/login/index`
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.list {
			display: flex;
			justify-content: space-between;
			padding: 3vw 2vw;
			border-bottom: 1px solid var(--f9Color);

			.left {
				display: flex;
				align-items: center;

				.title {
					margin: 0 0 0 5px;
					display: inline-block;
					font-size: var(--font14Size);
				}
			}

			.right {
				.t-icon {
					width: var(--font14Size) !important;
					height: var(--font14Size) !important;
					color: var(--f99Color) !important;
				}
			}
		}

		.button {
			margin: 3vw;
			text-align: center;

			.button {}
		}
	}
</style>