cart.js
5.43 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
/**
* 购物车页面操作
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2016/12/29
*/
'use strict';
let $ = require('yoho-jquery'),
tip = require('../../plugin/tip'),
dialog = require('../../plugin/dialog');
let cartObj = {
init(handle) {
let self = this;
self.handle = handle;
$('.cart-nav').on('click', 'li', function(e) {
self.cartNavClick(e);
});
$('.more-box>.down-arrow').on('click', function(e) {
self.arrowClick(e);
});
$('.btn-balance').on('click', function() {
self.balanceClick();
});
$('.promo-item').on('click', function(e) {
self.promoItemClick(e);
});
$('.all-gift-box').on('click', '.gift-item', (e) => {
self.allGiftBoxClick(e);
});
$('.nav-btn').on('click', () => {
self.navClick();
});
self.initPresellTip();
},
navClick() {
let self = this;
$('.main-wrap').toggleClass('edit');
if ($('.main-wrap').hasClass('edit')) {
self.handle.editMode = true;
$('.chk.edit').removeClass('checked');
} else {
self.handle.editMode = false;
}
},
arrowClick(e) {
$(e.currentTarget).parent().toggleClass('down');
},
cartNavClick(e) {
let self = this;
let type = $(e.currentTarget).data('type');
window.setCookie('cartType', type);
self.handle.refreshPage('');
},
initPresellTip() {
if (typeof window.cookie === 'function' && window.cookie('_hasShowCartPresellTip') === 'y') {
$('#presell-tip').removeClass('show').addClass('hide');
} else {
$('#presell-tip').removeClass('hide').addClass('show');
setTimeout(function() {
$('#presell-tip').removeClass('show').addClass('hide');
window.setCookie('_hasShowCartPresellTip', 'y');
}, 3000);
}
},
promoItemClick(e) {
let cartType = window.cookie('cartType') || 'ordinary';
let promotionId = $(e.currentTarget).data('id');
let promotionType = $(e.currentTarget).data('type');
let promotionTitle = encodeURIComponent($(e.currentTarget).data('title'));
let title = '促销商品';
if (promotionType === 'Gift') {
if ($(e.currentTarget).data('status') === 30) {
window.location.href = `/cart/index/new/gift?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}&edit=1`;
} else {
window.location.href = `/cart/index/new/gift?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
}
} else if (promotionType === 'Needpaygift') {
if ($(e.currentTarget).data('status') === 30) {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}&edit=1`;
} else {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
}
} else {
window.location.href = `/product/index/index?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
}
},
allGiftBoxClick(e) {
let cartType = window.cookie('cartType') || 'ordinary';
if ($(e.currentTarget).hasClass('advanceBuy')) {
window.location.href = '/cart/index/new/advanceBuy?cartType=' + cartType;
} else {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
}
},
balanceClick() {
let cartType = window.cookie('cartType') || 'ordinary';
if (window._yas && window._yas.sendCustomInfo) {
let productId = Array.from($('.good-item.is-checked').map((i, e) => $(e).data('id')));
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_SC_TOBUY_CLICK',
param: JSON.stringify({
C_ID: window.C_ID,
PRD_ID: productId.join(','),
})
}, true);
}
}, 200);
}
let lowStocks = $('.good-item.low-stocks.is-checked').length;
if (lowStocks > 0) {
tip.show(`所选商品中有${lowStocks}种库存不足的商品`);
return false;
}
if ($('.all-gift-box>.freebie').length) {
dialog.showDialog({
dialogText: '您还未选择赠品,是否去选择赠品',
hasFooter: {
leftBtnText: '我不要赠品',
rightBtnText: '去选择'
}
}, function() {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
}, function() {
window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
});
return false;
}
if (!$('.good-item.is-checked').length) {
tip.show('请先勾选商品');
return false;
}
window.location.href = '/cart/index/new/orderEnsure?cartType=' + cartType;
}
};
module.exports = cartObj;