<script>
	import functions from "@/utils/functions.js";
	import {banben} from '@/api/user.js'
	export default {
		onLaunch: function() {
			//#ifndef MP-WEIXIN
			plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
				//  获取 app的version
				let appversion = wgtinfo.version;
				// 存缓存 版本号
				try {
					uni.setStorageSync('appversion', appversion);
				} catch (e) {}
				console.log("appversion:" + appversion);
			});
			let v = uni.getStorageSync('appversion');
			if(v.indexOf('v')==-1){
				banben({
					version: v
				}).then(res => {
					console.log('res', res.new_version);
					console.log(res.new_version==v);
					if(res.new_version==v){
						return
					}
					if(!res) return
					uni.showModal({ //提醒用户更新  
						title: "版本更新",
						success: (re) => {
							if (re.confirm) {
								//   更新操作，resetURL 是ap1	p更新的接口地址
								const downloadTask = uni.downloadFile({ //执行下载
									url: functions.getDomain()+'/static/xy-pro-'+res.new_version+'.apk', //下载地址
									success: downloadResult => { //下载成功
										if (downloadResult.statusCode == 200) {
											plus.runtime.install( //安装
													downloadResult.tempFilePath, {
														force: true
													},
													function(res) {
														utils.showToast('更新成功，重启中');
														plus.runtime.restart();
													}
												);
											}
										}
								});
								var showLoading = plus.nativeUI.showWaiting("正在下载", {back: "none"});//{back: "none"}用来禁止返回键
								downloadTask.onProgressUpdate((res) => {
									showLoading.setTitle("  正在下载" + res.progress + "%  ");
									if (res.progress == 100) {
										plus.nativeUI.closeWaiting();
									}
								});
							}
						}
					})
				})
			}else{
				v=v.substring(1);
				banben({
					version: v
				}).then(res => {
					console.log('res', res.new_version);
					console.log(res.new_version==v);
					if(res.new_version==v){
						return
					}
					if(!res) return
					uni.showModal({ //提醒用户更新   
						title: "版本更新",
						success: (re) => {
							if (re.confirm) {
								//   更新操作，resetURL 是ap1	p更新的接口地址
								const downloadTask = uni.downloadFile({ //执行下载
									url: functions.getDomain()+'/static/xy-pro-'+res.new_version+'.apk', //下载地址
									success: downloadResult => { //下载成功
										if (downloadResult.statusCode == 200) {
											plus.runtime.install( //安装
													downloadResult.tempFilePath, {
														force: true
													},
													function(res) {
														utils.showToast('更新成功，重启中');
														plus.runtime.restart();
													}
												);
											}
										}
								});
								var showLoading = plus.nativeUI.showWaiting("正在下载", {back: "none"});//{back: "none"}用来禁止返回键
								downloadTask.onProgressUpdate((res) => {
									showLoading.setTitle("  正在下载" + res.progress + "%  ");
									if (res.progress == 100) {
										plus.nativeUI.closeWaiting();
									}
								});
							}
						}
					})
				})
			}
			
			//#endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	page{
		background: #F1F1F1;
	}
	
	
	.big-titlt{
		@include fonts(34upx,red,bold);
	}
	.big-title{
		width: 750upx;
		margin: auto;
		padding: 30upx 0upx 30upx 0upx;
		@include fonts(34upx,red,bold);
		background:#C8C7CC;
		text-indent: 30upx;
	}
	.re-colo{
		@include fonts(26upx,red);
		width: 690upx;
		text-align: right;
		margin: auto;
	}
	.re-bor{
		color: red;
		border: 1upx solid red!important;
	}
	.hg-color{
		color: #4CD964!important;
	}
	.bhg-color{
		color:red!important;
	}
	.red-clor{
		color: black;
		padding: 5upx;
	}
	.black-color{
		color: white!important;
		background:#808080;
		padding: 5upx;
	}
	.card-gery{
		background:#C0C0C0!important;
	}
	.card{
		view{
			font-size: 34upx!important;
		}
		text{
			font-size: 32upx!important;
		}
		.btn-group{
			padding-top: 0upx!important;
		}
	}
	.white-card{
		.list-list{
			padding-top: 40upx;
			padding-bottom: 40upx;
			view{
				font-size: 34upx!important;
			}
			text{
				font-size: 32upx!important;
			}
			.list-right{
				text{
					font-size: 32upx!important;
				}
				input{
					font-size: 32upx!important;
				}
			}
		}
		.mid-card{
			view{
				font-size: 34upx!important;
			}
			text{
				font-size: 32upx!important;
			}
			input{
				font-size: 32upx!important;
			}
		}
		
	}
	.btn-jian,.btn-jia{
		text{
			font-size: 32upx!important;
		}
	}
.layui-bg-cyan {
    background-color: #2f4056 !important;
    color: #fff !important
}
.layui-badge {
    height: 18px;
    line-height: 18px
}

.layui-badge-dot {
    width: 8px;
    height: 8px;
    padding: 0;
    border-radius: 50%
}

.layui-badge-rim {
    height: 18px;
    line-height: 18px;
    border-width: 1px;
    border-style: solid;
    background-color: #fff;
    color: #5f5f5f
}

.layui-btn .layui-badge,
.layui-btn .layui-badge-dot {
    margin-left: 5px
}

.layui-nav .layui-badge,
.layui-nav .layui-badge-dot {
    position: absolute;
    top: 50%;
    margin: -5px 6px 0
}

.layui-nav .layui-badge {
    margin-top: -10px
}

.layui-tab-title .layui-badge,
.layui-tab-title .layui-badge-dot {
    left: 5px;
    top: -2px
}
.layui-badge-rim,
.layui-border,
.layui-colla-content,
.layui-colla-item,
.layui-collapse,
.layui-elem-field,
.layui-form-pane .layui-form-item[pane],
.layui-form-pane .layui-form-label,
.layui-input,
.layui-layedit,
.layui-layedit-tool,
.layui-panel,
.layui-quote-nm,
.layui-select,
.layui-tab-bar,
.layui-tab-card,
.layui-tab-title,
.layui-tab-title .layui-this:after,
.layui-textarea {
    border-color: #eee
}
.layui-badge,
.layui-badge-dot,
.layui-badge-rim {
    position: relative;
    display: inline-block;
    padding: 0 6px;
    font-size: 12px;
    text-align: center;
    background-color: #ff5722;
    color: #fff;
    border-radius: 2px
}


</style>

