functions.js
2.77 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
let $ = require('yoho-jquery'),
tip = require('plugin/tip');
let functions = {
/**
* 添加门票
*/
addTickets(productSku, buyNumber) {
var data = {
productSku: productSku,
buyNumber: buyNumber
};
// 校验电子票
$.ajax({
url: '/cart/index/checkTickets',
dataType: 'json',
data: data,
type: 'post',
success: function(addRestult) {
if (addRestult.code !== 200) {
if (addRestult.code === 401) {
window.location.href = '//m.yohobuy.com/signin.html?refer=' + window.location.href;
}
tip.show(addRestult.message);
} else {
$('#productSku').val(productSku);
$('#buyNumber').val(buyNumber);
$('#buyNowForm').submit();
}
},
error: function() {
tip.show('网络异常~');
}
});
},
/**
* 添加限购商品
*/
addLimitCode(limitProductCode, sku, skn, buyNum) {
let url = $('#limitProductPay').val() + '?limitproductcode=' + limitProductCode + '&sku=' +
sku + '&skn=' + skn + '&buy_number=' + buyNum;
// 调用接口判断商品是否可以购买
$.ajax({
url: url
}).then(function(res) {
// 如果有错,则商品不可购买,执行页面刷新,否则跳到结算页面
if (res.error) {
tip.show(res.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
location.href = url;
}
}).fail(function() {
tip.show('网络异常!');
setTimeout(function() {
location.reload();
}, 2000);
});
},
/**
* 添加到购物车
*/
addToCart(sku, skn, buyNum) {
$.ajax({
method: 'POST',
url: '/cart/index/add',
data: {
productSku: sku,
new_product_skn: skn,
buyNumber: buyNum
}
}).done(function(res) {
var cartNum;
if (res.code === 200) {
cartNum = res.data.goods_count;
if (cartNum > 99) {
cartNum = '99+';
}
$('.num-tag').html(cartNum).removeClass('hide');
}
if (res.message) {
tip.show(res.message);
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
});
}
};
module.exports = functions;