forked from nsjcy/frontEnd/nsjcy

liyj
2020-02-11 e60e253cb3ce0597ded89b56a414c731e28c4ff1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// lawPublicity.js
const app = getApp();
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    dataSet: [],
    isHideLoadMore: true, //loading样式
    isHideMorebtn: true, //更多按钮样式
    isHideEnd: true, //有底线样式  (三者默认隐藏)
    size: 10
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      isHideLoadMore: false
    }, this.showList(options.id))
  },
 
  showList: function(id) {
    var that = this;
    // d46ee05998ce48f893a63623cbde6875
    wx.request({
      url: app.globalData.url + '/api/article/legalServiceQuery?page=1&size=' + that.data.size + '&ownerId=' +id,
      success: function(res) {
        console.log(res)
        if (res.data.code == 0) {
          (res.data.data.content).forEach(e => {
            (e.createTime) = app.formatDate(e.createTime)
          })
          var dataSet = res.data.data.content;
          if (res.data.data.totalElements < that.data.size) {
            // 到底了,没数据加载
            that.setData({
              dataSet,
              isHideMorebtn: true, //隐藏更多按钮
              isHideEnd: false //显示已到底
            })
          } else {
            that.setData({
              dataSet,
              size: that.data.size + 10,
              isHideMorebtn: false, //显示更多按钮
              isHideEnd: true //隐藏已到底
            })
          }
        } else {
          wx.showModal({
            title: '提示',
            content: "请求失败!"
          })
        }
      },
      complete: function() {
        that.setData({
          isHideLoadMore: true
        })
      }
    })
  },
 
  // 跳转详情
  link: function(e) {
    var id = e.currentTarget.dataset.id;
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '../lawPublicityDetail/lawPublicityDetail?id=' + id
    })
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
 
  },
 
  // 加载更多
  getMore: function() {
    // 有加载更多按钮
    if (!this.data.isHideMorebtn) {
      this.setData({
        isHideMorebtn: true, //隐藏点击按钮
        isHideLoadMore: false //显示loading状态
      })
      setTimeout(() => {
        this.setData({
          isHideLoadMore: true //1.2s后隐藏loading
        });
        this.showList() //重新定义列表
      }, 1200)
    }
  }
 
})