<script>
	export default {
		globalData: {
			tabbarIndex: 0,
			authorization: '',
			storeId: '',
			userId: '',
			roleId:''
		},
		onLaunch: function() {
			console.log('App Launch');
			uni.getStorage({
				key: 'loginInfo',
				success: (res) => {
					console.log('登录')
					this.globalData.authorization = res.data.Authorization;
					this.globalData.userId = res.data.userId;
					// uni.showLoading({
					// 	title:'加载中……',
					// 	mask:true
					// })

					// uni.switchTab({
					// 	url:'pages/book/index/index'
					// })
					// uni.switchTab({
					// 	url:'pages/center/index/index',
					// })
					// uni.switchTab({
					// 	url:'pages/settlement/index/index'
					// })

					uni.switchTab({
						url: 'pages/book/index/index'
					})
					uni.setStorage({
						key: 'tabbarIndex',
						data: 1,
						success: (res) => {
							this.globalData.tabbarIndex = 1;
						}
					})

				},
				fail: () => {

				}
			})

		},
		onShow: function() {
			console.log('App Show ')
			uni.hideTabBar();

			// const KJJPush = uni.requireNativePlugin('KJ-JPush');
			// KJJPush.setAlias(this.globalData.userId,1,result => {
			//     console.log("setAlias:"+JSON.stringify(result));
			// }); 
			// KJJPush.getAlias_seq(1,result => {
			//     console.log("getAlias_seq:"+JSON.stringify(result));
			// });
			// #ifdef APP-PLUS
			setTimeout(()=>{
					this.versionVerification();
			},500)
		
			// #endif
		},
		mounted() {
			this.getDic();
		},
		onLoad: function() {

		},
		onHide: function() {
			console.log('App Hide')
		},
		watch: {
			'$store.state.dicChange'(newval, oldval) {
				if (newval) {
					console.log('')
					this.getDic();
				}

			}
		},
		methods: {
			versionVerification() {
				var productId = uni.getSystemInfoSync().platform == 'ios' ? 2 : 1;
				var versionNo = plus.runtime.version;
				console.log('当前版本号',productId,versionNo)
				this.$axios.post('system/sysVersion/', {
					"productId": productId,
					"versionNo": versionNo
				}).then(res => {
				
					console.log('查询到的版本',res)
					var url = res.data?res.data.productUrl:'';
					var status= res.data?res.data.status:1;
					if(status==0){
						if (url){
							uni.showModal({
								title: '提示',
								content: '版本过旧请升级',
								cancelText: '取消退出',
								confirmText: '前往升级',
								success: function(res) {
									if (res.confirm) {
										plus.runtime.openURL(url, function(res) {
											console.log(res);
										});
									} else if (res.cancel) {
										plus.runtime.quit();
									}
								}
							});
						}else{
								uni.showModal({
									title: '提示',
									content: '当前版本已经停用，请前往官网下载最新版本',
									showCancel:false,
									confirmText: '知道了',
									success: function(res) {
										if (res.confirm) {
										} 
									}
								});
							}
					}

				}).catch(err => {
					console.log('错误',err.msg)
				})
			},
			getDic() {
				uni.getStorage({
					key: 'dic',
					fail: (err) => {
						this.$axios.post('app/dic/findAllDic', {}).then(res => {
							console.log(res.data)
							uni.setStorage({
								key: 'dic',
								data: res.data
							})
							this.$store.state.dicChange = false;
						}).catch(err => {
							console.log(err.msg)
						})
					}
				})
			},
		}

	}
</script>
<style>
/* 	 @import '@/common/css/common.scss';
	 @import '@/common/css/iconfont.css'; */
</style>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>