<template>
	<!-- #ifdef MP-WEIXIN -->
	<StartPage :flag="!!vdata.list.length" />
	<!-- #endif -->
	<JeepayAdStart ref="refAdStart" :list="vdata.list" :time="10" :url="vdata.url" @openInt="openInt" />
</template>

<script setup>
import { $adList } from '@/http/apiManager.js'
import storageManage from '@/util/storageManage.js'
import { reactive, nextTick } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import StartPage from './components/StartPage.vue'
onShow(() => {
	nextTick(() => {
		if (vdata.list.length > 0 && timeStartFlag && opneInterval) {
			opneInterval()
		}
	})
})

let opneInterval = undefined
const userInfo = storageManage.userInfo()
const vdata = reactive({
	list: [],
	url: '',
})
let timeStartFlag = false
const params = {
	appPlace: 1,
}
const isLogin = (flag) => {
	// vdata.url = storageManage.token()
	// 	? (userInfo && userInfo.isEpUuser) ? ' ' : '/pages/workbench/workbench'
	// 	: '/pages/login/login'
	vdata.url = storageManage.token()
		? (userInfo && userInfo.isEpUuser) ? ' ' : '/pages/workbench/workbench'
		: '/pages/workbench/workbenchCopy'

	if (flag) {
		if (vdata.url == '/pages/workbench/workbench')
			return uni.switchTab({
				url: vdata.url,
			})
		uni.redirectTo({
			url: vdata.url,
			fail: (info) => {
				console.log(info)
			},
		})
	}
}
isLogin()
const getList = async () => {
	$adList(params).then(({ bizData }) => {
		const adDate = bizData.map((v) => JSON.parse(v.appContent))
		vdata.list = [...adDate.flat()]

		if (!vdata.list.length) {
			isLogin(true)
		} else {
			opneInterval()
		}
	}).catch(err => {
		opneInterval()
	})
}
getList()
const openInt = (fun) => {
	opneInterval = fun
}
</script>

<style lang="scss" scoped></style>
