page-render.js
5.79 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
let $ = require('yoho-jquery'),
chosePanel = require('common/chose-panel'),
tip = require('plugin/tip');
let dbClass = 'data-bind';
module.exports = function(callback) {
let productId = $('#productId').val();
let goodsId = $('#goodsId').val();
let productSkn = $('#productSkn').val();
if (productId && (goodsId || productSkn)) {
$.ajax({
type: 'POST',
url: '/product/detail/info',
data: {
id: productId,
goodsId: goodsId,
productSkn: productSkn
},
success: function(data) {
// 如果当前是秒杀商品,且不在秒杀路径下,跳到该商品的秒杀详情页
let reg = /\/product\/show_([\d]+)/;
let regPro = /\/product\/pro_([\d]+)_([\d]+)/;
let regSeckill = /\/product\/seckill/;
// let regProSeckill = /\/product\/seckill\/pro_([\d]+)_([\d]+)/;
let thisHref = window.location.href;
let thisRefer = document.referrer;
// 如果秒杀商品没有吊牌价,显示原销售价
if (data.isSecKill === 'Y' && !data.cartInfo.price) {
$('.previous-price').text(data.cartInfo.salePrice);
}
if (!regSeckill.test(thisRefer)) {
if (data.isSecKill === 'Y' && (reg.test(thisHref) || regPro.test(thisHref))) {
window.location.replace('/product/seckill/show_' + $('#productSkn').val() + '.html');
}
}
render(data); // eslint-disable-line
callback(data);
}
});
} else {
callback(); // eslint-disable-line
}
};
function render(data) {
if (data.goodsPrice) {
$('.goods-price>.current-price').text(data.goodsPrice.currentPrice);
$('.goods-price>.previous-price').text(data.goodsPrice.previousPrice);
$('.goods-price').removeClass(dbClass);
}
if (!data.noLimitGoodsBtn) {
if (data.canGetLimitCode) {
$('.data-can-get-limit-code').removeClass(dbClass);
}
if (data.codeEmpty) {
$('.data-code-empty').removeClass(dbClass);
}
if (data.gotCode) {
$('.data-got-code').removeClass(dbClass);
}
}
if (data.studentPrice) {
$('.price-date').removeClass(dbClass);
$('.student-value').text(data.studentPrice);
} else if (data.vipLevel) {
let li = $('.vip-level>li').first().remove();
for (let i = 0; i < data.vipLevel.list.length; i++) {
let item = data.vipLevel.list[i];
let itemLi = li.clone();
if (item.currentLevel) {
itemLi.addClass('current-level');
}
itemLi.find('.vip-price').text(item.text);
$('.vip-level').append(itemLi);
}
$('.vip-level').removeClass(dbClass);
}
if (data.goodsDiscount && data.goodsDiscount.list && data.goodsDiscount.list.length) {
let shortText = $('#goodsDiscount>.short-text').remove();
let liText = $('#goodsDiscount>.discount-folder>.folder-item').remove();
for (let i = 0; i < data.goodsDiscount.list.length; i++) {
let discount = data.goodsDiscount.list[i];
let itemText = i === 0 ? shortText.clone() : liText.clone();
if (discount.text) {
if (i === 0) {
itemText.text(discount.text)
.append('<span class="icon-down iconfont dropdown"></span>')
.prependTo('#goodsDiscount');
} else {
itemText.text(discount.text).appendTo('#goodsDiscount>.discount-folder');
}
}
}
$('#goodsDiscount').removeClass('data-bind');
}
if (data.cartInfo) {
$('.num-incart').attr('href', data.cartInfo.cartUrl);
if (data.cartInfo.addToCartUrl) {
$('.add-to-cart-url').text(data.tickets ? '立即购买' : '加入购物车').removeClass(dbClass);
}
if (data.cartInfo.soldOut) {
$('#soldOut').removeClass(dbClass);
}
if (data.cartInfo.notForSale) {
$('#notForSale').removeClass(dbClass);
}
if (data.cartInfo.limitNotForSale) {
$('#limitNotForSale').removeClass(dbClass);
}
if (data.cartInfo.canBuyLimit) {
$('.can-buy-limit').removeClass(dbClass);
}
if (data.cartInfo.noLimitCode) {
$('#noLimitCode').removeClass(dbClass);
}
if (data.cartInfo.canNotBuy) {
$('#noLimitCode').removeClass(dbClass);
}
if (data.cartInfo.preSale) {
$('#preSale').removeClass(dbClass);
}
$('.cart-bar').removeClass('data-bind');
$('#limitCodeUrl').val(data.cartInfo.limitCodeUrl);
$('#limitProductPay').val(data.cartInfo.limitProductPay);
if (data.cartInfo.limitProductCode) {
$('#limitProductCode').val(data.cartInfo.limitProductCode).removeClass(dbClass);
}
}
if (data.isCollect === true) {
$('#likeBtn').addClass('liked');
}
if (data.tickets) {
$('#buyNowForm').attr('action', data.ticketsConfirm).removeClass(dbClass);
}
if (data.loginUrl) {
$('#loginUrl').val(data.loginUrl).removeClass(dbClass);
}
// 定金预售商品
if (data.isDepositAdvance === 'Y') {
setTimeout(function() {
$('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() {
tip.show('定金预售商品只能在APP端购买');
return false;
});
}, 200);
} else {
chosePanel(data);
}
$('.' + dbClass).remove();
}