
export default {
    data() {
        return {
            pageNum: 1,
            pageSize: 20,
            tableData: [],
            isEmpty: false,
            isRequest: false,
            isRefreshClear: true
        }
    },
    methods: {
        reset() {
            this.pageNum = 1
            if (this.isRefreshClear) {
                this.tableData = []
            }
        },
        async refresh(loading = false) {
            if (this.isRequest) return
            this.isRequest = true
            this.reset()
            const res = await this.loadData(loading)
            uni.stopPullDownRefresh()
            if (res && res.length > 0) {
                this.tableData = res
                this.pageNum++
            } else {
                this.tableData = []
            }
            this.isEmpty = !this.tableData || this.tableData.length === 0
            this.isRequest = false
        },
        async loadMore(loading = false) {
            if (this.isRequest || this.tableData.length <= 0) return
            if (this.tableData.length % this.pageSize > 0) return
            this.isRequest = true
            const res = await this.loadData(loading)
            if (res && res.length > 0) {
                this.tableData = this.tableData.concat(res)
                this.pageNum++
            }
            this.isEmpty = !this.tableData || this.tableData.length === 0
            this.isRequest = false
        }
    }
}
