2023-01-11 16:33:13 +08:00
|
|
|
export default {
|
2023-04-04 08:47:19 +08:00
|
|
|
onPullDownRefresh() {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.store && this.store.reload()
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
2023-04-04 08:47:19 +08:00
|
|
|
onReachBottom() {
|
|
|
|
|
if (this.store.status != 'noMore') {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.store.next && this.store.next()
|
2023-01-11 16:33:13 +08:00
|
|
|
}
|
|
|
|
|
},
|
2023-04-04 08:47:19 +08:00
|
|
|
data() {
|
2023-01-11 16:33:13 +08:00
|
|
|
return {
|
|
|
|
|
store: {},
|
2023-08-10 09:18:17 +08:00
|
|
|
}
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2023-04-04 08:47:19 +08:00
|
|
|
DataSource(url) {
|
2023-08-10 09:18:17 +08:00
|
|
|
var me = this
|
2023-01-11 16:33:13 +08:00
|
|
|
return {
|
|
|
|
|
data: [],
|
2023-11-06 11:01:29 +08:00
|
|
|
status: 'noMore',
|
2023-01-11 16:33:13 +08:00
|
|
|
empty: false,
|
|
|
|
|
total: 0,
|
2023-03-30 09:04:07 +08:00
|
|
|
header: {
|
2023-04-04 08:47:19 +08:00
|
|
|
'Content-Type': 'application/json;charset=UTF-8',
|
2023-03-30 09:04:07 +08:00
|
|
|
},
|
2023-01-11 16:33:13 +08:00
|
|
|
params: {
|
2023-07-03 09:16:54 +08:00
|
|
|
pageNum: 1,
|
2023-03-30 09:04:07 +08:00
|
|
|
pageSize: 20,
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
2023-09-06 18:13:08 +08:00
|
|
|
timer: null,
|
2023-08-23 16:22:08 +08:00
|
|
|
callBack: null,
|
|
|
|
|
firstCallBack: null,
|
|
|
|
|
loadedCallback: null,
|
2023-04-04 08:47:19 +08:00
|
|
|
reload() {
|
2023-11-06 11:01:29 +08:00
|
|
|
if (this.status == 'loading') return
|
2023-08-10 09:18:17 +08:00
|
|
|
this.data = []
|
|
|
|
|
this.empty = false
|
|
|
|
|
this.params.pageNum = 1
|
|
|
|
|
this.next()
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
2023-08-23 16:22:08 +08:00
|
|
|
search() {
|
|
|
|
|
// 节流搜索
|
|
|
|
|
clearTimeout(this.timer)
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
|
|
this.reload()
|
|
|
|
|
}, 300)
|
|
|
|
|
},
|
2023-04-04 08:47:19 +08:00
|
|
|
next() {
|
2023-11-06 11:01:29 +08:00
|
|
|
this.status = 'loading'
|
2023-01-11 16:33:13 +08:00
|
|
|
me.$request({
|
|
|
|
|
url: url,
|
2023-03-30 09:04:07 +08:00
|
|
|
data: this.params,
|
2023-01-11 16:33:13 +08:00
|
|
|
header: this.header,
|
2023-04-04 08:47:19 +08:00
|
|
|
method: 'POST',
|
2023-10-26 09:03:16 +08:00
|
|
|
debounce: false,
|
2023-01-11 16:33:13 +08:00
|
|
|
}).then((res) => {
|
2023-08-10 09:18:17 +08:00
|
|
|
console.warn(res)
|
2023-09-06 18:13:08 +08:00
|
|
|
let resultData = res.data?.list || res.data?.records || res.data || []
|
2023-07-03 09:16:54 +08:00
|
|
|
if (this.params.pageNum == 1) {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.data = resultData
|
2023-01-11 16:33:13 +08:00
|
|
|
if (resultData.length == 0 || resultData == 0) {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.empty = true
|
|
|
|
|
this.status = 'noMore'
|
|
|
|
|
} else if (resultData.length < this.params.pageSize) {
|
|
|
|
|
this.status = 'noMore'
|
2023-01-11 16:33:13 +08:00
|
|
|
} else if (res.total == resultData.length) {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.status = 'noMore'
|
2023-11-06 11:01:29 +08:00
|
|
|
} else {
|
|
|
|
|
this.status = 'more'
|
2023-01-11 16:33:13 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.data.push(...resultData)
|
2023-03-30 09:04:07 +08:00
|
|
|
if (resultData.length < this.params.pageSize) {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.status = 'noMore'
|
2023-11-06 11:01:29 +08:00
|
|
|
} else {
|
|
|
|
|
this.status = 'more'
|
2023-01-11 16:33:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 09:16:54 +08:00
|
|
|
if (this.params.pageNum == 1) {
|
2023-08-10 09:18:17 +08:00
|
|
|
this.firstCallBack && this.firstCallBack()
|
2023-01-11 16:33:13 +08:00
|
|
|
}
|
2023-08-10 09:18:17 +08:00
|
|
|
this.loadedCallback && this.loadedCallback()
|
|
|
|
|
this.params.pageNum++
|
|
|
|
|
this.total = res.total
|
|
|
|
|
this.loading = false
|
2023-11-06 11:01:29 +08:00
|
|
|
uni.stopPullDownRefresh()
|
2023-08-10 09:18:17 +08:00
|
|
|
})
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
2023-08-10 09:18:17 +08:00
|
|
|
}
|
2023-01-11 16:33:13 +08:00
|
|
|
},
|
|
|
|
|
},
|
2023-08-10 09:18:17 +08:00
|
|
|
}
|