<script>
var http = require("./common/request.js");
var tabberData = require ('./components/tabber/tabber.js'  )
import Vue from 'vue'
export default {
	globalData: {
	    principal: [] ,
		isbingCID:false,
		diary:{},
	},
	onLaunch: function() {
	   uni.getSystemInfo({
	   	success: function(e) {
	   		// #ifndef MP
	   		Vue.prototype.StatusBar = e.statusBarHeight;
	   		if (e.platform == 'android') {
	   			Vue.prototype.CustomBar = e.statusBarHeight + 50;
	   		} else {
	   			Vue.prototype.CustomBar = e.statusBarHeight + 45;
	   		};
	   		// #endif

	   		// #ifdef MP-WEIXIN
	   		Vue.prototype.StatusBar = e.statusBarHeight;
	   		let custom = wx.getMenuButtonBoundingClientRect();
	   		Vue.prototype.Custom = custom;
	   		Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
	   		// #endif

	   		// #ifdef MP-ALIPAY
	   		Vue.prototype.StatusBar = e.statusBarHeight;
	   		Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
	   		// #endif
	   	}
	   })

	   //清除权限缓存
	   uni.removeStorageSync('authorityList');

	   // #ifdef APP-PLUS

	   //消息推送
		getApp().globalData.isbingCID = false;
	   // const _self = this;
	   plus.push.addEventListener('click', function(message) {
		//console.log(message,'click')
		//console.log(message.payload)
		if(message.payload && message.payload.url){
			let userInfo = uni.getStorageSync('userInfo');
			//是否登录
			if(userInfo){
				//console.log(message.payload.url)
				uni.navigateTo({
				    url: message.payload.url
				});
			}
		}
	   });
	   plus.push.addEventListener('receive', function(message) {
		console.log(message,'receive')
		if ( message.aps ) {  // Apple APNS message
		    //APNS下发的消息，应用在前台

		} else if ( 'LocalMSG' == message.payload ) {   // 特殊payload标识本地创建的消息
		    //本地创建的消息，通常不需要处理
		    //注意：不要在这种情况下再此调用plus.push.createMessage，从而引起循环创建本地消息
		} else {
		    //接收到在线透传消息
			plus.push.createMessage(message.content, "LocalMSG",{cover:false,title:message.title});
		}
	   });
	   // #endif
	},
	onShow: function() {
		http.getDomain();
		    //半个小时为周期来生成该用户的任务预警信息
			setInterval(function(){
				console.log("-----------------开始生成任务预警信息-----------------");
				var userId = uni.getStorageSync("userInfo").id;
				var porject = uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id);
				if(userId!=null && porject.contractId!=null &&  porject.id){
					http.request("/app/task/taskRules",{userId:userId,contractId:porject.contractId,projectId:porject.id},null,1).then((res)=>{
						console.log("-----------------任务预警信息执行完成-----------------");
					})
				}
			},1800000);
			//定时监测

		// #ifdef APP-PLUS
		plus.runtime.getProperty(plus.runtime.appid,(widgetInfo)=>{
		    //console.log(widgetInfo)
			this.widgetInfo = widgetInfo;
			//console.log(plus.os.name)
			http.request("/app/appversion/update",{name:widgetInfo.name,version:widgetInfo.version,platform:plus.os.name}).then((res)=>{
				console.log(res)
				if(res.update){
					//检查是否有新版本
					this.$set(this.tabberData,'newVersion',true);
				}
			})

		});
		// #endif

	},
	onHide: function() {

	}
};
</script>

<style>
/*每个页面公共css */
	@import "style/main.css";
	@import "style/icon.css";
	@import "style/ly-tree.css";
	@import "style/index.css";
	.menuImageNoTask{
		height: 80rpx;
		width: 120rpx;
	}
	.menuImageTask{
		height: 90rpx;
		width: 90rpx;
	}
	.cu-avatar {
		font-variant: small-caps;
		margin: 0;
		padding: 0;
		display: inline-flex;
		text-align: center;
		justify-content: center;
		align-items: center;
		background-color: white;
		color: #ffffff;
		white-space: nowrap;
		position: relative;
		width: 94upx;
		height: 64upx;
		background-size: cover;
		background-position: center;
		vertical-align: middle;
		font-size: 1.5em;
	}
	.login-img{
			 width: 30rpx;
			 height: 30rpx;
	}
	/* 浅黄辅色 */
	.bg-yellow-secondary{
		background-color:#FCF1E2;
		color: #EF9D1E;
	}
	/* 浅蓝辅色 */
	.bg-blue-secondary{
		background-color:#C6E6FF;
		color: #0A8CD5;
	}
	/* 背景灰色*/
	.bg-gray-secondary{
		background-color:#F7F7F7;
	}
	uni-checkbox:not([disabled]) .uni-checkbox-input:hover{
		border-color: #d1d1d1;
	}
</style>
