...
|
...
|
@@ -6,80 +6,73 @@ |
|
|
|
|
|
|
|
|
var $ = require('jquery'),
|
|
|
Hammer = require('yoho.hammer'),
|
|
|
tip = require('../../plugin/tip'),
|
|
|
chosePanel = require('../../cart/chose-panel');
|
|
|
tip = require('../../plugin/tip'),
|
|
|
chosePanel = require('../../cart/chose-panel');
|
|
|
|
|
|
var likeEle = document.getElementById('likeBtn'),
|
|
|
likeHammer = likeEle && new Hammer(likeEle);
|
|
|
var productId = $('#productId').val();
|
|
|
|
|
|
var addToCartEle = document.getElementById('addtoCart'),
|
|
|
addToCartHammer = addToCartEle && new Hammer(addToCartEle),
|
|
|
productId = $('#productId').val();
|
|
|
$('#likeBtn').on('click', function() {
|
|
|
var opt,
|
|
|
favorite;
|
|
|
|
|
|
if (likeHammer) {
|
|
|
likeHammer.on('tap', function(e) {
|
|
|
var opt,
|
|
|
favorite;
|
|
|
var $this = $(this);
|
|
|
|
|
|
var $this = $(e.target);
|
|
|
if ($this.hasClass('liked')) {
|
|
|
opt = 'cancel';
|
|
|
favorite = 0;
|
|
|
} else {
|
|
|
opt = 'ok';
|
|
|
favorite = 1;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('liked')) {
|
|
|
opt = 'cancel';
|
|
|
favorite = 0;
|
|
|
} else {
|
|
|
opt = 'ok';
|
|
|
favorite = 1;
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/product/opt/favoriteProduct',
|
|
|
data: {
|
|
|
id: productId,
|
|
|
opt: opt
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$this.toggleClass('liked');
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/product/opt/favoriteProduct',
|
|
|
data: {
|
|
|
id: productId,
|
|
|
opt: opt
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$this.toggleClass('liked');
|
|
|
|
|
|
if ('cancel' === opt) {
|
|
|
tip.show('取消收藏成功');
|
|
|
} else if ('ok' === opt) {
|
|
|
tip.show('收藏成功');
|
|
|
}
|
|
|
} else if (data.code === 400) {
|
|
|
location.href = data.data;//未登录跳转登录页
|
|
|
} else {
|
|
|
tip.show(data.message);
|
|
|
if ('cancel' === opt) {
|
|
|
tip.show('取消收藏成功');
|
|
|
} else if ('ok' === opt) {
|
|
|
tip.show('收藏成功');
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
} else if (data.code === 400) {
|
|
|
location.href = data.data;//未登录跳转登录页
|
|
|
} else {
|
|
|
tip.show(data.message);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 统计代码:用于统计用户加入或取消商品收藏的动作
|
|
|
if (window._yas) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
pd: productId,
|
|
|
fa: favorite
|
|
|
}, true);
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (addToCartHammer) {
|
|
|
addToCartHammer.on('tap', function(e) {
|
|
|
chosePanel.show();
|
|
|
// 统计代码:用于统计用户加入或取消商品收藏的动作
|
|
|
if (window._yas) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
pd: productId,
|
|
|
fa: favorite
|
|
|
}, true);
|
|
|
}
|
|
|
|
|
|
//统计代码:用于统计用户加入购物车的动作
|
|
|
if (window._yas) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
pd: productId,
|
|
|
by: 1
|
|
|
}, true);
|
|
|
}
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
});
|
|
|
} |
|
|
$('#addtoCart').on('click', function() {
|
|
|
chosePanel.show();
|
|
|
|
|
|
//统计代码:用于统计用户加入购物车的动作
|
|
|
if (window._yas) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
pd: productId,
|
|
|
by: 1
|
|
|
}, true);
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}); |
|
|
\ No newline at end of file |
...
|
...
|
|