Authored by Lynnic

点赞功能

... ... @@ -5,9 +5,8 @@
*/
var $ = require('jquery'),
lazyLoad = require('yoho.lazyload'),
Swiper = require('yoho.iswiper');
var loading = require('../../plugin/loading'),
Swiper = require('yoho.iswiper'),
loading = require('../../plugin/loading'),
tip = require('../../plugin/tip');
var introUrl = $('#introUrl').val(),
... ...
... ... @@ -11,6 +11,7 @@ var goodsSwiper;
require('./desc');
require('./comments-consults');
require('./like.js');
require('../recommend-for-you.js');
lazyLoad($('img.lazy'));
... ...
/**
* 商品详情
* @author: Lynnic
* @date: 2015/11/24
*/
var $ = require('jquery'),
Hammer = require('yoho.hammer'),
tip = require('../../plugin/tip');
var likeHammer = new Hammer('#likeBtn');
likeHammer.on('tap', function(e) {
var productId = $('#productId').val(),
opt;
var $this = $(this);
if ($this.hasClass('liked')) {
opt = 'cancel';
} else {
opt = 'ok';
}
$.ajax({
type: 'POST',
url: '/product/opt/favoriteProduct',
data: {
id: productId,
opt: opt
},
success: function(data) {
if (data.code === 200) {
$this.toggleClass('liked');
} else if (data.code === 400) {
location.href = data.data;//未登录跳转登录页
} else {
tip.show(data.message);
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
\ No newline at end of file
... ...
... ... @@ -346,14 +346,14 @@ $basicBtnC:#eb0313;
font-size: pxToRem(47px);
color: #444;
}
&.unfavorite{
font-size: pxToRem(34px);
color:#ccc;
}
&.favorite {
font-size: pxToRem(34px);
color: $basicBtnC;
color: #ccc
}
&.favorite.liked{
color:$basicBtnC;;
}
&.addto-cart,
&.sold-out {
height: pxToRem(80px);
... ...
... ... @@ -119,9 +119,9 @@
<a href="" class="sold-out">已售罄</a>
{{/if}}
{{#if favorite}}
<a href="" class="favorite iconfont ">&#xe605;</a>
<a href="" id="likeBtn" class="favorite iconfont liked">&#xe605;</a>
{{else}}
<a href="" class="unfavorite iconfont ">&#xe605;</a>
<a href="" class="favorite iconfont">&#xe605;</a>
{{/if}}
</div>
{{/cartInfo}}
... ... @@ -130,5 +130,9 @@
<input id="introUrl" type="hidden" value={{introUrl}}>
{{/if}}
{{#if id}}
<input id="productId" type="hidden" value={{id}}>
{{/if}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...