123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- export default {
- data() {
- return {
- listData: [],
- listParams: {
- page: 0,
- limit: 15
- },
- listStatus: ''
- }
- },
- methods: {
- getList(params = {}, refresh = false) {
- if (!this.GetListFn) return
- if (!refresh && this.listStatus === 'loading') return
- this.listStatus = 'loading'
- if (refresh) {
- this.listOver = false
- this.listParams.page = 0
- }
- this.listParams.page++
- this.listParams = Object.assign(this.listParams, params)
- // 额外附加的参数
- if (this.getParams) {
- const params = this.getParams()
- this.listParams = Object.assign(this.listParams, params)
- }
- const flag = this.beforeGetList(this.listParams)
- if (!flag) {
- this.listStatus = 'more'
- return
- }
- this.GetListFn(this.listParams).then(res => {
- console.log('list refresh: ', refresh)
- if (this.listParams.page === 1) {
- this.listData = []
- }
- this.listData = this.listData.concat(res.list)
- // this.listData = res.list.slice(0, 2)
- if (res.hasOwnProperty('lastPage')) {
- this.listStatus = res.lastPage ? 'noMore' : 'more'
- } else {
- this.listStatus = res.list.length === 0 ? 'noMore' : 'more'
- }
- // console.log('list status: ', this.listStatus, res)
- // 列表数据获取完成后回调
- if (this.getListCallback) {
- this.getListCallback(res)
- }
- }).catch(() => {
- this.listStatus = 'more'
- })
- },
- getParams() {
- return {}
- },
- beforeGetList() {
- return true
- }
- }
- }
|