favorite.js
6.76 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/**
* 我的收藏
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/2/23
*/
var $ = require('yoho.jquery');
var phoneReg = require('../passport/mail-phone-regx').phoneRegx['+86'];
var clockTxt = {
on: '[ 降价通知 ]',
off: '[ 取消通知 ]'
};
var favType;
var curSkn;
var $curClock;
//商品收藏
(function() {
var $defaultSorts,
$allSorts;
var $bodyMask,
$priceNotice,
$noticeContent,
$noticeSuccess,
$noticeSubOrCancel;
//关闭价格订阅弹窗和蒙层
function closeNoticeBox() {
$bodyMask.addClass('hide');
$priceNotice.addClass('hide');
//重置头部文字
$noticeSubOrCancel.text('订阅成功');
}
//显示价格订阅弹窗和蒙层
function showNoticeBox() {
if (typeof $bodyMask === 'undefined') {
$('body').append('<div class="body-mask hide"></div>');
$bodyMask = $('.body-mask');
}
$bodyMask.css({
height: $(document).height(),
width: $(document).width()
}).removeClass('hide');
if ($curClock.hasClass('noticed')) {
//取消降价通知
$.ajax({
type: 'GET',
url: '/home/favorite/cancelnotice',
data: {
skn: curSkn
}
}).then(function(data) {
if (data.code === 200) {
$noticeContent.addClass('hide');
$noticeSuccess.removeClass('hide').find('.notice-num').text(data.data.num);
$noticeSubOrCancel.text('取消成功');
if ($curClock.closest('.reduction-products').length > 0) {
$curClock.closest('.fav-good').remove();
} else {
$curClock.text(clockTxt.on);
}
}
});
}
$priceNotice.removeClass('hide');
}
if ($('.fav-products').length === 0) {
return;
}
favType = 'products';
$defaultSorts = $('.default-sorts');
$allSorts = $('.all-sorts');
$priceNotice = $('.price-notice');
$noticeContent = $('#price-notice .content');
$noticeSuccess = $('#price-notice .success');
$noticeSubOrCancel = $noticeSuccess.find('.subscribe-or-cancel');
//展开分类
$('#spread-sort').click(function() {
$defaultSorts.slideUp(function() {
$allSorts.slideDown();
});
});
//收起分类
$('#retract-sort').click(function() {
$allSorts.slideUp(function() {
$defaultSorts.slideDown();
});
});
//降价通知
$('.price-down-clock').click(function() {
$curClock = $(this),
showNoticeBox();
curSkn = $curClock.closest('.fav-good').data('skn');
});
//降价通知确定按钮
$('#price-notice').on('click', '.close', function() {
closeNoticeBox();
}).on('click', '.price-notice-sure', function() {
var $phone = $('#notice-phone-num'),
phone,
errTxt;
if ($noticeSuccess.hasClass('hide')) {
//订阅到手机号
phone = $.trim($phone.val());
if (phone === '' || !phoneReg.test(phone)) {
errTxt = phone === '' ? '请输入手机号码' : '手机号码格式不正确';
$phone.addClass('error');
$('#price-notice .err-text').removeClass('hide').find('em').html(errTxt);
return;
} else {
$phone.removeClass('error');
$('#price-notice .err-text').addClass('hide');
}
$.ajax({
type: 'GET',
url: '/home/favorite/notice',
data: {
phone: phone,
skn: curSkn
}
}).then(function(data) {
if (data.code === 200) {
$noticeSuccess.removeClass('hide');
$noticeContent.addClass('hide');
$noticeSuccess.find('.notice-num').html(data.data.num);
//切换商品通知文字
$curClock.toggleClass('noticed').text(clockTxt.off);
}
});
} else {
//关闭窗口
closeNoticeBox();
}
});
//商品可参加活动
$('.has-activity').click(function() {
var $this = $(this),
$activites = $this.next('.activites'),
$li = $this.closest('li');
if ($activites.hasClass('hide')) {
//显示
$activites.removeClass('hide');
$li.css('padding-bottom', $activites.outerHeight());
} else {
//隐藏
$activites.addClass('hide');
$li.css('padding-bottom', '');
}
});
}());
//品牌收藏
(function() {
if ($('.fav-brands').length === 0) {
return;
}
// 新品到着
$('.na-not-zero').click(function() {
var $this = $(this),
$naList = $this.next('.na-list'),
$li = $this.closest('li');
if (!$naList.hasClass('hide')) {
$naList.addClass('hide');
$li.css('padding-bottom', '');
return;
}
$.ajax({
type: 'GET',
url: '/home/newproduct'
}).then(function(html) {
$naList.removeClass('hide').find('.na-content').html(html);
$li.css('padding-bottom', $naList.outerHeight() + 10);
});
});
$('.na-content').on('click', '.na-pre, .na-next', function() {
var $this = $(this),
url = $this.data('url');
$.ajax({
type: 'GET',
url: url
}).then(function(html) {
$this.closest('.na-content').html(html);
});
});
}());
//全选【通用】
$('#me-checkall').click(function() {
$('.checkbox input[type="checkbox"]').prop('checked', $(this).prop('checked'));
});
//删除多个商品/品牌/文章【通用】
$('#me-del-checked').click(function() {
var ids = [],
url;
$('.checkbox input[type="checkbox"]:checked').each(function() {
ids.push($(this).closest('.fav-row').data('id'));
});
if (ids.length === 0) {
return;
}
switch (favType) {
case 'products':
url = '/home/favorite/multidelgoods';
break;
case 'brands':
url = '/home/favorite/multidelbrands';
break;
case 'articles':
url = '/home/favorite/multidelarticles';
break;
}
$.ajax({
type: 'GET',
url: url,
data: {
ids: ids
}
}).then(function(data) {
if (data.code === 200) {
window.history.go(0);
}
});
});