<template>
	<view class="content">
		<view class="logo">
			<image src="/static/logo.png" style="border-radius: 50%;"></image>
			<p>{{$qconfig.appName}}</p>
		</view>
		<view class="set-box" >
			
			<view class="item" @click="callPhone()">
				<view class="left">
					<text class="text">联系我们</text>
				</view>
				<image class="right" src="/static/image/right_arrow.png" mode="aspectFill"></image>
			</view>
			<view class="line"></view>
			<view class="item" @tap="loginNavTo('./msgSetting')">
				<view class="left">
					<text class="text">消息设置</text>
				</view>
				<image class="right" src="/static/image/right_arrow.png" mode="aspectFill"></image>
				<button class='contact-btn' open-type="contact"></button>
			</view>
			
			<view class="line"></view>
			<view class="item" @tap="checkUpdateApp()">
				<view class="left">
					<text class="text">版本号</text>
				</view>
				<view class="right-text">
					<text class="text">v{{version}}</text>
				</view>
			</view>
			<view class="line"></view>
			
		</view>
	
	    <view class="bottom-box y-f">
			<view class="es-c-66 es-fs-28">蜀ICP备2023036719号-7A</view>
			<view class="es-mt-20 es-fs-28 es-c"> <text @click="goToWeb(0)">《用户协议》</text>  <text @click="goToWeb(1)">《隐私政策》</text> </view>
		</view>
		
	</view>
</template>

<script>
 import { premissionCheck } from "@/js_sdk/wa-permission/permission.js"
 import { getAppVersion } from '@/api/common'
 import {appCheckUdate,openDownload } from '@/utils/APPUpdate.js'
 import { qconfig } from '@/utils/config';
 export default {
 	data() {
 		return {
			tel:undefined,
			version:"1.2.5",
			clickTime:1,
 		}
 	},
	onLoad() {
		this.getAppVersion1();
		// 修改顶部导航背景色
		// uni.setNavigationBarColor({ 
		// 	frontColor: '#ffffff',
		// 	backgroundColor: '#FF5C03',
		// 	animation: {
		// 		duration: 200,
		// 		timingFunc: 'easeIn'
		// 	}
		// });
	},
 	methods: {
	  async callPhone(){
			let result = await premissionCheck("CALL_PHONE");
			if(result==1){
				uni.makePhoneCall({
					phoneNumber: "4000717770"
				})
			}
		},
		goToWeb(index){
			uni.setStorageSync('url',index==0?"https://userapp.his.cdwjyyh.com/web/userAgreement":"https://userapp.his.cdwjyyh.com/web/privacyPolicy");
			uni.navigateTo({
				url:"/pages/index/h5"
			})
		},
		getAppVersion1(){
			    // #ifdef APP-PLUS
					   let that=this;
					   if(plus.runtime.isAgreePrivacy()) {
							plus.runtime.getProperty(plus.runtime.appid, function(widgetinfo) {
								// 可以根据manifest.json里的应用名称来进行针对性的APP升级
								let platform = uni.getSystemInfoSync().platform;
								that.version=widgetinfo.version+"("+widgetinfo.versionCode+")";
							});		  
						}
			   // #endif
			   
		},
		loginNavTo(url){
			if(!this.$isLogin()){
				this.$showLoginPage();
				return;
			}
			uni.navigateTo({
				url: url
			});
		},
		/* 检查更新 在线更新 */
		checkUpdateApp(){
			let that=this;
			console.log("qxj checkUpdateApp");
			if(this.clickTime<5){
				this.clickTime++;
				return;
			}
			plus.runtime.getProperty(plus.runtime.appid, function(widgetinfo) {
					//console.log("qxj widgetinfo:"+JSON.stringify(widgetinfo));
					if (widgetinfo.name == qconfig.appName) { //APP名称
						// 获取manifest.json里的版本号  
						let platform = uni.getSystemInfoSync().platform;
						let isAndroid=platform=="android";
						let type=isAndroid?1:2;
						getAppVersion(type).then(srcData => {
								// console.log("qxj getAppVersion srcData:"+JSON.stringify(srcData)+" isAppStore："+that.$qconfig.isAppStore);
								if(srcData.code==200){
									let data = srcData.data;
									let version = widgetinfo.versionCode,//用户当前版本
									appVersion = data.versionCode,//升级包版本
									appName = widgetinfo.name, //app名称
									isForce = data.isForce,//是否强制热更新
									updateConfig=JSON.parse(data.updateConfig),
									appurl = data.url,//升级包地址
									intro = data.note;//升级包提示
									
									//如果用户版本号小于升级包版本号，先升级	
									let afterVer=false;
									if(plus.runtime.channel=="baidu"){
									    afterVer=that.$qconfig.isAppStore?updateConfig.baidu:false;
									}
									else if(plus.runtime.channel=="huawei"){
									    afterVer=that.$qconfig.isAppStore?updateConfig.huawei:false;
									}
									else if(plus.runtime.channel=="xiaomi"){
									    afterVer=that.$qconfig.isAppStore?updateConfig.xiaomi:false;
									}
									else if(plus.runtime.channel=="yyb"){
									    afterVer=that.$qconfig.isAppStore?updateConfig.yyb:false;
									}
									else{
										afterVer=that.$qconfig.isAppStore?isForce:true;
									}
									if(data && (version < appVersion) && afterVer){
										uni.showModal({
											title:"更新提示",
											confirmText:"立即升级",
											content:intro,
											cancelText:'确定',
											confirmText:'取消',
											success: (res) => {
													if (res.cancel) {
														openDownload(srcData.data);
													} else if (res.confirm) {
														if(isForce==1){
															uni.showToast({title:"请先升级APP版本",icon:"none",duration:2000});
															//退出app
															setTimeout(function(){
																plus.runtime.quit();
															},2000)
														}
													}
											},
											fail: () => {
												uni.hideLoading();
											}
										})
									}
								}								
							},
							rej => {}
						).catch(()=>{
							//联网失败, 结束加载
							this.mescroll.endErr();
						});
					} 
			
			
			});
		
		
		}
 		
 	}
 }
 
 
</script>


<style scoped lang="scss">
page{
	height: 100%;
}
.content{
	height: 100%;
	background-color: #fff;
}

.line{
	height: 1px;background-color: #F7F7F7;
}

.logo{
	padding-top: 15%;
	text-align: center;
	image{
		width: 120rpx;
		height: 120rpx;
		border-radius: 10rpx;
		box-shadow:0px 0px 20rpx rgba(0,0,0,0.2);
	}
	p{
		margin: 10px 0px;
		font-size: 14px;
	}
}
.set-box{
	margin-top: 30upx;
	background: #fff;
	padding: 0 40upx;
	.item{
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25upx 0;
		.left{
			display: flex;
			align-items: center;
			.text{
				font-size: 30upx;
				color: #666;
			}
		}
		.right{
			width: 10upx;
			height: 20upx;
		 
		}
		.right-text{
			 
		}
	}
}
.contact-btn {
	position: absolute;
	width: 100%;
	display: flex;
	opacity: 0;
}


.bottom-box{
	position: absolute;
	bottom: 50rpx;
	width: 100%;
	
}

</style>
