<template>
	<view>
		<index ref="首页" v-show="page == '首页'" @changePage="changePage" />
		<my-case ref="案例" v-show="page == '案例'" />
		<dataBank ref="资料库" v-show="page == '资料库'" />
		<school ref="商学院" v-show="page == '商学院'" />
		<product ref="单品" v-show="page == '单品'" />

		<bottom-suspension-frame ref="pages" @onChange="pageChange" />
	</view>
</template>

<script>
import index from './index/index.vue'
import myCase from './index/myCase.vue'
import dataBank from './cloud/dataBank.vue'
import school from './cloud/school.vue'
import product from './cloud/product.vue'

import bottomSuspensionFrame from "./modules/bottomSuspensionFrame.vue";
export default {
	components: { bottomSuspensionFrame, index, myCase, dataBank, school, product },
	data() {
		return {
			swiperItemID: 'index',
			page: '首页'
		}
	},
	onShow() {
		// #ifdef MP-WEIXIN
		this.updatePageData(this.swiperItemID, this.page)
		// #endif
	},
	methods: {
		updatePageData(itemId, page) {
			if (this.$refs[this.page].updatePage) this.$refs.pages.onClick(itemId, page)
		},
		changePage(itemId, page, params) {
			this.$refs.pages.onClick(itemId, page, false, params)
		},
		pageChange(detail) {
			uni.setNavigationBarTitle({
				title: detail.name,
			})
			this.page = detail.name;
			try {
				console.log(this.$refs[detail.name].updatePage)
				if (this.$refs[detail.name].updatePage) uni.pageScrollTo({
					scrollTop: 0,
					duration: 0,
				})
				this.$refs[detail.name].init(detail.callBack, detail.params)
			} catch (error) {
				detail.callBack()
			}
			console.log("切换页面", detail)
		}
	}
}
</script>

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