<template>
	<view class="user" :class="$store.state.AppStyle" style="background-color: #f6f6f6;">
		<view class="header" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar bg-white" :style="{'height': CustomBar + 'px','padding-top':StatusBar + 'px'}">
				<view class="action" @tap="back">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content text-bold" :style="[{top:StatusBar + 'px'}]">
					关于我们
				</view>
				<view class="action">
				</view>
			</view>
		</view>
		<view :style="[{padding:NavBar + 'px 10px 0px 10px'}]"></view>
		<view class="app-about">
			<view class="app-logo">
				<image :src="logo" mode="widthFix"></image>
			</view>
			<view class="app-name">
				{{name}}
			</view>
			<view class="app-ver" v-if="wgtVer!=''">
				{{wgtVer}}
			</view>
			
		</view>
		<view class="cu-list menu margin-top">
			<!--  #ifdef APP-PLUS -->
			<view class="cu-item" @tap="isUpdate(true)">
				<view class="content">
					<text>最新版本</text>
				</view>
				<view class="action">
					<text class="update-tips bg-red" v-if="Update>0">News</text>
					<text class="text-gray">{{versionTitle}}</text>
					
					<text class="cuIcon-right"></text>
				</view>
			</view>
			<!--  #endif -->
			<view class="cu-item" @tap="rmlocal">
				<view class="content">
					<text class="tn-icon-clear  margin-right-sm"></text>
					<text>清除缓存</text>
				</view>
				<view class="action">
					<text class="text-gray">{{ localdata }}</text>
				</view>
			</view>
			<view class="cu-item" @tap="yhxy">
				<view class="content">
					<text class="tn-icon-my-circle margin-right-sm"></text>
					<text>用户协议</text>
				</view>
				<view class="action">
					<text class="cuIcon-right"></text>
				</view>
			</view>
			<view class="cu-item" @tap="ysxy">
				<view class="content">
					<text class="tn-icon-safe margin-right-sm"></text>
					<text>隐私协议</text>
				</view>
				<view class="action">
					<text class="cuIcon-right"></text>
				</view>
			</view>
		</view>
		
			
		<view class="about-tips">
			{{name}}平台部分图片，资源来源于互联网，如侵犯了您的权利，请立即联系邮箱（{{email}}）进行删除。
		</view>
		<!--  #ifdef APP-PLUS -->
		<view class="update" v-if="Update==2">
			<view class="update-bg">
				
			</view>
			<view class="update-box">
				<view class="update-main">
					<image src="../../static/app-plus/ic_ar.png"></image>
					<view class="update-title">发现新版本：{{versionTitle}}</view>
					<view class="update-intro"><rich-text :nodes="versionIntro"></rich-text></view>
					<view class="update-btn grid col-2">
						<view class="update-btn-box">
							<view class="update-btn-main bg-blue"  @tap="goUpdata(true)">
								确定
							</view>
						</view>
						<view class="update-btn-box">
							<view class="update-btn-main bg-gray" @tap="closeUpdate()">
								取消
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!--  #endif -->
	</view>
</template>

<script>
	import { localStorage } from '../../js_sdk/mp-storage/mp-storage/index.js'
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				NavBar:this.StatusBar +  this.CustomBar,
				AppStyle:this.$store.state.AppStyle,
				logo:"",
				name:"",
				email:"",
				versionCode:0,
				wgtVer:'',
				localdata: '',
				Update:0,
				versionUrl:"",
				versionTitle:"",
				versionIntro:"",
				aboutme:this.$API.GetAboutme(),
				
			}
		},
		onPullDownRefresh(){
			var that = this;
			
		},
		onShow(){
			var that = this;
			// #ifdef APP-PLUS
			
			//plus.navigator.setStatusBarStyle("dark")
			
			that.isUpdate(false);
			// #endif
			that.name = that.$API.GetAppName();
			that.logo = that.$API.GetLogo();
			that.email = that.$API.GetAppEmail();
			
			
		},
		onLoad() {
			var that = this;
			
			
		},
		methods: {
			ysxy() {
				var that = this;
			
				uni.navigateTo({
					url: '/pages/user/privacy'
				});
			},
			yhxy() {
				var that = this;
			
				uni.navigateTo({
					url: '/pages/user/agreement?button=none'
				});
			},
			closeLocal() {
				var that = this
				var userinfo = "";
				var token = "";
				//绕过用户状态
				if (localStorage.getItem('userinfo')) {
					userinfo = localStorage.getItem('userinfo')
					token = localStorage.getItem('token');
				}
				localStorage.clear();
				uni.showToast({
					title: '操作成功！',
					icon: 'none',
					duration: 1000,
					position: 'bottom'
				})
				that.localdata = '0 KB'
				localStorage.setItem('userinfo', userinfo);
				localStorage.setItem('token', token);
			},
			get_cache_size() {
				var that = this
				var obj = uni.getStorageInfoSync()
				if (obj) {
					that.localdata = obj.currentSize + ' KB'
				} else {
					console.log('浏览器不支持localStorage')
				}
			},
			rmlocal() {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '是否清除缓存？',
					success: function(res) {
						if (res.confirm) {
							that.closeLocal();
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			back(){
				uni.navigateBack({
					delta: 1
				});
			},
			goUpdata(){
				var that = this;
				console.log(that.versionUrl)
				if(that.versionUrl!=""){
					plus.runtime.openURL(that.versionUrl);  
				}
				that.closeUpdate();
			},
			isUpdate(Status) {
				var that = this;
			
				plus.runtime.getProperty(plus.runtime.appid, function(inf) {
			
					that.wgtVer = inf.version //获取当前版本号
					that.versionCode = inf.versionCode;
					var version = inf.versionCode;
					that.$Net.request({
						url: that.$API.GetUpdateUrl(),
						header: {
							'content-type': 'application/json'
						},
						method: 'get',
						success: function(res) {
							var versionCode = res.data.versionCode;
							that.versionUrl = res.data.versionUrl;
							that.versionTitle = res.data.version;
							that.versionIntro = res.data.versionIntro;
							if (Status) {
								uni.showToast({
									title:"检测完成",
									icon:'none',
									duration: 1000,
									position:'bottom',
								});
							}
							if (versionCode > version) {
								console.log("有更新");
								uni.hideTabBar({
									animation: true
								})
								that.Update = 1;
								if (Status) {
									if (res.data.versionUrl != "") {
										plus.runtime.openURL(res.data.versionUrl);
									}
								}
							}
			
						},
						fail: function(res) {
			
						}
					})
			
				})
			},
			toPage(title,cid){
				var that = this;
				
				uni.navigateTo({
				    url: '/pages/contents/info?cid='+cid+"&title="+title
				});
			},
			toAgreement(){
				var that = this;
				
				uni.navigateTo({
				    url: '/pages/user/agreement'
				});
			},
			closeUpdate(){
				var that = this;
				that.Update = 1;
				// uni.showTabBar({
				// 	animation: true
				// });
			},
		},
	}
</script>

<style>
	page{
		background: #f9f9f9;
	}
</style>