Item.js
15.6 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
var productdetails = {
productapiDomain:'http://itemapi.yohobuy.com',
dataTypes:'jsonp',
data:'',
mine:'',
product:'',
init:function (product_id) {
mine = this;
product = product_id;
$.ajax({
dataType:mine.dataTypes,
cache:true,
jsonpCallback:'itemsp',
data:{product_id:product_id, goods_id:goods_id},
url:mine.productapiDomain+'/item/item/goods',
success:function (result){
if (typeof result.code != 'undefined' && result.code == 200) {
data = result.data;
mine.data = data;
if (data.is_mobile) {
window.location.href='http://m.yohobuy.com' + window.location.pathname;
return true;
}
mine.goodsimage(data.goods_id);
mine.salebtn(data.sku_storage);
mine.price(data.price, data.is_advance, data.expect_arrival_time);
mine.outlet(data.is_outlets, data.outlets_discount);
mine.promotion(data.promotions, data.banner);
mine.vipprice(data.price, data.uid, data.vip_level);
mine.size(parseInt(data.goods_id));
mine.goods(parseInt(data.goods_id));
mine.tags();
mine.favitembtn();
mine.favbrand();
}
}
});
$('.amount-add').click(mine.plus);
$('.amount-subtract').click(mine.subtract);
},
outlet:function(is_outlet, outlet_discount) {
if (is_outlet != "Y") {
return false;
}
var tpl = $('#outlet').html();
var outlet = juicer(tpl, {discount:outlet_discount*10});
$('.info-activity').html(outlet);
},
promotion:function (promotions, banner) {
if (banner == '' && promotions == '') {
return false;
}
var tpl = $('#promotion').html();
var pro = juicer(tpl, {banner:banner, promotion:promotions});
$('.info-activity').html(pro);
},
toCart: function (product_id, goods_id, size_id, num, promotion_id, callback_func) {
$.ajax({
dataType:mine.dataTypes,
type:'GET',
data:{'product_id':product_id,goods_id:goods_id,size_id:size_id,num:num, promotion_id:promotion_id},
url:'http://shopping.yohobuy.com/shopping/add/tocart',
success:function (result) {
callback_func(result);
}
});
},
salebtn:function (sku_storage) {
var tpl = $('#sale-btn').html();
var salebtn = juicer(tpl, {data:data, num:sku_storage});
$('.info-submit').children('div:first').html(salebtn);
$('.button-cart').click(function () {
var goods_id = $('#goods_id').val();
var size_id = $('#size_id').val();
var sku = $('#sku_id').val();
var size_name = $('#size_name').val();
var storage = parseInt($('#storage').val());
var num = parseInt($('#num').val());
if (num > data.limit_num && data.limit > 0) {
alert('限购商品!您只能购买'+data.limit_num+'件!');
return true;
}
if (size_id == '') {
$('#sizeList .warning-tips').show();
return true;
}
if (num < 1) {
num = 1;
$('#num').val(1);
}
if (mine.data.attribute == 3) {
window.open('http://shopping.yohobuy.com/ticket?product_sku='+sku+'&buy_number=1');
return true;
}
if (storage < num) {
alert('库存不足!');
return true;
}
mine.toCart(product_id, goods_id, size_id, num, 0, mine.addToCart);
});
$('.button-supply').click(function () {
var sku = $('#sku_id').val();
if (sku == '') {
$('#sizeList .warning-tips').show();
return true;
}
var tpl = $('#mobile-message-tmpl').html();
$('.info-other').hide();
$('.info-buy').children('div').eq(0).siblings();
$('.info-buy').children('div').eq(1).html(tpl).show().slideDown('fast').siblings().slideUp('fast');
$('#notifyBtn').click(function(){
var mobile = $('#mobile').val();
if(mobile == ''){
return false;
}
if(!mobile.match(/^1[3|4|5|8][0-9]\d{4,8}$/)){
return false;
}
var goods_id = $('#goods_id').val();
$.ajax({
dataType:mine.dataTypes,
url:mine.productapiDomain+'/item/item/notify',
data:{'mobile' : mobile, 'product_id':product_id, 'goods_id' : goods_id, 'product_sku' : $('#sku_id').val()},
success:function (result) {
var _data = result.data;
if(_data.result == 1 || _data.result == 2){
$('#supply').removeClass('button-supply').addClass('button-wait').html('<span class="ifont font16">T</span>请等待补货');
$('#notifyBtn').click(function(){
return false;
});
$('.info-other').show();
$('.info-buy').children('div').eq(1).siblings();
$('.info-buy').children('div').eq(0).slideDown('slow').siblings().slideUp('slow');
if(_data.result == 2){
alert('您已经提交了补货通知,请不要重复提交.');
}
return false;
}
alert('补货通知提交失败,请稍后再试');
return false;
}
});
});
});
},
addToCart:function (result) {
if (typeof result.code != 'undefined' && result.code == 200) {
//1普通,2赠品,3虚拟,4特价
$('.info-other').hide();
$('.info-buy').children('div').eq(0).siblings();
var tpl = $('#cart-result-tmpl').html();
var cart_result = juicer(tpl, {result:result.data});
$('.info-buy').children('div').eq(1).html(cart_result).slideDown('fast').siblings().slideUp('fast');
$('#shopping').click(function(){
$('.info-other').show();
$('.info-buy').children('div').eq(1).siblings();
$('.info-buy').children('div').eq(0).slideDown('fast').siblings().slideUp('fast');
if ($('.info-buy').children('div').last().html() != '') {
$('.info-buy').append('<div id="resultBox" class="move-panel" style="display:block;"></div>').show();
}
$('.info-buy').children('div').last().show();
});
} else if (typeof result.code != 'undefined') {
alert(result.message);
}
},
favitembtn:function () {
var tpl = $('#favitemtpl').html();
var favitem_html = juicer(tpl, {data:data});
$('#fav_item').html(favitem_html);
if (data.is_favorite == 1) {
$('.button-favor').on({
mouseenter: function (){
$(this).html('<span class="ifont favored">f</span>取消收藏');
},
mouseout: function () {
$(this).html('<span class="ifont favored">f</span>已收藏');
}
});
}
},
price:function (price, is_advance, expect_arrival_time) {
var tpl = $('#priceTpml').html();
var price_html = juicer(tpl, {price:price, is_advance:is_advance, expect_arrival_time:expect_arrival_time,data:data});
$('.info-price').html(price_html);
},
vipprice:function(price, uid, vip_level) {
var tpl = $('#vip-price').html();
var vipprice_html = juicer(tpl, {price:price, uid:uid, vip_level:vip_level});
$('.info-price').append(vipprice_html);
},
size:function (good_id) {
if (data.goods_list.length == 0) {
return true;
}
var tpl = $('#size-tpml').html();
var size_html = juicer(tpl, {goods_id:good_id, goods:data.goods_list[good_id], status:data.status, erp_sku_id:data.sku, data:data});
$('#sizeList').html(size_html);
$('#sizeList a').not(':last').each(function(){
$(this).click(function(){
$('#sizeList a').removeClass('cur');
$(this).addClass('cur');
$('#sizeList').children('span').hide();
var num = $(this).attr('num');
mine.salebtn(num);
var size = $(this).attr('size');
var sizename = $(this).attr('sizename');
var sku = $(this).attr('sku');
$('#size_id').val(size);
$('#sku_id').val(sku);
$('#size_name').val(sizename);
$('#storage').val(num);
$('#num').val(1);
});
});
if (data.attribute == 3) {
$('#select_size_title').html('选日期:');
}
},
goods:function(good_id) {
if (data.goods_list.length == 0 ) {
return true;
}
$('#goods_id').val(good_id);
var tpl = $('#goods-tpml').html();
var goods_html = juicer(tpl, {goods_id:good_id, goods_list:data.goods_list, status:data.status});
$('#goodsList').html(goods_html);
$('#colorBox a').each(function(){
$(this).click(function(){
var this_goods_id = $(this).attr('goods_id');
$('#goods_id').val(this_goods_id);
mine.goodsimage(this_goods_id);
mine.size(this_goods_id);
$('#colorBox a').removeClass('cur');
$(this).addClass('cur');
var num = $(this).attr('storage');
mine.salebtn(num);
var color_name = $(this).attr('color_name');
$('.color dd:last-child').hide();
$('#goodsColor').html('<span>颜色:</span>' + color_name);
$('#num').val(1);
$('#size_id').val('');
$('#sku_id').val('');
$('#size_name').val('');
$('#storage').val('');
});
});
$('#goodsColor').html('<span>颜色:</span>' + data.goods_list[good_id]['color_name']);
},
tags:function () {
var tpl = $('#imageTags-tmpl').html();
var tags_html = juicer(tpl, {data:data});
$('.goods-tag-small').html(tags_html);
if (data.is_yohood == 'Y') {
$('#goods_tag_small').before('<div class="absolute yohood-tag"></div>');
}
if (data.can_buy == 'N') {
$('.info-other').before('<div class="yohoodNotice"><h3><b>YO‘HOOD会场限定商品</b></h3><p>该商品将优先于9月20-21日上海活动会场售卖,您可在YO’HOOD展会现场通过APP扫描商品二维码进行购买。9月22日,可在线购买。</p></div>');
}
},
goodsimage:function (goods_id) {
if (data.image_list.length == 0) {
return true;
}
try {
var tpl = $('#image-tmpl').html();
var img_html = juicer(tpl, {image_list:data.image_list[goods_id]['image']});
$('#bigImage').attr('src', data.image_list[goods_id]['image'][0]['big']);
$('.goods-img-small').html(img_html);
$('.goods-img-small a').on({
click:function () {
var big = $(this).attr('data');
$('#bigImage').attr('src', big);
},
mouseenter:function () {
var big = $(this).attr('data');
$('#bigImage').attr('src', big);
}
});
} catch (err){
}
},
favitem:function() {
$.ajax({
dataType:mine.dataTypes,
url:mine.productapiDomain+'/item/item/favitem?product_id='+product,
success:function (result) {
if (result.code == 403) {
window.location.href = 'http://www.yohobuy.com/signin.html?refer='+window.location.href;
} else if (result.code == 200) {
$('.button-favor').html('<span class="ifont favored">f</span>已收藏');
$('.button-favor').on({
mouseenter: function (){
$(this).html('<span class="ifont favored">f</span>取消收藏');
},
mouseout: function () {
$(this).html('<span class="ifont favored">f</span>已收藏');
}
});
} else if (result.code == 300) {
$('.button-favor').html('<span class="ifont">f</span>添加收藏');
$('.button-favor').off('mouseenter mouseout');
}
}
});
},
favbrand:function () {
if (data.brand_fav == 1) {
$('#brandFavor').addClass('favored');
}
$('#brandFavor').click(function () {
if(window.event && window.event.stopPropagation ) {
window.event.stopPropagation();
} else {
window.event.cancelBubble = true;
}
$.ajax({
dataType: mine.dataTypes,
url:mine.productapiDomain+'/item/item/favbrand?brand_id='+data.brand_id,
success:function(result) {
if (result.code == 200) {
$('#brandFavor').addClass('favored');
} else if (result.code == 300){
$('#brandFavor').removeClass('favored');
} else if (result.code == 403) {
window.location.href = 'http://www.yohobuy.com/signin.html?refer='+window.location.href;
}
}
});
});
},
plus:function() {
var now = parseInt($('#num').val());
var sku_storage = parseInt($('#storage').val());
if (sku_storage <= now) {
alert('库存不足!');
return true;
}
if (data.attribute == 3 && now == 1) {
alert('限购一件!');
return true;
}
$('#num').val(parseInt(now) + 1);
},
subtract:function () {
var now = $('#num').val();
if (now <= 1) {
$('#num').val(1);
alert('已经是最后一件了!不要再减了~ T_T');
return true;
}
$('#num').val(parseInt(now) - 1);
},
like:function() {
$.ajax({
dataType:mine.dataTypes,
cache:true,
jsonpCallback:'recommends',
url:mine.productapiDomain+'/item/item/recommends',
data:{'product_skn':product_skn},
success:function (result) {
var tpl = $('#like-tmpl').html();
if (typeof result.code == 'undefined' || result.data == null || result.data.length == 0) {
return false;
}
var like_html = juicer(tpl, {goods_list:result.data, len:result.data.length-1});
$('#like').html(like_html);
}
});
}
};