<template>
    <view class="tab">
        <view
            :class="'tab-item ' + (cur - 0 === index - 0 ? 'cur' : '') + ' ' + (noBg ? 'noBg' : '')"
            :data-index="index"
            @tap="tabChange"
            v-for="(item, index) in tabList"
            :key="index"
        >
            <text>{{ item.label }}</text>

            <image mode="widthFix" src="/static/images/statistics/sel.png" style="width: 12rpx; height: 8rpx" class="cur-img" />
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            cur: 0
        };
    },
    props: {
        tabList: {
            type: Array
        },
        noBg: {
            type: Boolean,
            default: false
        }
    },
    methods: {
        tabChange(e) {
            let index = e.currentTarget.dataset.index;
            this.setData({
                cur: index
            });
            this.$emit('tabChange', {
                detail: index
            });
        }
    },
    created: function () {}
};
</script>
<style>
.tab {
    display: flex;
}
.tab .tab-item {
    background: #f4f8fe;
    border: 2px solid #d6e6fc;
    border-radius: 6rpx;
    flex: 1;
    padding: 25rpx 20rpx;
    font-size: 30rpx;
    color: #999999;
    margin: 0 15rpx 30rpx;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tab .tab-item.cur {
    color: #3a80e7;
    position: relative;
}

.tab .tab-item.noBg {
    background: none !important;
    border: none !important;
    margin: 0 0rpx 30rpx;
}
.cur-img {
    display: none;
}
.tab .tab-item.cur:before {
    content: '';
    display: block;
    height: 5rpx;
    width: 100%;
    background: #3a80e7;
    position: absolute;
    bottom: 0;
    left: 0;
}
.tab .tab-item.cur .cur-img {
    display: block;
    position: absolute;
    bottom: -8rpx;
    left: calc(50% - 6rpx);
}
</style>
