// component/tabBar/tabBar.ts
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        //接收的json,用来显示tab
        tabItemJson: {
            type: Array,
            value: []
        },
        //默认点击第几个(默认第一个)
        initTabIndex: {
            type: Number,
            value: 0
        },
        canChangeIndex: {
            type: Boolean,
            value: true
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        currentTab: 0,
    },

    lifetimes: {
        attached: function () {
            // 在组件实例被从页面节点树添加时执行

            this.initTab(this.properties.initTabIndex)

        },
        detached: function () {
            // 在组件实例被从页面节点树移除时执行

        },
    },
    /**
     * 组件的方法列表
     */
    methods: {
        //选择某一项并且给上层id
        bindTabItem: function (event: any) {
            if(this.properties.canChangeIndex){
                this.initTab(Number(event.target.id))
            }
        },
        initTab: function (index: any) {
            this.setData({
                currentTab: index
            })
            this.triggerEvent('selectItemIndex', { selectIndex: index });
        }
    }
})