<script>
	import Vue from 'vue'
	import accountApi from '@/api/account.js'
	import oilSiteApi from '@/api/oil-site.js'
	let loginTimer = null
	let onlineTimer = null

	export default {
		data() {
			return {
				menuList: [{
						title: '渠道',
						isMutiple: false,
						key: 'channelCode',
						detailList: [{
							title: "全部",
							value: ""
						}]
					},
					{
						title: '0#轻柴油',
						key: 'oilProductCode',
						isMutiple: false,
						detailList: [{
							title: "全部",
							value: ""
						}]
					},
					{
						title: '品牌',
						key: 'siteBrand',
						isSort: true,
						isMutiple: false,
						detailList: [{
							title: "全部",
							value: ""
						}]
					}
				],
				msg: ''
			}
		},
		onLaunch() {
			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()

		},

		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)
					}
				})
			},
			onShareAppMessage() {
				let that = this
				wx.onAppRoute(() => {
					const pages = getCurrentPages() //获取加载的页面
					const view = pages[pages.length - 1] //获取当前页面的对象
					if (!view) return false 

					view.onShareAppMessage = () => { //重写分享配置
						return {
							title: '中品加油',
							path: "/pages/index/startPage/startPage", //若无path 默认跳转分享页
							// imageUrl:'/image/onshowMessage.png' //若无imageUrl 截图当前页面
							imageUrl: 'https://publicxingyou.oss-cn-hangzhou.aliyuncs.com/mp-oil/login-bg.png',
						}
					}
					// 是否跳过登陆
					let isRefuseLogin = uni.getStorageSync('refuseLogin')
					console.log('isRefuseLogin',isRefuseLogin,typeof isRefuseLogin)
					if(isRefuseLogin || view.route === 'pages/index/startPage/startPage' || view.route.includes('BagAuth')) return 					
					 this.getAmount()
				})
			},
			
			obtainUrlPathParameterTarget(url) {
				let target = {}
				if(url.includes('?')) {
					let paramsText = url.split("?")[1]
					let paramsArr = paramsText.split("&")
					paramsArr.forEach(item => {
						target[item.split('=')[0]] = item.split('=')[1]
					})
				}
				return target
			},
			
			// 是否token过期或ip更改
			getAmount() {			
				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() {
			uni.getLocation({
				type: 'wgs84',
				success: function(res) {
					uni.setStorageSync('location', {
						longitude: res.longitude + '',
						latitude: res.latitude + ''
					})
				}
			});
			// const token = uni.getStorageSync('Authorization')
			// const openid = uni.getStorageSync('openid')
			// let key = ''
			// if (token && openid) {
			// 	this.getAmount()
			// 	key = '真在线'
			// } else {
			// 	key = '离线'
			// }
			// if (key == '在线') {

			// }
			// setTimeout(() => {
			// 	if (key == '在线') {

			// 	} else {
			// 		// uni.redirectTo({
			// 		// 	url: '/BagAuth/pages/login/login'
			// 		// })
			// 	}
			// }, 2000)
			// // uni.showShareMenu()
			// // console.log('App Show')

		},
		onHide: function() {
			// console.log('App Hide')
		},
		onUnload:function() {
			uni.removeStorageSync('scanningParams')
		}
	}
</script>

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