|
@@ -0,0 +1,87 @@
|
|
|
+const { request } = require('../api/request')
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ data: {
|
|
|
+ searchForm: {
|
|
|
+ key_words: ''
|
|
|
+ },
|
|
|
+ pagenum: 0,
|
|
|
+ pagesize: 20,
|
|
|
+ finished: false, // 所有数据是否加载完
|
|
|
+ isRefresh: false, // 是否下拉刷新
|
|
|
+ isFetchLock: false, // 接口调用加锁
|
|
|
+ list: [],
|
|
|
+ freshing: false
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleKeyWords(event) {
|
|
|
+ this.setData({
|
|
|
+ 'searchForm.key_words': event.detail
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async fetOrderList() {
|
|
|
+ const that = this
|
|
|
+ const isRefresh = that.data.isRefresh
|
|
|
+
|
|
|
+ if (that.data.finished) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (that.data.isFetchLock) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ that.setData({
|
|
|
+ isFetchLock: true,
|
|
|
+ pagenum: that.data.pagenum + 1
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ const { status, data, msg } = await request({
|
|
|
+ url: that.data.api,
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ 'page': that.data.pageNum,
|
|
|
+ 'page_size': that.data.pageSize,
|
|
|
+ key_words: that.data.searchForm.key_words
|
|
|
+ },
|
|
|
+ showLoading: true
|
|
|
+ })
|
|
|
+ if (status) {
|
|
|
+ const { list } = data
|
|
|
+ if (Array.isArray(list)) {
|
|
|
+ const _list = isRefresh ? [].concat(list) : that.data.list.concat(list)
|
|
|
+
|
|
|
+ that.setData({
|
|
|
+ list: _list,
|
|
|
+ finished: list.length < 10,
|
|
|
+ isRefresh: false,
|
|
|
+ isFetchLock: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (e) {}
|
|
|
+ if (that.data.freshing) {
|
|
|
+ that.data.freshing = false
|
|
|
+ }
|
|
|
+ if (isRefresh && wx.stopPullDownRefresh) {
|
|
|
+ wx.stopPullDownRefresh()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ refresh() {
|
|
|
+ this.setData({
|
|
|
+ pagenum: 0,
|
|
|
+ pagesize: 20,
|
|
|
+ finished: false,
|
|
|
+ isRefresh: true,
|
|
|
+ isFetchLock: false
|
|
|
+ }, () => {
|
|
|
+ this.fetOrderList()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|