<template>
	<view class="safe-manage">
		<custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
		<view class="content">
			<!-- <navigator url="../address-manage/address-manage" class="app-item">
				<text>地址管理</text>
				<text class="cuIcon-right"></text>
			</navigator> -->
			<!-- <navigator url="../updata-psw/updata-psw" class="app-item">
				<text>修改密码</text>
				<text class="cuIcon-right"></text>
			</navigator> -->
			<navigator url="../change-phone/change-phone" class="app-item">
				<text>手机换绑</text>
				<text class="cuIcon-right"></text>
			</navigator>
			<view class="app-item" @tap="logout">
				<text>退出登录</text>
				<text class="cuIcon-right"></text>
			</view>
			<!-- <navigator url="../apply-return/apply-return" class="app-item">
				<text>申请退货</text>
				<text class="cuIcon-right"></text>
			</navigator> -->
		</view>
	</view>
</template>

<script>
	import {
		_API_Logout
	} from '@/apis/verify.js'
	export default {
		data() {
			return {
				title: '安全中心'
			}
		},
		methods: {
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								mask: true
							})
							_API_Logout().then(() => {
								if (this.$store.state.app.token) {
									this.$store.commit('app/LOGOUT')
									// window.history.replaceState({}, '', '/api/gzh/#/pages/login-reg/login-reg')
									// location.reload()
									this.toWxchatLogin("/pages/login-reg/login-reg", null)
								} else {
									this.$store.commit('app/LOGOUT')
									this.toWxchatLogin("/pages/login-reg/login-reg", null)
								}
							})
						}
					}
				})
			},
			toWxchatLogin(url, state) {
				url = url || "/pages/index/index"
				state = state || "cli"
				const redirect_uri = encodeURIComponent(`${this.$config.redirect_uri}/api/gzh#${url}`)
				const auth = () => window.location.href =
					`${this.$config.wxURL}?appid=${this.$config.appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`
				auth()
			},
		}
	}
</script>

<style lang="scss">
	.safe-manage {
		@include page();
	}
</style>
