<template>
	<view>
		<customNav :shownav="true" :title="$t('index.setting')" titledetl=""></customNav>
		<view class="contentV" style="margin-top: 30rpx;">
			<view class="itemView" @click="shezhixuanze(1)">
				<text class="textstye">{{$t('user.tuichudl')}}</text>
			</view>
			<view class="itemView" @click="shezhixuanze(2)">
				<text class="textstye">{{$t('user.zhuxiaozhh')}}</text>
			</view>
			<view class="itemView" @click="shezhixuanze(3)">
				<text class="textstye">{{$t('user.yinsizhc')}}</text>
			</view>
		</view>
		<view class="versionV">
			<view class="versionitem">
				<text class="appname">CTE</text>
				<text v-if="isnewV" class="zuixinbb">{{$t('user.yishizxbb')}}: v{{versionMSG.versionName}}</text>
				<text v-if="!isnewV" class="dangqbb">{{$t('user.dangqianbb')}}: v{{appversionN}}</text>
				<text v-if="!isnewV" class="huoqubb" @click="checkgengxin">{{$t('user.huoquzxbb')}}: v{{versionMSG.versionName}}</text>
			</view>
		</view>
		<popViewGG :tips="$t('user.xiazaijindu')" :show="show" :maskClosable="false" :isCancel="false">
			<view class="words">
				<text>{{$t('user.xiazaizhong')}} {{percentVal}}%</text>
			</view>
		</popViewGG>
	</view>
</template>
<!-- https://backend.cityexpress168.com.vn/ynszc.html -->
<script>
 import api from "@/pages/api/api.js"
	export default {
		data() {
			return {
				index:0,
				versionMSG:[],
				appversionN:'',
				appVersionCode:0,
				isnewV:true,
				updateUrl:'',
				show:false,
				percentVal:''
			}
		},
		onShow() {
			var info = uni.getSystemInfoSync();
			//console.log(info);
			this.appVersionCode=info.appVersionCode;
			this.appversionN=info.appVersion;
			this.getversion();
		},
		methods: {
			shezhixuanze(index){
				
				switch(index){
					case 0:
					
					break;
					case 1:
					this.tuichudengl();
					break;
					case 2://注销账号
					this.zhuxiaozhangh();
					break;
					case 3://隐私政策
						uni.navigateTo({
							url:'/pages/index/mindex/yinszhengc'
						})
					break;
					case 4:
					
					break;
					case 5:
					
					break;
				}
			},
			
			tuichudengl(){
				var that = this;
				uni.showModal({
				    title: that.$t('api.message'),
				    content: that.$t('user.querentcdq'),
					cancelText:that.$t('order.quxiao'),
					confirmText:that.$t('comp.queren'),
				    success: function (res) {
						if (res.confirm) { //这里是点击了确定以后
							uni.setStorageSync('userInfo','');
							uni.setStorageSync('token','');
							getApp().globalData.token='';
							that.disconectGoeasy();
							setTimeout(function() {
							  uni.navigateBack();
							}, 1000);
						} else { //这里是点击了取消以后
						  console.log('用户点击取消')
						}
						
				    }
				})
			},
			zhuxiaozhangh(){
				var that = this;
				uni.showModal({
				    title: that.$t('user.zhuxiaozhh'),
				    content: that.$t('user.zhuxiaodqzh'),
					cancelText:that.$t('order.quxiao'),
					confirmText:that.$t('comp.queren'),
				    success: function (res) {
						if (res.confirm) { //这里是点击了确定以后
							this.updatazuxiao();
						} else { //这里是点击了取消以后
						  console.log('用户点击取消')
						}
						
				    }
				})
			},
			updatazuxiao(){
				var that = this;
				api('deleuser',{
				},res=>{
					console.log(res)
					uni.setStorageSync('userInfo','');
					uni.setStorageSync('token','');
					that.disconectGoeasy();
					setTimeout(function() {
					  uni.navigateBack();
					}, 1000);
				},failc=>{
					//console.log('getadvertis----',failc)
				})
			},
			checkgengxin(){
				return;
			},
			disconectGoeasy(){
				this.goEasy.disconnect({
				    onSuccess: function(){
				        console.log("GoEasy disconnect successfully.")
						getApp().globalData.goEasycnt=false;
				    },
				    onFailed: function(error){
				        console.log("Failed to disconnect GoEasy, code:"+error.code+ ",error:"+error.content);
				    }
				});
			},
			
			// 	var that = this;
			// 	uni.showModal({
			// 	    title: that.$t('api.message'),
			// 	    content: that.$t('user.shifougengxin'),
			// 		cancelText:that.$t('order.quxiao'),
			// 		confirmText:that.$t('comp.queren'),
			// 	    success: function (res) {
			// 			if (res.confirm) { //这里是点击了确定以后
			// 				that.gengxinApp();
			// 			} else { //这里是点击了取消以后
			// 			  console.log('用户点击取消')
			// 			}
						
			// 	    }
			// 	})
			// },
			
			// gengxinApp(){
			// 	var that = this;					
			// 	var dtask = plus.downloader.createDownload(
			// 	this.updateUrl,
			// 	{
			// 		method: "GET"
			// 	}, (d, status) => {
			// 		console.log(d);
			// 		if (status == 200) {
						
			// 			plus.runtime.install(d.filename)
			// 		} else {
			// 			plus.nativeUI.alert(that.$t('user.anzhuangsbcs') + status)
			// 		}
			// 	});
			// 	dtask.start();
			// 	var prg = 0;//进度数字化
			// 	that.show = true;
			// 	var show= plus.nativeUI.showWaiting("Loading...");
				
			// 	dtask.addEventListener('statechanged',function(task,status){
			// 		switch(task.state){//根据下载状态调整其显示内容
			// 			case 1:
			// 				that.percentVal = "Loading……";
			// 				//showLoading.setTitle("正在下载……");
			// 				break;
			// 			case 2:
			// 				that.percentVal = "Connected";
			// 				//showLoading.setTitle("连接到服务器");
			// 				break;
			// 			case 3:
			// 				that.percentVal = parseInt((parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100);
			// 				//showLoading.setTitle("正在下载：" + this.percentVal + "%");
			// 				break;
			// 			case 4:
			// 				plus.nativeUI.closeWaiting();
			// 				that.show = false;
			// 				break;
			// 		}
			// 	});
			// },
			
			getversion(){//消息推送
				var that = this;
				api('getversion',{
					platform:'0',
					name:'跑腿王'
				},res=>{
					console.log(res.data)
					this.versionMSG=res.data.data;
					if(this.appVersionCode<this.versionMSG.version){
						this.isnewV = false;
						this.updateUrl=that.$baseImagurl+this.versionMSG.downloadUrl;
					}
				},failc=>{
					//console.log('getadvertis----',failc)
				})
			},
		},
	}
</script>

<style>
	page{
		background-color: #F2F3F7;
	}
	
.contentV{
		display:flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
}
	
	.itemView{
		display:flex;
		justify-content: flex-start;
		margin-top: 20rpx;
		height: 100rpx;
		width: 90%;
		border: 2rpx dotted darkgray;
		background-color: aliceblue;
	}
	.textstye{
		font-size: 30rpx;
		margin-left: 30rpx;
		height: 80rpx;
		line-height:80rpx;
	}
.versionV{
	position:fixed;
	bottom: 40rpx;
	width: 100%;
}
.versionitem{
	display:flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	width: 90%;
}
.appname{
	font-size: 30rpx;
}
.zuixinbb{
	padding-top: 10rpx;
	font-size: 28rpx;
}
.dangqbb{
	padding-top: 10rpx;
	font-size: 28rpx;
}
.huoqubb{
	padding-top: 10rpx;
	font-size: 28rpx;
	color: blue;
	text-decoration:underline;
}

.words{
	width: 100%;
	text-align: center;
	font-size: 30rpx;
	height: 80rpx;
	line-height: 80rpx;
}
</style>
