my-reward.page.js
2.07 KB
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
'use strict';
require('activity/my-reward.page.css');
let $ = require('yoho-jquery'),
yoho = require('yoho-app');
let page = 2,
searching = false,
winH = $(window).height();
// 获取推送消息开启状态
function getStatus() {
yoho.invokeMethod('get.usernotificationstatus', {}, function(res) {
if (parseInt(res, 10) === 1 || res === '1') {
$('.state').find('b').html('已开启');
} else if (parseInt(res, 10) === 0) {
$('.state').find('b').html('去开启');
}
});
}
if (yoho.isApp) {
// 提供给APP调取刷新
yoho.ready(function() {
yoho.addNativeMethod('refreshInfoPushState', function() {
getStatus();
});
});
}
// 点击开启状态跳转APP设置
$('.state').click(function() {
yoho.invokeMethod('go.appsetting');
});
// 活动规则展开与收起
$('.title').click(function() {
if ($(this).find('i').hasClass('down')) {
$('.detail').css('height', 'auto');
$(this).find('i').removeClass('down').html('');
} else {
$('.detail').css('height', '0px');
$(this).find('i').addClass('down').html('');
}
});
// 奖励列表数据
function moreList() {
if (searching) {
return;
}
searching = true;
$.ajax({
type: 'GET',
url: '/activity/reward-list',
data: {
page: page
},
success: function(data) {
if (data === '') {
return true;
}
$('.reward-list').append(data);
searching = false;
page++;
},
});
}
function scrollHandler() {
// 当scroll到3/4$goodsContainer高度后继续请求下一页数据
if ($(window).scrollTop() + winH >
$(document).height() - 0.25 * $('.reward-list').height()) {
moreList();
}
}
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
$(function() {
if (yoho.isApp) {
yoho.ready(function() {
getStatus();
});
}
});