functions.js
3.82 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
let $ = require('yoho-jquery'),
tip = require('plugin/tip'),
yoho = require('yoho-app');
let functions = {
/**
* 添加门票
*/
addTickets(productSku, buyNumber) {
let 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 {
window.location.href = '/cart/index/ticketsConfirm?productSku=' + productSku +
'&buyNumber=' + buyNumber;
}
},
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) {
if (!yoho.isLogin()) {
let preInfo = `${sku}_${skn}_${buyNum}`;
let actCkOpthn = {
path: '/product',
expires: 1
};
window.setCookie('tmp-cart-info', preInfo, actCkOpthn);
window.location.href = '//m.yohobuy.com/signin.html?refer=' + encodeURIComponent(window.location.href);
return false;
}
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_GDS_DT_ADD_TO_SC',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')],
PRD_ID: $('#productId').val(),
PRD_NUM: buyNum,
PRD_SKN: skn,
PRD_SKU: sku
})
}, true);
}
$.ajax({
method: 'POST',
url: '//m.yohobuy.com/cart/index/add',
data: {
productSku: sku,
new_product_skn: skn,
buyNumber: buyNum
},
xhrFields: {
withCredentials: true
},
}).done(function(res) {
let cartNum;
if (res.code === 200) {
cartNum = res.data.goods_count;
if (cartNum > 99) {
cartNum = '99+';
}
$('.num-tag').html(cartNum).removeClass('hide');
window.setCookie('tmp-cart-info', '');
}
if (res.message) {
tip.show(res.message);
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
});
}
};
module.exports = functions;