forked from nsjcy/frontEnd/nsjcy

liuwh
2020-05-09 6ee2429b63ff94f80a5c3e5db963ef77745b0094
SunshineLnsMinApp/pages/dxal/dxal.js
@@ -1,9 +1,4 @@
// pages/dxal/dxal.js
import {
  $startWuxRefresher,
  $stopWuxRefresher,
  $stopWuxLoader
} from '../../templeteDist/wuxDist/index';
var app = getApp();
@@ -18,7 +13,8 @@
    dongtai3_1: app.globalData.imgUrl + '/image/dongtai3-1.jpg',
    inputShowed: false,
    inputVal: "",
    page:1,
    content: '------加载中------',
    items: [],
    count: 0,
    scrollTop: 0,
@@ -28,44 +24,53 @@
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    $startWuxRefresher();
  },
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  },
  onRefresh() {
    console.log('onRefresh')
    this.setData({
      count: 10
    })
    setTimeout(() => {
      this.setData({
        items: this.getList()
      })
      $stopWuxRefresher()
    }, 1000)
  },
  onLoadmore() {
    console.log('onLoadmore')
    setTimeout(() => {
      this.setData({
        items: [...this.data.items, ...this.getList(10, this.data.count)],
        count: this.data.count + 10,
      })
      if (this.data.items.length < 30) {
        $stopWuxLoader()
      } else {
        console.log('没有更多数据')
        $stopWuxLoader('#wux-refresher', this, true)
    var that = this;
    wx.showLoading();
    wx.request({
      url: app.globalData.url + '/api/article/publicMsgQuery',
      data: {
        page: that.data.page,
        size: 10,
        flag: '典型案例',
      },
      success: function(res) {
        wx.hideLoading();
        console.log('res', res);
        if (res.data.code == 0) {
          let content = res.data.data.result.content.map(({
            createTime,
            ...i
          }) => ({
            ...i,
            createTime: app.formatDate(createTime),
          }));
          console.log(content)
          if (content.length < 10) {
            that.setData({
              items: [...that.data.items, ...content],
              hasMoreData: false,
              content: '------我是有底线的------'
            })
          } else {
            that.setData({
              items: [...that.data.items, ...content],
              hasMoreData: true,
              content: '------加载更多------',
              page: that.data.page + 1
            })
          }
        } else {
          wx.showToast({
            title: res.data.msg,
          })
        }
      }
    }, 1000)
    })
  },
  getList: (count = 10, step = 0) => [...new Array(count)].map((n, i) => ({
    title: `Pull down ${i + step}`,
    content: 'Wux Weapp'