red-shop.js
2.88 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
/*
* @Author: Targaryen
* @Date: 2017-03-23 11:31:51
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-01 16:58:34
*/
/** *****************
* 红人店铺首页
********************/
const Swiper2 = require('yoho-swiper2');
let tip = require('../../plugin/tip');
let $goodsContainer = $('.index-goods-container');
let $collect = $('#collect');
const shopId = $('#shopId').val();
/**
* 异步检测是否已经收藏
*/
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/index/shopFav',
xhrFields: {
withCredentials: true
},
data: {
shopId: shopId
},
success: function(data) {
if (data.collect) {
$collect.attr('class', 'already-collect pull-left');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
/**
* 异步加载人气单品
*/
$.each($goodsContainer, function(index, elem) {
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product//new/shop/hotlist',
xhrFields: {
withCredentials: true
},
data: {
skns: $(elem).data('skns')
},
success: function(result) {
$(elem).html(result);
}
});
});
/**
* 店铺轮播图
*/
if ($('.shop-swiper')) {
let num = $('.shop-swiper').length;
for (let i = 1; i <= num; i++) {
new Swiper2('.shop-swiper-' + i, {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
slideElement: 'li',
paginationClickable: true,
pagination: $(this).closest('.shop-swiper-' + i).find('.pagination-inner').get(0)
});
}
}
/**
* 店铺收藏取消收藏操作
*/
$collect.on('click', function() {
let options = {
id: shopId,
opt: 'ok',
type: 'shop'
};
if ($collect.hasClass('already-collect')) {
options.opt = 'cancel';
}
$.ajax({
method: 'get',
url: location.protocol + '//m.yohobuy.com/product/opt/favoriteBrand',
xhrFields: {
withCredentials: true
},
data: options,
success: function(result) {
if (result.code === 200) {
if ($collect.hasClass('already-collect')) {
$collect.attr('class', 'not-collect pull-left');
tip.show('店铺取消收藏成功');
} else {
$collect.attr('class', 'already-collect pull-left');
tip.show('店铺收藏成功');
}
}
if (result.code === 400) {
if ($('#jump-login').length <= 0) {
$('body').append('<a href=\'' + result.data + '\'><span id="jump-login"><span></a>');
}
$('#jump-login').click();
}
}
});
});