coupons.page.js
3.71 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
133
134
135
136
137
138
139
140
// 不要使用es6
'use strict';
var $ = require('yoho-jquery'),
couponsListHbs = require('home/coupons-list.hbs'),
notResultHbs = require('home/coupon-not-result.hbs');
var $couponTab1 = $('.coupon-tab1'),
$couponTab2 = $('.coupon-tab2'),
$couponTab3 = $('.coupon-tab3'),
$couponUl = $('.coupon-tab'),
page = 1,
indexNum,
couponFun,
scrollHandler,
$tabDom;
require('home/coupons.page.css');
require('../common');
$('body').css({'background-color': '#f2f2f2'});
couponFun = function() {
$tabDom = $couponUl.find('li.activate');
if (!$tabDom) {
return false;
}
if ($tabDom.data('AjaxFlag')) {
return false;
}
$tabDom.data('AjaxFlag', true);
page = $tabDom.data('page') || 1;
indexNum = $tabDom.index() * 1;
// 首屏渲染page = 2
if (indexNum === 0 && !$tabDom.data('page')) {
page = 2;
}
$.ajax({
type: 'POST',
url: '/home/couponsAjax',
dataType: 'json',
data: {
status: indexNum,
page: page
},
success: function(data) {
var $activeDom;
if (indexNum === 1) {
$activeDom = $couponTab2;
} else if (indexNum === 2) {
$activeDom = $couponTab3;
} else {
$activeDom = $couponTab1;
}
if (page <= 1 && data.length <= 0) {
$activeDom.html(notResultHbs());
return false;
}
if (data.length <= 0) {
return false;
}
$tabDom.data('page', ++page);
$tabDom.data('AjaxFlag', false);
$activeDom.append(couponsListHbs({list: data}));
window.rePosFooter(); // 重新计算底部位置
}
});
};
scrollHandler = function() {
if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) {
couponFun();
return;
}
};
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
// tab 事件
$couponUl.on('click', 'li', function() {
$(this).addClass('activate').siblings().removeClass('activate');
$('.coupon-list').addClass('hide').eq($(this).index()).removeClass('hide');
couponFun();
window.rePosFooter(); // 重新计算底部位置
});
// 详细信息事件
$('.coupon-list').on('click', '.info-btn', function() {
var $this = $(this);
if ($this.hasClass('down')) {
$this.removeClass('down').addClass('up');
$this.closest('.coupon-group').find('.coupon-footer').removeClass('hide');
} else {
$this.removeClass('up').addClass('down');
$this.closest('.coupon-group').find('.coupon-footer').addClass('hide');
}
// 优惠券埋点
window._yas && window._yas.sendCustomInfo && window._yas.sendCustomInfo({
op: 'YB_COUPON_DETAIL_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')] || 1,
COUPON_ID: $this.closest('.coupon-group').data('coupon-id')
})
}, true);
});
// 立即使用
$('.coupon-list').on('click', 'a.btn', function() {
var $this = $(this);
// 优惠券埋点
window._yas && window._yas.sendCustomInfo && window._yas.sendCustomInfo({
op: 'YB_COUPON_IMMEDIATE_USE_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')] || 1,
COUPON_ID: $this.closest('.coupon-group').data('coupon-id')
})
}, true);
document.location.href = $this.data('link');
});
// 首屏渲染无结果判断
if ($('.coupon-tab1').find('.coupon-group').length <= 0) {
$('.coupon-tab1').html(notResultHbs());
window.rePosFooter(); // 重新计算底部位置
}