<template>
	<view>
		<uni-card>
			<!-- 	<uni-list-item title="操作手册" showExtraIcon="true" :extra-icon="list" showArrow
				to="/pages/my/updatePwd" /> -->
			<!-- <uni-list-item title="活体激活" showExtraIcon="true" :extra-icon="cameraExtraIcon" showArrow to="/pages/living/check" /> -->
			<uni-list-item title="修改密码" showExtraIcon="true" :extra-icon="extraIcon" showArrow
				to="/pages/my/updatePwd" />
			<view @click="goOut">
				<uni-list-item title="退出登录" showExtraIcon="true" :extra-icon="goOutExtraIcon" showArrow />
			</view>
		</uni-card>
	</view>
</template>

<script>
	import {
		getUser,
		getOpenid,
		setOpenid
	} from '@/common/auth.js'
	import {
		UpdatePwd,
		unbind,
		logout
	} from '@/api/my.js'

	export default {
		data() {
			return {
				list: {
					color: '#4a4a4a',
					size: '18',
					type: 'list'
				},
				cameraExtraIcon: {
					color: '#4a4a4a',
					size: '18',
					type: 'camera-filled'
				},
				extraIcon: {
					color: '#4a4a4a',
					size: '18',
					type: 'gear-filled'
				},
				goOutExtraIcon: {
					color: '#4a4a4a',
					size: '18',
					type: 'close'
				}
			}
		},
		methods: {
			goOut() {
				uni.showModal({
					title: '提示',
					content: '是否退出登录',
					cancelText: '取消',
					confirmText: '确定',
					success: function(response) {
						if (response.confirm) {
							uni.showLoading({
								title: '正在退出中...',
								mask: true,
							})
							const user = getUser()
							const {
								accountType
							} = user
							if (accountType === '0') {
								unbind().then(res => {
									console.log(res);
									logout().then(resp => {
										let openId = getOpenid();
										uni.clearStorageSync()
										setOpenid(openId)
										uni.hideLoading()
										uni.showToast({
											icon: 'none',
											title: '退出成功'
										})
										setTimeout(function() {
											let url = window.location.href;
											//页面授权之后退出再清空openId登录code不刷新问题
											if (url.indexOf("?") !== -1 && url.indexOf(
													"code") !== -1) {
														
												const urlWithoutQuery = url.split('?')[0];
												console.log(urlWithoutQuery,'<---------urlWithoutQuery')
												window.location.href = urlWithoutQuery
											} else {
												uni.reLaunch({
													url: '/pages/login/index'
												})
											}
										}, 1000)
									})
								})
							} else {
								logout().then(resp => {
									let openId = getOpenid();
									uni.clearStorageSync()
									setOpenid(openId)
									uni.hideLoading()
									uni.showToast({
										icon: 'none',
										title: '退出成功'
									})
									setTimeout(function() {
										let url = window.location.href;
										//页面授权之后退出再清空openId登录code不刷新问题
										if (url.indexOf("?") !== -1 && url.indexOf("code") !==
											-1) {
												
											const urlWithoutQuery = url.split('?')[0];
											console.log(urlWithoutQuery,'<---------urlWithoutQuery')
											window.location.href = urlWithoutQuery
										} else {
											uni.reLaunch({
												url: '/pages/login/index'
											})

										}
									}, 1000)
								})
							}

						}
					}
				})

			}
		}
	}
</script>

<style>
</style>