Component({
    properties: {
        list: Array,
        callback: Function
    },
    data: {
        safeAreaBot: 0,
        show: false,
        showList: [],
        extend: []
    },
    lifetimes: {
        attached: function () {
            wx.getSystemInfo({
                success: res => {
                    this.setData({
                        safeAreaBot: res.screenHeight - res.safeArea.bottom
                    })
                }
            })
        },
    },
    observers: {
        'list': function (numberA, numberB) {
            if (numberA.length >= 5) {
                let showList = numberA.splice(0, 3);
                showList.push({
                    icon: "icon-gengduo",
                    label: "更多"
                })
                this.setData({
                    showList,
                    extend: numberA
                })
            } else {
                this.setData({
                    showList: numberA
                })
            }
        }
    },
    options: {
        addGlobalClass: true
    },
    methods: {
        onClose() {
            this.setData({
                show: false
            })
        },
        callback(e) {
            const {
                item
            } = e.currentTarget.dataset;
            if (item.label == '更多') return this.setData({
                show: true
            })
            if (this.data.show) this.setData({
                show: false
            })
            if (!item) return;
            this.triggerEvent("callback", item)
        }
    }
})