Showing
5 changed files
with
57 additions
and
10 deletions
@@ -5,9 +5,8 @@ | @@ -5,9 +5,8 @@ | ||
5 | */ | 5 | */ |
6 | var $ = require('jquery'), | 6 | var $ = require('jquery'), |
7 | lazyLoad = require('yoho.lazyload'), | 7 | lazyLoad = require('yoho.lazyload'), |
8 | - Swiper = require('yoho.iswiper'); | ||
9 | - | ||
10 | -var loading = require('../../plugin/loading'), | 8 | + Swiper = require('yoho.iswiper'), |
9 | + loading = require('../../plugin/loading'), | ||
11 | tip = require('../../plugin/tip'); | 10 | tip = require('../../plugin/tip'); |
12 | 11 | ||
13 | var introUrl = $('#introUrl').val(), | 12 | var introUrl = $('#introUrl').val(), |
@@ -11,6 +11,7 @@ var goodsSwiper; | @@ -11,6 +11,7 @@ var goodsSwiper; | ||
11 | 11 | ||
12 | require('./desc'); | 12 | require('./desc'); |
13 | require('./comments-consults'); | 13 | require('./comments-consults'); |
14 | +require('./like.js'); | ||
14 | require('../recommend-for-you.js'); | 15 | require('../recommend-for-you.js'); |
15 | 16 | ||
16 | lazyLoad($('img.lazy')); | 17 | lazyLoad($('img.lazy')); |
static/js/product/detail/like.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情 | ||
3 | + * @author: Lynnic | ||
4 | + * @date: 2015/11/24 | ||
5 | + */ | ||
6 | +var $ = require('jquery'), | ||
7 | + Hammer = require('yoho.hammer'), | ||
8 | + tip = require('../../plugin/tip'); | ||
9 | + | ||
10 | +var likeHammer = new Hammer('#likeBtn'); | ||
11 | + | ||
12 | +likeHammer.on('tap', function(e) { | ||
13 | + var productId = $('#productId').val(), | ||
14 | + opt; | ||
15 | + var $this = $(this); | ||
16 | + | ||
17 | + if ($this.hasClass('liked')) { | ||
18 | + opt = 'cancel'; | ||
19 | + } else { | ||
20 | + opt = 'ok'; | ||
21 | + } | ||
22 | + | ||
23 | + $.ajax({ | ||
24 | + type: 'POST', | ||
25 | + url: '/product/opt/favoriteProduct', | ||
26 | + data: { | ||
27 | + id: productId, | ||
28 | + opt: opt | ||
29 | + }, | ||
30 | + success: function(data) { | ||
31 | + if (data.code === 200) { | ||
32 | + $this.toggleClass('liked'); | ||
33 | + } else if (data.code === 400) { | ||
34 | + location.href = data.data;//未登录跳转登录页 | ||
35 | + } else { | ||
36 | + tip.show(data.message); | ||
37 | + } | ||
38 | + }, | ||
39 | + error: function() { | ||
40 | + tip.show('网络断开连接了~'); | ||
41 | + } | ||
42 | + }); | ||
43 | +}); |
@@ -346,14 +346,14 @@ $basicBtnC:#eb0313; | @@ -346,14 +346,14 @@ $basicBtnC:#eb0313; | ||
346 | font-size: pxToRem(47px); | 346 | font-size: pxToRem(47px); |
347 | color: #444; | 347 | color: #444; |
348 | } | 348 | } |
349 | - &.unfavorite{ | ||
350 | - font-size: pxToRem(34px); | ||
351 | - color:#ccc; | ||
352 | - } | ||
353 | &.favorite { | 349 | &.favorite { |
354 | font-size: pxToRem(34px); | 350 | font-size: pxToRem(34px); |
355 | - color: $basicBtnC; | 351 | + color: #ccc |
356 | } | 352 | } |
353 | + &.favorite.liked{ | ||
354 | + color:$basicBtnC;; | ||
355 | + } | ||
356 | + | ||
357 | &.addto-cart, | 357 | &.addto-cart, |
358 | &.sold-out { | 358 | &.sold-out { |
359 | height: pxToRem(80px); | 359 | height: pxToRem(80px); |
@@ -119,9 +119,9 @@ | @@ -119,9 +119,9 @@ | ||
119 | <a href="" class="sold-out">已售罄</a> | 119 | <a href="" class="sold-out">已售罄</a> |
120 | {{/if}} | 120 | {{/if}} |
121 | {{#if favorite}} | 121 | {{#if favorite}} |
122 | - <a href="" class="favorite iconfont "></a> | 122 | + <a href="" id="likeBtn" class="favorite iconfont liked"></a> |
123 | {{else}} | 123 | {{else}} |
124 | - <a href="" class="unfavorite iconfont "></a> | 124 | + <a href="" class="favorite iconfont"></a> |
125 | {{/if}} | 125 | {{/if}} |
126 | </div> | 126 | </div> |
127 | {{/cartInfo}} | 127 | {{/cartInfo}} |
@@ -129,6 +129,10 @@ | @@ -129,6 +129,10 @@ | ||
129 | {{#if introUrl}} | 129 | {{#if introUrl}} |
130 | <input id="introUrl" type="hidden" value={{introUrl}}> | 130 | <input id="introUrl" type="hidden" value={{introUrl}}> |
131 | {{/if}} | 131 | {{/if}} |
132 | + | ||
133 | + {{#if id}} | ||
134 | + <input id="productId" type="hidden" value={{id}}> | ||
135 | + {{/if}} | ||
132 | 136 | ||
133 | </div> | 137 | </div> |
134 | {{> layout/footer}} | 138 | {{> layout/footer}} |
-
Please register or login to post a comment