<template>
	<view class="container">
		<enterNavigator :selectedIndex="nav_current_index" @clickToIndex='homeNavigatorClick'/>
		<home :viewTop="subviewTop" :viewHeight="subviewHeight" v-show="nav_current_index == config.page_index.home" />
		<AIChat :viewTop="subviewTop" :viewHeight="subviewHeight" v-show="nav_current_index == config.page_index.ai_chat" />
		<AIDraw :viewTop="subviewTop" :viewHeight="subviewHeight" v-show="nav_current_index == config.page_index.ai_draw" />
	</view>
</template>

<script>
	import enterNavigator from '../../pages/enter/enter-navigator.vue'
	import home from '../../pages/home/home.vue'
	import AIChat from '../../pages/AI_chat/AI_chat.vue'
	import AIDraw from '../../pages/AI-draw/AI-draw.vue'
	import config from '../../utils/config.js'
	export default {
		data() {
			return {
				nav_current_index: 0,     // 当前导航索引
				subviewTop: 0,
				subviewHeight: 0,
			}
		},
		mounted() {
			let systemInfo = uni.getSystemInfoSync()
			
			this.subviewTop = 60
			this.subviewHeight = systemInfo.screenHeight - this.subviewTop
			
			this.onNotification()
		},
		onUnload() {
			this.offNotification()
		},
		methods: {
			onNotification() {
				let self = this
				uni.$on(config.notification.switch_page_index, function(index) {
					// console.log('notification_index', index)
					if(self.nav_current_index == index) {
						return
					}
					self.nav_current_index = index
				})
			},
			offNotification() {
				uni.$off(config.notification.switch_page_index)
			},
			homeNavigatorClick(index) {
				if(index == config.page_index.ai_chat ||
				   index == config.page_index.ai_draw) {
					if(this.tools.is_login_gotoLogin(index) == false) {
						return
					}
				}
				this.nav_current_index = index
				this.tools.current_navigator_page_index = index
			}
		},
		components: {
			enterNavigator,
			home,
			AIChat,
			AIDraw
		}
	}
</script>

<style lang="scss">
	.container{
		background-color: #2A2832;
	}
</style>
