<script>
import { useUserStoreWidthOut } from './store/modules/user'
import { useServiceStoreWidthOut } from './store/modules/service'

const userStore = useUserStoreWidthOut()
const serviceStore = useServiceStoreWidthOut()

export default {
	async onLaunch() {
		try {
			await uni.$u.api.login()
			this.getCarInfo()
		} catch (error) {
			uni.$u.alertError(error)
		}
	},
	onShow: function () {
		console.log('App Show')
	},
	onHide: function () {
		console.log('App Hide')
	},
	methods: {
		async getCarInfo() {
			try {
				if (!userStore.token) return
				const res = await uni.$u.api.getCarInfo()
				serviceStore.setCurrentCar(res)
				setTimeout(() => {
					this.getCarInfo()
				}, 1000)
			} catch (error) {
				console.error(error);
				serviceStore.setCurrentCar(null)
				throw error
			}
		}
	}
}
</script>

<style lang="scss">
/*每个页面公共css */
@import '@/uni_modules/uni-scss/index.scss';
@import 'uni.scss';
@import '@/uni_modules/vk-uview-ui/index.scss';

// 设置整个项目的背景色
page {
	background-color: #f5f5f5;
}

uni-page-body {
	min-height: 100%;
	height: 100%;
}
</style>
