admin
2020-12-31 91fce32b078d7e29aa0260e5e47c7df602c4c5ee
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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,
    /* 列表数据结束 */
 
 
    //中奖弹框
    showDrawnModal: false,
    //过期未领弹框
    showOutDateModal: false,
    showNotice: false,
    noticeMode: 'closable',//closable
  },
 
  onLoad() {
    help.setPageNavBar("天天领现金");
    $this = this;
    $this.requestNotice();
    $this.requestActivity(1, true);
    //延时请求
    setTimeout(() => {
      $this.requestRecieveAwardNotify();
    }, 1000);
 
  },
 
  //请求活动
  requestActivity(page, first) {
    $this.setData({
      page: page,
      isRequesting: true,
      showEmptyDefault: false
    });
    if (first) {
      my.showNavigationBarLoading();
    }
    api.getRecommendActivity({
      data: {
        page: page
      },
      showErrorToast: true,
      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
            })
          }
        }
      },
      fail: function () {
        //请求失败需要将页码减1
        if ($this.data.page > 1) {
          $this.setData({
            page: $this.data.page - 1
          });
        }
      },
      complete: function () {
        my.hideNavigationBarLoading();
        my.stopPullDownRefresh();
        setTimeout(() => {
          $this.setData({
            isRequesting: false,
            showLoading: false
          });
        }, 1000);
 
      }
    });
 
  },
  requestNotice() {
    api.getNotice({
      position: 'home',
      success(res) {
        if (res.code == 0) {
          $this.setData({
            notice: res.data,
            showNotice: true,
            noticeMode: res.data.link ? 'link' : 'closable'
          })
        }
      }
    });
 
  },
  //获取奖项通知
  requestRecieveAwardNotify() {
    api.getRecieveAwardNotify({
      success: function (res) {
        if (res.code == 0) {
          if (res.data.type == 1)//领奖
          {
            $this.setData({
              award: res.data,
              showDrawnModal: true
            });
          } else if (res.data.type == 2)//过期
          {
            $this.setData({
              award: res.data,
              showOutDateModal: true
            });
          }
 
        }
      }
    });
  },
  //领奖
  onRecieveAward() {
    api.recieveAward({
      showLoading: true,
      showErrorToast: true,
      activityId: $this.data.award.activityId,
      success: function (res) {
        if (res.code == 0) {
          my.showToast({
            content: res.msg
          });
        } else {
          my.showToast({
            content: res.msg
          });
        }
      }
 
    });
  },
  onOutDateDetailClick() {
    api.setDrawnNotifyRead({
      id: $this.data.award.id,
      success: function (res) {
 
      }
    });
  },
 
  //下拉刷新
  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
    });
  },
  showDialog() {
 
 
  },
  onCloseDialog1() {
 
    this.setData({
      showDrawnModal: false
 
    });
 
 
  },
  onCloseDialog2(event) {
    this.setData({
      showOutDateModal: false
    });
  },
 
 
 
 
  onNoticeClick() {
 
    if (this.data.noticeMode == 'closable') {
      this.setData({
        showNotice: false
      });
    } else {
      my.showToast({
        content: "进入详情"
      });
      if ($this.data.notice.link) {
        my.navigateTo({
          url: '/pages/web/web?url=' + $this.data.notice.link
        })
      }
    }
  }
 
 
});