bundle.js
2.63 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
/**
* Created by targaryen on 2016/11/25.
*/
let $ = require('yoho-jquery'),
Swiper = require('yoho-swiper');
let $bundle = $('#placeholder-bundle');
let bundleT = require('product/detail/bundle.hbs');
let bundleContentT = require('product/detail/bundle-content.hbs');
let bundleObj = {
bundles: [],
bundleIndex: 0,
init(bundles) {
let self = this;
self.bundles = bundles;
try {
self.render();
self.regTabsSwiper();
self.regProductSwiper();
self.regEvent();
} catch (e) {
console.error(e);
}
},
render() {
let self = this;
var bundleHtml = bundleT({
bundleDatas: self.bundles,
bundleData: self.bundles[self.bundleIndex],
bundleIndex: self.bundleIndex
});
return $bundle.replaceWith(bundleHtml);
},
renderProduct() {
let self = this;
var bundleHtml = bundleContentT({
bundleData: self.bundles[self.bundleIndex],
});
$('.bundle-content').html(bundleHtml);
self.regProductSwiper();
},
regEvent() {
let self = this;
$('.bundle-tabs').on('click', '.swiper-slide', (e) => {
let index = $(e.currentTarget).data('index');
if (self.bundleIndex !== index) {
$(e.currentTarget).addClass('selected').siblings().removeClass('selected');
self.bundleIndex = index;
self.renderProduct();
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_GDS_PACKAGE_TAB_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
PRD_ID: $('#productId').val(),
TAB_ID: index + 1
})
}, true);
}
}
});
},
regProductSwiper() {
let self = this;
if (self.bundles[self.bundleIndex].productList.length > 3) {
new Swiper('.bundle-product', {
freeMode: true,
slidesPerView: 'auto',
lazyLoading: true
});
}
},
regTabsSwiper() {
let self = this;
if (self.bundles.length > 3) {
$('.bundle-tabs').removeClass('any');
new Swiper('.bundle-tabs', {
freeMode: true,
slidesPerView: 'auto',
lazyLoading: true
});
}
}
};
module.exports = bundleObj;