<template>
	<view class="ezy-xuexi-page">
		<view class="icon-title-navBar-box">
			<text class="nav-bar-title">学习</text>
		</view>
		<chanpin1 v-if="chanpinId==1" ref="chanpin1Ref"></chanpin1>
		<!-- 底部 tabBar -->
		<custom-tab-bar :show="true" :current-index="currentTabIndex" />
	</view>
</template>

<script>
	import CustomTabBar from '@/components/custom-tabbar/index.vue';
	import cacheManager from "@/utils/cacheManager.js";
	import {
		onLoad,
		onShow,
		onHide,
		onUnload
	} from "@dcloudio/uni-app"
	import {
		toast
	} from '../../utils/common';
	import chanpin1 from './chanpin1'
	import {
		banbenImpinfo
	} from "@/api/login.js"
	export default {
		data() {
			return {
				currentTabIndex: 1,
				banbenId: '',
				chanpinId: ''
			}
		},
		components: {
			CustomTabBar,
			chanpin1
		},
		onLoad(options) {
			uni.hideTabBar()
		},
		onShow() {
			this.currentTabIndex = 1
			const cacheData = cacheManager.get('contentInfo');
			if (cacheData) {
				console.log('使用缓存数据');
			this.switchUseCache(cacheData)
			} else {
				console.log('重新请求数据,请求版本内容详情接口');
				this.getBanbenInfo();
			}
		},
		onHide() {
			console.log('学习页面隐藏')
		},
		onUnload() {
			// 页面卸载无需特殊处理
		},
		methods: {
			switchUseCache(data){
				switch (Number(data.chanpinId)) {
					case 1:
						this.$nextTick(() => {
							this.$refs.chanpin1Ref.initData()
						})
						break;
					case 2:
				
						break;
					default:
				
				}
			},
			switchGetNeiRongInfo(data) {
				switch (Number(data.chanpinId)) {
					case 1:
						const banbenId = data.banbenId
						this.$nextTick(() => {
							this.$refs.chanpin1Ref.initData(banbenId)
						})
						break;
					case 2:

						break;
					default:

				}
			},
			getBanbenInfo() {
				banbenImpinfo({}).then(res => {
					if (res.code == 0) {
						this.chanpinId = res.data.chanpinId
						this.switchGetNeiRongInfo(res.data)
					} else {
						toast('请求版本内容详情接口数据异常')
						return
					}
				}).catch(() => {
					toast('请求版本内容详情接口数据异常')
					return false
				})
			},
		},
		computed: {}
	}
</script>