<template>
    <global-page>
        <home v-show="tabbarValue == 'home'"></home>
        <panel v-show="tabbarValue == 'panel'"></panel>
        <chat v-show="tabbarValue == 'chat'"></chat>
        <template #bottom>
            <global-button size="large" type="primary" @tap="handleLogOut" v-show="tabbarValue == 'home'">退出登录</global-button>
            <custom-tabbar v-model="tabbarValue"></custom-tabbar>
        </template>
    </global-page>
</template>

<script setup>
import home from '../home/index.vue'
import panel from '../panel/index.vue'
import chat from '../chat/index.vue'
import { ref, watch } from 'vue'
import useUserStore from 'mocp/store/user'
import useBaseStore from 'mocp/store/base'
import { findWeatherSynopsesMessagesApi } from 'mocp/api/panel'
import { onLoad } from '@dcloudio/uni-app'

const userStore = useUserStore()
const baseStore = useBaseStore()
//天气信息
const weatherInfo = ref()
const findWeatherSynopsesMessages = async () => {
    const res = await findWeatherSynopsesMessagesApi({ airportCode: userStore.userInfo.terminal })
    if (res.code == 200 && res.data) {
        weatherInfo.value = res.data[res.data.length - 1]
        uni.$emit('sendWeatherInfo', weatherInfo.value)
    }
}
onLoad(async () => {
    //加载基础参数
    await baseStore.initSysData()
    //加载天气信息
    await findWeatherSynopsesMessages()
})
//页面参数
const query = defineProps(['name'])
const tabbarValue = ref(query.name || 'panel')
watch(tabbarValue, (value) => {
    if (value == 'panel') {
        findWeatherSynopsesMessages()
    }
})
//退出登录
const handleLogOut = () => {
    userStore.handleLogOut()
}
</script>

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