<template>
	<view class="container">
    <view class="list-menu">
      <view class="list-menu-item" @click="clearCache">
        <uni-icons class="list-menu-icon" custom-prefix="iconfont" :type="clearIcon" size="20" :color="primaryColor"></uni-icons>
        <view class="text">清除缓存</view>
        <uni-icons class="list-menu-genduo" custom-prefix="iconfont" type="icon-gengduo"></uni-icons>
      </view>
      <view class="list-menu-item" @click="logoutUser">
        <uni-icons class="list-menu-icon" custom-prefix="iconfont" :type="logOutIcon" size="20" :color="primaryColor"></uni-icons>
        <view class="text">注销登录</view>
        <uni-icons class="list-menu-genduo" custom-prefix="iconfont" type="icon-gengduo"></uni-icons>
      </view>
    </view>
	</view>
</template>

<script>
	import {
		logout
	} from '@/api/auth.js'
	export default {
		data() {
			return {
        primaryColor: "#1a94bc",
        clearIcon: "icon-qingchu",
        logOutIcon: "icon-tuichu",
				userInfo:{}
			}
		},
		created() {
			// const userInfo = uni.getStorageSync('userInfo')
			// if (!userInfo) {
			// 	console.log('havent userInfo')
			// 	uni.showModal({
			// 		content: '艺术家账户过期,请重新登录！',
			// 		showCancel: false,
			// 		success() {
			// 			//没有缓存则跳转登录页面
			// 			uni.reLaunch({
			// 				url: '/pages/login/login'
			// 			});
			// 		}
			// 	});
			// } else {
			// 	this.userInfo = userInfo;
			// 	console.log('have userInfo')
			// }
		},
		methods: {
		  //清除缓存
      clearCache() {
        let that = this;
        uni.showModal({
          title: "提示",
          content: "确定清除缓存吗！",
          showCancel: true,
          success: function(ress){
            if(ress.confirm){
				uni.removeStorageSync('atlas_current');
				uni.removeStorageSync('atlas_detailId');
				uni.removeStorageSync('detailId');
				uni.showToast({
					title: '清除成功!',
					duration: 2000
				});
            }
          }
        });
      },
	
	  //注销
	  	logoutUser(){
	  		let that = this;
	  		uni.showModal({
	  		  title: "提示",
	  		  content: "确定注销吗！",
	  		  showCancel: true,
	  		  success: function(ress){
	  			  if(ress.confirm){
	  				 logout().then(res => {
	  				 	 if (res.data.code === 200) {
	  				 	   uni.reLaunch({
	  				 	   	url: '/pages/index/index',
	  						success() {
	  							uni.clearStorage();
	  							uni.showToast({
	  								title: '注销成功!',
	  								duration: 2000
	  							});
	  						}
	  				 	   });
	  				 	 } else {
	  				 	   uni.showModal({
	  				 	     content: "注销失败，请联系管理员!",
	  				 	     showCancel: false,
	  				 	   });
	  				 	 }
	  				 }); 
	  			  }
	  		  }
	  		});
	  	}
	  }
    }
			
</script>

<style lang="scss">
.container {
  padding: 20rpx;

  .list-menu {
    margin-top: 20rpx;
    padding: 0 20rpx;
    background-color: $uni-white;
    border-radius: 10rpx;
    box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.2);


  }

  .list-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 80rpx;
    line-height: 80rpx;
    border-bottom: 2rpx solid $uni-border-2;

    .list-menu-icon{
      color: $uni-primary;
    }

    .text {
      font-size: 26rpx;
      line-height: 80rpx;
      width: calc(100% - 100rpx);
    }

    .list-menu-genduo{

    }

  }

  .list-menu-item:first-child {
  }

  .list-menu-item:last-child {
    border-bottom: 0 !important;
  }

}
</style>
