<template>
	<view class="page-content">
		<image src="../../../static/img/start.jpg" width="" mode="widthFix"></image>
	</view>
</template>

<script>
	import oilSiteApi from '@/api/oil-site.js'
	export default {
		data() {
			return {

				imgURL: this.global.imgURL + 'start/',
				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: ""
						}]
					}
				],

			}
		},
		onLoad(option) {
	
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate((res) => {
				console.log('请求完新版本信息的回调', res.hasUpdate);
				if (!res.hasUpdate) {
					this.initFn(option)
				}
			});

			updateManager.onUpdateReady((res) => {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success(res) {
						if (res.confirm) {
							updateManager.applyUpdate();
						} else {
							this.initFn(option)
						}
					},
				});
			});

			updateManager.onUpdateFailed(function(res) {
				console.log('新的版本下载失败')
			});
		},

		methods: {
			initFn(option) {
				let interstitialAd = null
				let openid = uni.getStorageSync('openid')
				let token = uni.getStorageSync('Authorization')
				
				if (wx.createInterstitialAd) {
					interstitialAd = wx.createInterstitialAd({
						adUnitId: 'adunit-063722d8f7b2b65e'
					})
					let handle = () => {
						if (token && openid) {
							uni.switchTab({
								url: '/pages/tabbar/home/home',
							})
						} else {
							uni.redirectTo({
								url: '/BagAuth/pages/login/login'
							})
						}
					}
					interstitialAd.onClose(handle)
					interstitialAd.onError((err) => {
						console.log('onError', err)
						handle()
					})
				}
				if (interstitialAd) {
					interstitialAd.show().catch((err) => {
						console.error('show catch', err)
					})
				}

			},
			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
							})
						})
						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);
					}
				})
			},
		}
	}
</script>

<style scoped>
	.page-content {
		height: 100%;
		overflow: hidden;
	}

	.page-content image {
		width: 750upx;
	}
</style>
