export default {
    data() {
        return {
            empty: false,
            loading: false,
            finished: false,
            page: 0
        };
    },
    methods: {
        getData(isFirst = false) {
            console.log('调动了');
            if (isFirst) {
                this.page = 0;
                this.lists = [];
                this.$root.$el.scrollTop = 0;
            }

            this.loading = true;
            this.finished = false;
            this.empty = false;
            let data = { page: this.page, size: 20, sort: 'createdAt,desc' };
            if (this.beforeData) {
                data = {
                    ...data,
                    ...this.beforeData()
                };
            }

            this.$http.post(this.url, data, { body: 'json' }).then(res => {
                this.lists = [...this.list, ...res.content];
                this.empty = res.empty;
                this.loading = false;
                this.finished = res.last;
                if (!this.finished) {
                    this.page = this.page + 1;
                }
            });
        }
    }
};
