<template>
    <view>
        <view class="tabbar-container" :class="isIpx?'IpxBot':''">
            <view class="tabbar-item" v-for="(item,index) in tabList" :class="[item.centerItem ? 'center-item' : '']"
                @click="changeItem(item)" :key="index">
                <view :class="item.imgclass" :style="{padding: item.id == 0?0:'10rpx'}">
                    <image :src="tabId==item.id?item.selectIcon:item.icon" mode=""></image>
                </view>
                <view class="item-bottom" :class="[tabId==item.id ? 'item-active' : '']">
                    <text>{{item.text}}</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        props: {
            currentPage: {
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                //适配IPhoneX
                isIpx: false, 
                //底部Tab
                tabId: 0,
				// 列表
				tabList: [ {
				    id: 2,
				    path: "/pages/list/tpxw",
				    icon: "/static/tab/tpxw.png",
				    selectIcon: "/static/tab/tpxwcur.png",
				    text: "新闻资讯",
				    centerItem: false,
					imgclass:"tpxw item-top"
				},{
				    id: 0,
				    path: "/pages/index/index",
				    icon: "/static/tab/home.png",
				    selectIcon: "/static/tab/homes.png",
				    text: "首页",
				    centerItem: true,
					imgclass:"home item-top"
				}, {
				    id: 3,
				    path: "/pages/index/mine",
				    icon: "/static/tab/mine.png",
				    selectIcon: "/static/tab/minecur.png",
				    text: "个人中心",
				    centerItem: false,
					imgclass:"mine item-top"
				}],
            }
        },
        mounted() {
            this.tabId = this.currentPage;
            //隐藏原生tab
            uni.hideTabBar();
        },
        created() {
            // 判断为 iPhone X 给予底部距离
            let that = this
            uni.getSystemInfo({
                success: function(res) {
                    if (res.model.indexOf('iPhone X') !== -1) {
                        that.isIpx = true;
                    }
                }
            })
        },
        methods: {
            // tab 切换
            changeItem(item) {
                uni.switchTab({
                    url: item.path,
                });
            },

        }
    }
</script>
<style scoped>
    view {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }

    .tabbar-container {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        /* height: 100rpx; */
        box-shadow: 0 0 5px #999;
        display: flex;
        align-items: center;
        padding: 5rpx 0;
        color: #999999;
        background-color: #FFFFFF;
		z-index:99
    }

    .tabbar-container .tabbar-item {
        width: 33%;
        height: 140rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
		color:##808080;
    }

    .tabbar-container .item-active {
        color: #DE242F;
    }

    .tabbar-container .center-item {
        display: block;
        position: relative;
    }

    .tabbar-container .tabbar-item .item-top {
        width: 70rpx;
        height: 70rpx;
        padding: 5rpx;
    }

    .tabbar-container .center-item .item-top {
        flex-shrink: 0;
        width: 140rpx;
        height: 140rpx;
        position: absolute;
        top: -60rpx;
        left: calc(54% - 70rpx);
        border-radius: 50%;
        /* box-shadow: 0 0 5px #999; */
		box-shadow: 0px -3px 4px rgb(0 0 0 / 6%);
        background-color: #FFFFFF;
    }
	.tabbar-container .tabbar-item .tpxw{
	    width:84rpx;
		height:84rpx;
	}
	.tabbar-container .tabbar-item .item-top.mine{
	    width:80rpx;
		height:84rpx;
	}

    .tabbar-container .tabbar-item .item-top image {
        width: 100%;
        height: 100%;
    }
	.tabbar-container .center-item .item-top image{
		width: 120rpx;
		height: 120rpx;
		margin-top:10rpx;
	}


    .tabbar-container .tabbar-item .item-bottom {
        font-size: 28rpx;
        width: 100%;
    }

    .tabbar-container .center-item .item-bottom {
        position: absolute;
        bottom: 10rpx;
		left:8rpx
    }

    /* 适配iPhone X */
    .IpxBot {
        padding-bottom: 30rpx !important;
    }
</style>