admin
2020-12-19 84920ada00d69565bef33e7e31bc32b426ec5dc3
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
108
109
110
111
112
113
114
115
116
117
118
119
var help = require('../../util/help.js');
var api = require('../../util/api.js');
var $this;
Page({
  data: {
    /* 列表数据开始 */
    list: [],
    showLoading: false,
    page: 1,
    total: 0,
    showEmptyDefault: false,
    isRequesting: false,//是否正在请求中
    showFooter: false,
    /* 列表数据结束 */
  },
  onLoad() {
    help.setPageNavBar("浏览足迹");
    $this = this;
    $this.requestActivity(1, true);
  },
  onPullDownRefresh() {
    console.log('onPullDownRefresh', new Date());
    my.showToast({
      content: "下拉刷新触发"
    });
    this.requestActivity(1);
  },
  //请求活动
  requestActivity(page, first) {
    $this.setData({
      page: page,
      isRequesting: true,
      showEmptyDefault:false
    });
    api.getScanActivityRecord({
      page: page,
      showLoading: first,
      success: function (res) {
        console.log(res)
        if (res.code == 0) {
          var list =res.data.data;
          //设置列表数据
          if (list != null && list.length > 0) {
            var totalList = $this.data.list.concat(list);
            if (page == 1) {
              totalList = list;
            }
            $this.setData({
              total: res.data.count,
              list: totalList,
              showFooter: totalList.length >= res.data.count
            })
          }
          //设置空列表默认显示
          if (page == 1 && (list == null || list.length == 0)) {
            $this.setData({
              showEmptyDefault: true
            })
          }
        } else {
          my.showToast({
            content: res.msg
          });
        }
      },
      fail: function () {
        //请求失败需要将页码减1
        if ($this.data.page > 1) {
          $this.setData({
            page: $this.data.page - 1
          });
        }
      },
      complete: function () {
        my.stopPullDownRefresh();
        setTimeout(() => {
          $this.setData({
            isRequesting: false,
            showLoading: false
          });
        }, 1000);
 
      }
    });
 
  },
  //下拉刷新
  onPullDownRefresh() {
    this.requestActivity(1, false);
  },
  //到达底部
  async scrollMytrip() {
    if (this.data.isRequesting)
      return;
    try {
      console.log('scrollMytrip:');
      const { page, list, } = this.data;
      // 判断是否还有数据需要加载
      if (list.length < this.data.total) {
        //开启加载
        this.setData({ showLoading: true });
        const newPage = page + 1;
        $this.requestActivity(newPage);
      }
    } catch (e) {
      this.setData({ showLoading: false });
      console.log('scrollMytrip执行异常:', e);
    }
  },
  clickItem(event) {
    var item = help.getEventParam(event, 'item');
    console.log(item.activity.id);
    my.navigateTo({
      url: '/pages/activity-detail/activity-detail?id=' + item.activity.id
    });
  }
 
 
});