<script>
	import Vue from 'vue'
	import accountApi from '@/api/account.js'
	import oilSiteApi from '@/api/oil-site.js'
	import wxCode from '@/api/wxcode.js'
	import tools from '@/utils/tools.js'
	let loginTimer = null
	let onlineTimer = null
	export default {
		data() {
			return {
				loginStatus: 'online',
				msg: ''
			}
		},
		onLaunch(option) {
			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
				}
			})
			this.onShareAppMessage(option.query.scene);
			
		},
		onLoad(e) {
			console.log(e,'666666666666666666666666666666')
			
		},
		methods: {
		
			getFilterData() {
				oilSiteApi.getCheckInfo().then(res => {
					if (res.code == 20000) {
						let channelCodes = []
						res.data.channelCodes.map(item => {
							channelCodes.push({
								title: item.name,
								value: item.id
							})
						})
						let productCodes = []
						res.data.productCodes.map(item => {
							productCodes.push({
								title: item.name,
								value: item.id
							})
						})
						let siteBrands = []
						res.data.siteBrands.map(item => {
							siteBrands.push({
								title: item.name,
								value: item.id
							})
						})
						console.log(channelCodes, productCodes, siteBrands)
						this.menuList[0].detailList = this.menuList[0].detailList.concat(channelCodes)
						this.menuList[1].detailList = this.menuList[1].detailList.concat(productCodes)
						this.menuList[2].detailList = this.menuList[2].detailList.concat(siteBrands)
						uni.setStorageSync('filterData', this.menuList)
						// this.$refs.slFilter.resetMenuList(this.menuList)
					}
				})
			},
			onShareAppMessage(e) {
				let that = this
				wx.onAppRoute((res) => {
					// console.log(res, '当前页面路由发生变化 触发该事件onShareAppMessage');
					const pages = getCurrentPages() //获取加载的页面
					const view = pages[pages.length - 1] //获取当前页面的对象
					if (!view) return false //如果不存在页面对象 则返回
					view.onShareAppMessage = () => { //重写分享配置
						return {
							title: '一路油你,星油能源',
							path: "/pages/index/startPage/startPage", 
							imageUrl: 'https://xoi-support.oss-cn-hangzhou.aliyuncs.com/星油admin小程序/xxxxx.png',
						}
					}
					
					let white = ['pages/index/startPage/startPage']
					if(view.route === 'BagStation/pages/stationDetail/stationDetail') {
						uni.removeStorageSync('refuseLogin')
					}
					// // 是否跳过登陆
					let isRefuseLogin = uni.getStorageSync('refuseLogin')
					if(isRefuseLogin || white.includes(view.route) || view.route.includes('BagAuth')) return 	
					 this.getAmount()
				})
			},
			// 是否token过期或ip更改
			getAmount() {
				// clearTimeout(loginTimer)
				accountApi.getTotalOilCardInfo().then(res => {
					if (res.code == 42011) {
						uni.showModal({
							title: '需要您重新登录',
							content: res.msg,
							duration: '3000',
							success: function(res) {
								if (res.confirm) {
									uni.redirectTo({
										url: '/BagAuth/pages/login/login'
									})
								}
							}
						})
					}
				})
			},
		},
		onReady() {

		},

		onShow: function(option) {
			const token = uni.getStorageSync('Authorization')
			const openid = uni.getStorageSync('openid')
			let key = ''
			if (token && openid) {
				this.getAmount()
				key = '真在线'
			} else {
				key = '离线'
			}
			if (key == '在线') {

			}
			setTimeout(() => {
				console.log(key)
				if (key == '在线') {

				} else {
					// uni.redirectTo({
					// 	url: '/BagAuth/pages/login/login'
					// })
				}
			}, 2000)
			// uni.showShareMenu()
			// console.log('App Show')
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					uni.setStorageSync('location', {
						longitude: res.longitude + '',
						latitude: res.latitude + ''
					})
				}
			});
		},
		onHide: function() {
			// console.log('App Hide')
		}
	}
</script>
<style lang="scss">

</style>
<style>
	/*每个页面公共css */
	@import '@/static/icon/iconfont.css';
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "colorui/animation.css";
	@import "common/common.css";
</style>