<template>
	<view class='set-page'>
		<view class='set-main'>
			<view class='main-line'>
				<view class='line-item' @click='getProtol'>
					<view class='item-text'>相关协议</view>
					<view class='item-icon'></view>
				</view>
				<view class='line-item' @click='cancelSize'>
					<view class='item-text'>清除缓存</view>
					<view class='item-r'>
						<view class='r-text'>{{cacheSize}}</view>
						<i class='r-icon'></i>
					</view>
				</view>
				<view class='line-item'>
					<view class='item-text'>当前版本</view>
					<view class='item-version'>{{versionNumber}}</view>
				</view>
			</view>
			<view  v-show="token!=''">
				<view class='line-des'>
					如果您今后不打算使用APP，您可以选择
					<view class='des-x' @click='goCancel'>注销账号</view>
				</view>
				<view  class='line-tips' >注：该操作不可恢复</view>
			</view>
			
		</view>
		<view  v-show="token!=''" class='set-footer' @click='goOut'>退出登录</view>
		<!-- 注销 -->
		<view :hidden="userFeedbackHidden" class="popup_content">
					<view class="popup_title">提示</view>
					<view class='popup_main'>
						您一但确认注销，您所有信息都会被清除，您确认注销账号？
					</view>
					<view class='btn-main'>
						<view class='btn-confirm' @click='cancelAccount()'>
							确认
						</view>
						<view class='btn-cel' @click="hideDiv()" >
							取消			 
						</view>
					</view>
		</view>
		<view class="popup_overlay" :hidden="userFeedbackHidden" ></view>
		
		<!-- 退出 -->
		<view :hidden="outHidden" class="popup_content">
					<view class="popup_title">提示</view>
					<view class='popup_main'>
						您确定退出登录吗？
					</view>
					<view class='btn-main'>
						<view class='btn-confirm' @click='loginOut()'>
							确认
						</view>
						<view class='btn-cel' @click="loginCel()" >
							取消
						</view>
					</view>
		</view>
		<view class="popup_overlay" :hidden="outHidden" ></view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userFeedbackHidden:true,//弹窗
				outHidden:true,
				protocolList:[],
				versionNumber:'',
				cacheSize:'',
				token:''
			}
		},
		onLoad() {
			let self = this;
			self.init()
			self.token=uni.getStorageSync('token')
			plus.cache.calculate(size => {
				if (size < 1024) {
						self.cacheSize = size + 'B';
				} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
						self.cacheSize = Math.floor((size / 1024) * 100) / 100 + 'KB';
				} else if (size / 1024 / 1024 >= 1) {
						self.cacheSize = Math.floor((size / 1024 / 1024) * 100) / 100 + 'M';
				}
				console.log(self.cacheSize,'size')
			});
			plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo){
					if(wgtinfo.version){
						self.versionNumber = wgtinfo.version;
					}else{
						self.versionNumber = plus.runtime.version;
					}
					console.log(self.versionNumber,'version')
			});
		},
		methods: {
			init(){
				const self=this
				self.$request('/pawn/setting','GET').then(res => {
				
					const { protocol,phone }=res.result
					if(protocol){
						self.protocolList=JSON.parse(protocol)
					}
				}).catch(err=>{
				  console.log(err,'请求出错')
				})
			},
			cancelSize(){
								
				let self = this;
				plus.cache.clear(res=>{
						uni.showToast({
							title: '清除成功！',
							icon: 'none',
							success() {
								self.cacheSize = '0B';
							}
						});
				})
			},
			getProtol(){
				uni.navigateTo({
					url:'/pages/prolist/prolist?mydata='+encodeURIComponent(JSON.stringify(this.protocolList))
				})
			},
			goCancel(){
				
				this.userFeedbackHidden=false	
			},
			goOut(){
				// this.userHidden=false
				this.outHidden=false
			},
			cancelAccount(){
				//注销账号
				const self=this
				self.$request('/pawn/client/die','POST').then(res => {
					console.log(res,'myinit');
					const { die}=res.result
					console.log(die,'die')
					if(die==true){
						console.log(die,'die2')
						self.userFeedbackHidden=false
						uni.removeStorageSync('token')
						this.Go('uni:/pages/index/index','tab')
					}
					
					
				})
			},
			loginOut(){
				//退出登录
				const self=this
				console.log(333)
				self.$request('/pawn/client/loginOut','POST').then(res => {
					console.log(res,'logout');
					self.outHidden=false
					uni.removeStorageSync('token')	
					this.Go('uni:/pages/index/index','tab')	
			
				})
			},
			loginCel(){
				this.outHidden=true
			},
			hideDiv(){
				//隐藏弹窗
				this.userFeedbackHidden=true
				this.userHidden=true
				this.outHidden=true
			},
		},
		onShow() {
			this.init()
			this.token=uni.getStorageSync('token')
		}
	}
</script>

<style src='./index.less' lang="less" scoped></style>
