123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- const { request } = require('../api/request')
- const { debounce } = require('../utils/util')
- module.exports = {
- data() {
- return {
- pagenum: 1,
- pagesize: 20,
- finished: false, // 所有数据是否加载完
- isRefresh: false, // 是否下拉刷新
- isFetchLock: false, // 接口调用加锁
- listData: [],
- freshing: false
- }
- },
- methods: {
- handleKeyWords: debounce(function (event) {
- const { formkey } = event.target.dataset
- if (formkey) {
- this.setData({
- [`searchForm.${formkey}`]: event.detail.value
- }, () => {
- this.refreshOrderList()
- })
- }
- }, 2000),
- async fetchOrderList() {
- const that = this
- const isRefresh = that.data.isRefresh
- if (that.data.finished) {
- return
- }
- if (that.data.isFetchLock) {
- return
- }
- that.setData({
- isFetchLock: true
- })
- try {
- const { status, data, msg } = await request({
- url: that.data.listUrl,
- method: 'POST',
- data: {
- 'page': that.data.pagenum,
- 'page_size': that.data.pagesize,
- ...that.data.searchForm
- },
- showLoading: false
- })
- if (status) {
- const { list } = data
- if (Array.isArray(list)) {
- const listFormat = list.map(item => {
- if (that.data.listUrl === '/api/user/goods/shop/list') {
- return {
- ...item,
- shop_address: item.shop_address ? JSON.parse(item.shop_address) : {}
- }
- }
- if (that.data.listUrl === '/api/user/track/list') {
- return {
- ...item,
- track_img_url: item.track_img_url ? JSON.parse(item.track_img_url) : {}
- }
- }
- return {
- ...item
- }
- })
- const _list = isRefresh ? [].concat(listFormat) : that.data.listData.concat(listFormat)
- const temp = {
- listData: _list,
- finished: list.length < that.data.pagesize,
- isRefresh: false,
- isFetchLock: false,
- pagenum: that.data.pagenum + 1
- }
- // VR看菜园:轮播图只取前三个
- if (that.data.listUrl === '/api/user/vr/list') {
- temp['topSwiperData'] = _list.filter(item => item.top === 1)
- temp['listData'] = _list.filter(item => item.top !== 1)
- }
- if (isRefresh && this.data.hasOwnProperty('leftList')) {
- temp['leftList'] = []
- temp['rightList'] = []
- }
- that.setData(temp, () => {
- if (that.isLeft) {
- const timer = setTimeout(() => {
- clearTimeout(timer)
- that.isLeft(list)
- }, 500)
- }
- })
- }
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (e) {}
- if (that.data.freshing) {
- that.setData({
- freshing: false
- })
- }
- if (isRefresh && wx.stopPullDownRefresh) {
- wx.stopPullDownRefresh()
- }
- },
- refreshOrderList() {
- this.setData({
- pagenum: 1,
- pagesize: 20,
- finished: false,
- isRefresh: true,
- isFetchLock: false
- }, () => {
- this.fetchOrderList()
- })
- }
- }
- }
|