index.page.js
5.56 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
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
/**
* 个人中心首页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/2/17
*/
var $ = require('yoho-jquery'),
handlebars = require('yoho-handlebars');
var yas = require('../common/data-yas');
var RECID = (new Date().getTime() + '_PC_YOHOBUY_' +
Math.floor(Math.random() * 1000000 + 1000000) +
'_' + Math.floor(Math.random() * 1000000 + 1000000));
require('./orders/order-block');
require('../common');
// 关闭消息提示
$('#close-message').click(function() {
$('.message-tip').slideUp(200);
});
/**
*
* @param self 点击的控件
* @param $ul 列表父
* @param page 总共页数
* @param itemWith 子元素宽
* @param curPage 当前页码
* @param num 一页商品数量
*/
function pageChange(self, $ul, page, itemWith, curPage, num) {
var $this = self,
left;
if ($this.hasClass('next')) {
// 第2页显示前翻按钮
if (curPage === 2) {
$this.siblings().removeClass('no-visible');
}
// 最后一页隐藏后翻按钮
if (curPage === page) {
$this.addClass('no-visible');
}
} else {
// 倒数第2页显示后翻按钮
if (curPage === page - 1) {
$this.siblings().removeClass('no-visible');
}
// 第1页隐藏前翻按钮
if (curPage === 1) {
$this.addClass('no-visible');
}
}
left = -num * (curPage - 1) * itemWith;
$ul.animate({
marginLeft: left
}, 400);
}
// 新品上架
(function() {
var $naPager = $('.na-pager'),
$rcPager = $('.rc-pager'),
$naUl = $('.new-arrival ul'),
$rcUl = $('.recommend ul'),
naPage = Math.ceil($naUl.children('li').length / 5),
rcPage = Math.ceil($rcUl.children('li').length / 6),
naItemWith = $naUl.children('li:last-child').outerWidth(),
rcItemWith = $rcUl.children('li:last-child').outerWidth(),
naCurPage = 1,
rcCurPage = 1,
PRDID = [];
var $brandsBox = $('#home-brands-box'),
$newBox = $('#home-new-box'),
$recommendBox = $('#home-recommend-box'),
$brandsTpl = $('#home-brands-tpl').html(),
$newTpl = $('#home-new-tpl').html(),
$recommendTpl = $('#home-recommend-tpl').html();
$naUl.width($naUl.width() * naPage);
$rcUl.width($rcUl.width() * rcPage);
// 最新上架翻页
$naPager.click(function() {
var $this = $(this);
if (naPage > 1) {
if ($this.hasClass('next')) {
++naCurPage;
} else {
--naCurPage;
}
pageChange($this, $naUl, naPage, naItemWith, naCurPage, 5);
}
});
// 为你推荐翻页
$rcPager.click(function() {
var $this = $(this);
if (rcPage > 1) {
if ($this.hasClass('next')) {
++rcCurPage;
} else {
--rcCurPage;
}
PRDID = [];
$rcUl.find('li').each(function(index) {
if (PRDID.length >= 6) {
return false;
}
if (index >= (rcCurPage - 1) * 6) {
PRDID.push($(this).find('a').data('id'));
}
});
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', {
REC_POSE: 120004,
PRD_ID: PRDID.join(','),
PRD_NUM: PRDID.length,
ACTION_ID: 0,
page_num: rcCurPage,
REC_ID: RECID
});
pageChange($this, $rcUl, rcPage, rcItemWith, rcCurPage, 6);
}
});
// 为您优选埋点 start
setTimeout(function() {
PRDID = [];
$rcUl.find('li').each(function(index) {
if (PRDID.length >= 6) {
return false;
}
if (index >= 0) {
PRDID.push($(this).find('a').data('id'));
}
});
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', {
REC_POSE: 120004,
PRD_ID: PRDID.join(','),
PRD_NUM: PRDID.length,
ACTION_ID: 0,
page_num: 1,
REC_ID: RECID
});
}, 3000);
$rcUl.find('li a').bind('click', function() {
var index = $(this).closest('li').index() + 1;
yas.givePoint('YB_CHOOSE_FOR_YOU_Y', {
REC_POSE: 120004,
PRD_ID: $(this).data('id'),
PRD_NUM: index % 6 === 0 ? 6 : index % 6,
ACTION_ID: 1,
page_num: rcCurPage,
REC_ID: RECID
});
return true;
});
// 为您优选埋点 end
// 我的消息、我的头像
$.getJSON('//www.yohobuy.com/home/index/newsAvatar', function(data) {
$('#user-thumb').attr('src', data.avatar);
if (+data.msg > 0) {
$('#new-count').html(data.msg).removeClass('hide');
}
});
// 异步数据
$.getJSON('//www.yohobuy.com/home/index/async', function(data) {
// 首页异步数据待处理订单,未读消息,待分享商品数量
if (data.numbers) {
$.each(data.numbers, function(key, val) {
$('#' + key).html(val);
});
}
// 喜欢的品牌
if (data.brands) {
$brandsBox.html(handlebars.compile($brandsTpl)(data.brands));
}
// 新品上架
if (data.products) {
$newBox.html(handlebars.compile($newTpl)(data.products));
}
// 推荐
if (data.rec) {
$recommendBox.html(handlebars.compile($recommendTpl)(data.rec));
}
});
}());