export default {
    data() {
        return {
            running: false
        }
    },
    props: {
        value: {
            type: Boolean,
            default: false
        },
        block: {
            default: true
        },
        title: {
            default: '正在处理您的请求',
            type: String
        }
    },
    mounted() {
        this.$el.style.display = 'none !important';
    },
    watch: {
        running() {
            if (this.running) {
                this.showTriggle && this.showTriggle()
            } else {
                this.hideTriggle && this.hideTriggle()
            }
            this.render();
            this.$emit('input', this.running);
        },
        value: {
            handler() {
                this.running = this.value;
            },
            immediate: true
        }
    },
    methods: {
        render() {
            this.$el.style.display = this.running ? (this.block ? 'block !important' : 'inline-block !important') : 'none !important';
        },
        show() {
            this.running = true;
        },
        hide() {
            this.running = false;
        },
        wait(fn) {
            this.show();
            return new Promise(async ok => {
                let ds = await fn();
                this.hide();
                ok(ds);
            });
        }
    }
}