<template>
	<view class="footer flex p-y-xs2 bg-tab-nav">
		<view class="flex-fill" v-for="item,index in navList" :key="index" @click="tabChange(item.url)">
			<view class="icon">
				<image class="h-15" v-if="item.url.split('?')[0] == activeRouter" :src="item.activeIcon" mode="heightFix"></image>
				<image class="h-15" v-else :src="item.icon" mode="heightFix"></image>
			</view>
			<view class="fn-12" :class="{ 'router-link-active': item.url.split('?')[0] == activeRouter }">{{ $t(item.label) }}</view>
			<view class="tip-right" v-if="item.num">
				{{item.num}}
			</view>
		</view>
	</view>
</template>
<script>
	import {
		leak_num
	} from '@/api/index.js';
	import {
		mapMutations
	} from "vuex";
	import {
		navList
	} from "./list.js";
	export default {
		computed: {
			navList
		},
		data() {
			return {
				activeRouter:''
			};
		},
		created() {
			const routes = getCurrentPages(); //获取当前打开过的页面路由数组
			const curRoute = routes[routes.length - 1].route //获取当前页面路由
			this.activeRouter = '/' + curRoute;
			this.leak_num();
		},
		methods: {
			...mapMutations('user', [ 'setOrderNumber']),
			leak_num(){
				leak_num().then(res => {
					this.setOrderNumber(res.data.num)
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: 'none',
					})
				});
			},
			tabChange(url) {
				uni.switchTab({
					url: url
				});
			},
		},
	};
</script>
<style lang="scss" scoped>
	.flex-fill{
		text-align: center;
		line-height: 1;
		position: relative;
	}
	.p-y-xs2 {
		padding: 4px 0px;
	}
	.h-15{
		height: 20px;
		width: 20px;
	}
	.footer {
		box-shadow: 0rpx 2rpx 5rpx 0rpx rgba(0,0,0,0.16);
		border-top: 1rpx solid #f8f8f8;
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		z-index: 999 !important;
		color: rgba(#fff, 0.3);
		justify-content: space-around !important;
		.tip-right{
			font-size: $font-sm;
			color: #FFF;
			background-color: $uni-color-error;
			border-radius: 100%;
			position: absolute;
			right:-1em;
			top: -1em;
			min-width: 1.5em;
			height: 1.5em;
			line-height: 1.5em;
		}
	}
	.fn-12{
		margin-top: 4px;
		color:#666992;
		font-size:24rpx ;
	}
	.router-link-active {
		color:#17C474;
	}

	.bg-tab-nav {
		background-color: #fff;
	}
</style>