<template>
	<view class="ezy-custom-tabbar">
		<view class="tabbar-item-box" v-for="(item, index) in tabList" :key="index" @click="switchTab(item.path,index)">
			<view class="tabbar-item"
				:style="{ backgroundImage: 'url(' + (currentTab == index ? item.activePath : item.iconPath) + ')' }">
			</view>
		</view>
	</view>
	<tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
	<tishiDlVue ref="popupRef"></tishiDlVue>
</template>

<script>
	import {
		MESSAGE_VISITER_TO_LOGIN
	} from "@/utils/constant.js"
	import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
	import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
	import {
		useTabBarHistory
	} from '@/utils/emitEvents.js';
	import cacheManager from "@/utils/cacheManager.js";
	import {
		toast,
		getUserIdentity
	} from "@/utils/common";
	import {
		nextTick,
	} from "vue";
	import tishiDlVue from './tishiDl.vue';
	export default {
		components: {
			tipMiddleDialog,
			tipBigDialog,
			tishiDlVue
		},
		data() {
			return {
				tabList: [{
						iconPath: 'static/images/tabbar/unselect/xuanke-sj.png',
						activePath: 'static/images/tabbar/select/xuanke-sj.png',
						path: `/pages/chanpinXuanze/index`
					},
					{
						iconPath: 'static/images/tabbar/unselect/xuexi-sj.png',
						activePath: 'static/images/tabbar/select/xuexi-sj.png',
						path: `/pages/chanpinneirong/index`
					},
					{
						iconPath: 'static/images/tabbar/unselect/faxian-sj.png',
						activePath: 'static/images/tabbar/select/faxian-sj.png',
						path: '/pages/game/index'
					},
					{
						iconPath: 'static/images/tabbar/unselect/wode-sj.png',
						activePath: 'static/images/tabbar/select/wode-sj.png',
						path: `/pages/chanpinMy/my`
					},
				],
				currentTab: 0,
				isNavigating: false,
				MESSAGE_VISITER_TO_LOGIN
			};
		},
		props: {
			levelId: {
				type: String,
			},
			typeId: {
				type: String,
			},
			subjectId: {
				type: String,
			},
			currentTabNumber: {
				type: Number,
			},
			tipFlag: {
				type: String,
			},

		},
		methods: {
			// 游客弹窗---确定
			ykConfirm() {
				uni.redirectTo({
					url: '/pages/login/index'
				});
			},

			switchTab(path, index) {

				if (index == this.currentTab) {
					// 同页面不刷新
					return;
				}

				if (path == '/pages/chanpinneirong/index' && !cacheManager.get('auth').typeId) {
					this.$refs.popupRef.open();
					return false
				}
				this.currentTab = index;
				this.navigateToEditPage(path)

			},
			navigateToEditPage(path) {
				if (this.isNavigating) {
					uni.showToast({
						title: '正在跳转中...',
						icon: 'none'
					});
					return;
				}
				this.isNavigating = true;
				uni.showLoading({
					title: '加载中'
				}); // 显示Loading

				uni.redirectTo({
					url: path,
					complete: () => {
						uni.hideLoading();
						this.isNavigating = false;
					}
				});
			}
		},
		created() {

			this.currentTab = this.currentTabNumber
		}
	}
</script>