installment.page.js
2.78 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
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
var $ = require('yoho-jquery'),
ellipsis = require('yoho-mlellipsis'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading');
var winH = $(window).height(),
$installmentOnly = $('.installment-only'),
searching = false,
page = 0;
const Timer = function() {
this.counter = 0;
this.countdownTimer = null;
};
ellipsis.init();
function search() {
if (searching) {
return;
}
searching = true;
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/product/recom/maylike?gender=1,3',
data: {
page: page + 1
},
success: function(data) {
if (data === '') {
loading.hideLoadingMask();
} else {
searching = false;
$('#goods-list').append(data);
loading.hideLoadingMask();
page++;
$('.good-detail-text .name').each(function() {
var $this = $(this),
$title = $this.find('a');
$title[0].mlellipsis(2);
});
}
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
loading.hideLoadingMask();
}
});
}
function scrollHandler() {
if ($(window).scrollTop() + winH >= $(document).height() - 200) {
search();
}
}
// srcoll to load more
$(window).scroll(function() {
if ($installmentOnly.length > 0) {
window.requestAnimationFrame(scrollHandler);
}
});
if ($installmentOnly.length > 0) {
$('.installment-page').css({
background: '#efefef'
});
search();
}
/**
* 倒计时
*
* @param progress 进度回调
* @param complete 完成回调
*/
Timer.prototype.startCountdown = function(progress, complete) {
if (this.counter > 0 || this.countdownTimer) {
return;
} else {
this.counter = 59;
}
if (progress) {
progress.call(this, this.counter);
}
this.countdownTimer = setInterval(()=> {
this.counter--;
if (this.counter <= 0) {
if (complete) {
clearInterval(this.countdownTimer);
this.counter = 0;
this.countdownTimer = null;
complete.call(this);
}
}
if (progress && this.counter > 0) {
progress.call(this, this.counter);
}
}, 1000);
};
/**
* 点击发送短信事件
*/
$('#send-sms').click(function() {
new Timer().startCountdown(function(counter) {
$('#send-sms').text(counter + 's');
}, function() {
$('#send-sms').text('获取验证码');
});
return false;
});
require.ensure([], function() { // this syntax is weird but it works
});