<template>
	<view>
		<view style="color: #fff;">
			<tn-nav-bar :bottomShadow="false" backgroundColor="#26B3A0">账号安全</tn-nav-bar>
			<view :style="{height: tobheight+'px'}"></view>
		</view>
		<view class="user">
			<!-- 用户功能 -->
			<view class="com-item">
				<view class="com-wrap">
					<navigator class="cell" v-for="(item, index) in userList" :key="index"
						:url="hasLogin ? item.url : '/pages/user/signin'" @click="getroute">
						<view class="cell-left">
							<u-icon :name="item.icon"
								:color="item.icon=='grid-fill'?'rgb(255, 202, 40)':item.icon=='question-circle-fill'?'rgb(49, 201, 232)':item.icon=='setting-fill'?'rgb(90, 199, 37)':'#26B3A0'"
								size="22"></u-icon>
							<view class="cell-text">{{ item.title }}</view>
						</view>
						<u-icon name="arrow-right" color="#9e9e9e" size="18"></u-icon>
					</navigator>
				</view>
			</view>

		</view>
		<view @click="destroyAccount()" hover-class="hoversubmit" class="signinnow">注销账号
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import {
		loginOut
	} from '@/api/my/index.js'
	export default {
		data() {
			return {
				tobheight: 45,
				platform: this.$platform.get(),


				userList: [{
						title: '更换手机号',
						icon: 'phone-fill',
						path: 'collect-list',
						url: '/pages/user/accountSafe/updateMobile/index',
					},
					{
						title: '修改密码',
						icon: 'lock-fill',
						path: 'collect-list',
						url: '/pages/user/accountSafe/updatePwd/index?from=set'
					}
				],
			}
		},
		computed: {
			...mapGetters(['hasLogin'])
		},
		onLoad() {

		},
		methods: {
			async destroyAccount() {
				let res = await loginOut()
				console.log('注销账号返回值', res);
				if (res.code == 0) {
					uni.clearStorageSync()
					uni.showToast({
						title: '注销账号成功',
						icon: 'success',
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/user/signin'
						})
					}, 1500)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	@import './index.scss';
</style>