main.js
10.3 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
var cart =
{
//用于购买按钮
buy : function(callbackFunc){
var goods_id = $('#goods_id').val();
var size_id = $('#size_id').val();
var size_name = $('#size_name').val();
var num = $('#num').val();
var promotion_id = $('#promotion_id').val();
var promotion_type = $('#promotion_type').val();
if(goods_id == 0){
QGlobal.UI.alertWindow('请选择颜色','alertDialog','alertMessageBox',401);
return;
}
if(size_id == 0 || size_name==''){
QGlobal.UI.alertWindow('请选择尺码','alertDialog','alertMessageBox',401);
return;
}
if(num < 1) {
QGlobal.UI.alertWindow('请至少购买一件','alertDialog','alertMessageBox',401);
return ;
}
if(!this.checkCartLimit(num)){
QGlobal.UI.alertWindow('您买的商品太多了,请联系我们的客服,专门为您服务','alertDialog','alertMessageBox',401);
return;
}
//window.open('http://www.baidu.com', 'baidu');
this.AddToCart(goods_id, size_id, num, size_name, promotion_id, promotion_type, callbackFunc);
},
checkCartLimit : function(num){
var cartInfo = eval('(' + $.cookie('_g') + ')');
if(cartInfo != null){
if(parseInt(parseInt(cartInfo._nac) + parseInt(cartInfo._ac) + parseInt(num)) > 1000){
return false;
}
}
return true;
},
//向购物车增加商品
AddToCart : function(goods_id, size_id, num, size_name, promotion_id, promotion_type, callbackFunc){
$.post('/shopping',{goods_id:goods_id,size_id:size_id,num:num,size_name:size_name,promotion_id:promotion_id,promotion_type:promotion_type},
function(data){
if(data.code == 200){
// window.open('/shopping/cart', 'cartList');
eval(callbackFunc + '(200,' + data.data.totalNum + ',' + data.data.totalCost + ',' + data.data.goodsInCartId + ',"")');
} else{
eval(callbackFunc + '(' + data.code + ',' + num + ',' + 0 + ',0' + ',"' + data.message +'")');
}
}, 'json');
},
/**
* 商品详情页面显示结果
*/
productDetailBuyResult : function(resultCode, totalNum, totalCost, goodsInCartId, msg){
if(resultCode == 200) {
$('#curTotalNum').html(totalNum);
$('#curTotalCost').html(totalCost);
$('#shoppingCart').dialog('open');
$('#shoppingCart').show();
} else {
//失败的提示
QGlobal.UI.alertWindow(msg,{'code':401});
}
},
/**
* 购物车购买结果显示
*/
cartBuyResult : function(resultCode, totalNum, totalCost, goodsInCartId, msg){
if(resultCode == 200)
{
$('#dialogSellInfo').dialog('close');
location.reload();
}
else
{
alert(msg);
}
},
closeBuyResult : function(){
$('#buyResult').hide();
},
//移除商品
doRemove : function(id, cartId, isPreSell, isGift, isOutlets) {
this.remove(id, cartId, isPreSell, isGift, isOutlets);
},
remove : function(id, cartId, isPreSell, isGift, isOutlets) {
$.post('/shopping/cart/delone',{id:id,cartId:cartId}, function(data){
if(data.code == 200){
cart.setNoGoodsStatus();
if(isPreSell != 1){
PromotionUtil.delGoods(id, isGift, isOutlets);
PromotionUtil.showResultInCart();
}
$('#trDetail' + id).remove();
}
}, 'json');
},
onlyRemove : function(id, cartId, isPreSell, isGift, isOutlets){
$.post('/shopping/cart/delone',{id:id,cartId:cartId}, function(data){
if(data.code == 200){
cart.setNoGoodsStatus();
if(isPreSell != 1){
PromotionUtil.delGoods(id, isGift, isOutlets);
}
$('#trDetail' + id).remove();
}
}, 'json');
} ,
//从购物车移入收藏
moveToFavorite : function(id, cartId, isPreSell, isGift, isOutlets) {
$.post('/shopping/cart/movetofavorite', {cartId:cartId,id:id}, function(data){
if(data.code == 200){
if(isPreSell != 1){
cart.setNoGoodsStatus();
PromotionUtil.delGoods(id, isGift, isOutlets);
PromotionUtil.showResultInCart();
}
$('#trDetail' + id).remove();
}else if(data.code == 401){
alert('您还没有登录,请先登录,然后再收藏该商品');
//QGlobal.UI.alertWindow('您还没有登录,请先登录,然后再收藏该商品','alertDialog','alertMessageBox',401);
}
}, 'json');
},
/**
* 设置是否显示购物车已空
*/
setNoGoodsStatus: function(){
var cartInfo = eval('(' + $.cookie('_g') + ')');
if(cartInfo != null){
if(cartInfo._nac == 0){
if(cartInfo._ac > 0){
window.location.reload();
}
//显示购物车已空
$('#noGoodsInCart').show();
$('#commonTotalCost').html(0);
}
if(cartInfo._ac == 0){
$('#divAdvanceTitle').hide();
$('#advanceCartGoodsList').hide();
$('#advanceFeeList').hide();
$('#advanceBottom').hide();
}
if(cartInfo._nac == 0 && cartInfo._ac == 0)
{
//待优化
window.location.reload();
}
}
},
/**
* 清空购物车
*/
clearCart : function(cartId) {
$.post('/shopping/cart/clearcart', {cartId:cartId}, function(data){
if(data.code == 200){
window.location.reload();
}
}, 'json');
},
/**
* 增加数量
*/
addNum : function(cartId, detailId, isPreSell, isOutlets) {
var curNum = $('#curNum' + detailId).val();
var num = parseInt(curNum, 10) + 1;
if(!this.checkCartLimit(num)){
QGlobal.UI.alertWindow('您买的商品太多了,请联系我们的客服,专门为您服务','alertDialog','alertMessageBox',401);
return;
}
this.modifyNum(cartId, detailId, num, isPreSell, isOutlets);
},
//减少数量
cutNum: function(cartId, detailId, isPreSell, isOutlets) {
var curNum = $('#curNum' + detailId).val();
var num = curNum -1;
if(num < 1) {
if(confirm('确定要把该商品从购物车删除吗?')){
this.doRemove(detailId, cartId, isPreSell, 0, isOutlets);
}
} else {
this.modifyNum(cartId, detailId, num, isPreSell, isOutlets);
}
},
//修改商品到制定数量
modifyNum: function (cartId, detailId, num, isPreSell, isOutlets){
$.post('/shopping/cart/changenum', {cartId:cartId,id:detailId,num:num},function(data){
if(data.code == 200){
$('#curNum' + detailId).val(num);
//更新小计价格
var gPrice = $('#gPrice' + detailId).val();
$('#gTotalCost' + detailId).html(QGlobal.Viewhelper.formatMoney(num * gPrice));
cart.setNoGoodsStatus();
if(isPreSell != 1) {
//更新购物车数组里产品的数量
PromotionUtil.updateGoodsNum(detailId, num, isOutlets);
//修改成功,重新计算促销方案
PromotionUtil.showResultInCart();
}
}
});
},
expandSwitch : function(btnId, expandId){
if($('#' + expandId).is(":hidden") == false) {
//当前为显示
$('#' + expandId).hide();
} else {
$('#' + expandId).show();
}
},
showSellInfo : function(productId, promotion_id, promotion_type){
$.post('/shopping/cart/saleinfo', {product_id:productId,promotion_id:promotion_id,promotion_type:promotion_type},function(data){
$('#dialogSellInfo').html(data);
$('#dialogSellInfo').dialog({
autoOpen: false,
width:640,
height:420,
modal: true,
resizable: false
});
$('#dialogSellInfo').dialog('open');
initMiniProduct();
});
},
showCommonSellInfo : function(productId){
$.post('/shopping/cart/commonsaleinfo', {product_id:productId},function(data){
$('#dialogSellInfo').html(data);
$('#dialogSellInfo').dialog({
autoOpen: false,
width:640,
height:420,
modal: true,
resizable: false
});
$('#dialogSellInfo').dialog('open');
initMiniProduct();
});
},
checkCartGift: function(isPreSell){
if(!PromotionUtil.checkSelGift()){
$('#selGiftNotice').dialog({
autoOpen: false,
width:360,
height:220,
modal: false,
resizable: false
});
$('#selGiftNotice').dialog('open');
return false;
}
this.checkStorage(isPreSell);
},
/**
* 关闭选择赠品的提示
*/
closeGiftNotice : function(){
$('#selGiftNotice').dialog('close');
},
clickFlag : 1, //防止多次点击
checkStorage : function(isPreSell){
if(cart.clickFlag == 0){
return;
}
cart.clickFlag = 0;
$.getJSON('/shopping/cart/checkstorage?isPreSell=' + isPreSell, function(jsonData){
cart.clickFlag = 1;
if(jsonData.code == 200){
$('#submitOrder' + isPreSell).submit();
}else{
QGlobal.UI.alertWindow("您要购买的“" + jsonData.data + "“库存不足,您可以进行缺货登记或选择其他的商品,感谢您的支持!",{boxWidth:420,boxHeight:160});
}
});
},
recommendsProduct : function(page, obj)
{
QGlobal.Page.QSend_Url = '/shopping/cart/recommendsproduct';
QGlobal.Page.QItem = 'recommendsProduct';
var str = page;
QGlobal.Page.getList(str, obj);
}
};
/**
* 收藏使用的js
*/
FavoriteUtil = {
boxList : function(page){
QGlobal.Page.QSend_Url = '/home/favorite/boxlist';
QGlobal.Page.QItem = 'favoriteList';
QGlobal.Page.getList(page);
}
};
/**
* 购物流程的支付页面所用的功能
*/
cart.pay = {
/**
* 去支付
*/
goPay : function()
{
/* var order_code = $('#order_code').val();
var payment = $(":radio[name='payment'][checked]").val();
window.loc ation = 'http://www.yohobuy.com/pay?order_code=' + order_code + "&payment_type=" + payment; */
$('#payForm').submit();
return false;
},
/**
* 选择一个支付方式
*/
selPayment : function(paymentId)
{
$('#payment_' + paymentId).attr('checked', 'true');
var paymentName = $('#payimg' + paymentId).attr('alt');
$('#spanBtnPay').html('使用' + paymentName + '付款');
}
};