Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        title: {
            type: String,
        },
        type: {
            type: String,
            value: "全部"
        },
        list: {
            type: Array,
        },
        onChange: {
            type: Function,
        },
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
            this.setData({
                actions: this.data.list.map(item => {
                    return {
                        name: getApp().globalData.Language.getMapText(item.remarks || item.value),
                        value: item.value,
                        color: item.value == this.data.type ? "#3874F6" : ""
                    }
                })
            })
            this.setShowText();
        }
    },
    data: {
        actionShow: false,

    },
    methods: {
        setShowText() {
            this.setData({
                showText: this.data.actions.find(item => item.value == this.data.type).name
            })
        },
        openActionSheet() {
            this.setData({
                actionShow: true
            })
        },
        onSelect(event) {
            const {
                value
            } = event.detail;
            if (this.data.type == value) return this.onCancel();
            this.setData({
                actions: this.data.actions.map(item => {
                    item.color = item.value == value ? "#3874F6" : "";
                    item.loading = item.value == value ? true : false;
                    return item
                })
            })
            this.triggerEvent("onChange", value)
        },
        onCancel() {
            this.setData({
                actionShow: false,
                actions: this.data.actions.map(item => {
                    item.loading = false;
                    return item
                })
            })
            this.setShowText();
        }
    }
})