咨询页面增加点赞/有用功能。 code review by Zhang Zhen
Showing
3 changed files
with
71 additions
and
57 deletions
@@ -11,30 +11,17 @@ | @@ -11,30 +11,17 @@ | ||
11 | var goodsConsultsEle = $('#goods-consults')[0], | 11 | var goodsConsultsEle = $('#goods-consults')[0], |
12 | goodsConsultsHammer = goodsConsultsEle && new Hammer(goodsConsultsEle); | 12 | goodsConsultsHammer = goodsConsultsEle && new Hammer(goodsConsultsEle); |
13 | 13 | ||
14 | -// $favBtn.on('click', function() { | ||
15 | -// var id = $(this).closest('.consult-item').data('id'), | ||
16 | -// $that = $(this), | ||
17 | -// count = $that.find('.count').html() - 0; | ||
18 | -// if (!$(this).hasClass('highlight')) { | ||
19 | -// $.ajax({ | ||
20 | -// method: 'post', | ||
21 | -// url: '/home/upxxDown', | ||
22 | -// data: { | ||
23 | -// consult_id: id | ||
24 | -// } | ||
25 | -// }).done(function(data) { | ||
26 | -// if (data.code === 200) { | ||
27 | -// $that.addClass('highlight'); | ||
28 | -// $that.find('.count').html(count+1); | ||
29 | -// } else if (data.code === 400) { | ||
30 | -// location.href = data.data;//未登录跳转登录页 | ||
31 | -// } | ||
32 | -// }).fail(function(data) { | ||
33 | -// $that.addClass('highlight'); | ||
34 | -// $that.find('.count').html(count+1); | ||
35 | -// }); | ||
36 | -// } | ||
37 | -// }); | 14 | +function showCountPlus($el) { |
15 | + var $count = $el.find('.animate-count'); | ||
16 | + $count.css('display','inline'); | ||
17 | + $count.animate({ | ||
18 | + opacity: 0.25, | ||
19 | + fontSize: '0.7rem', | ||
20 | + right: '-=5' | ||
21 | + }, 300, function () { | ||
22 | + $count.css('display', 'none'); | ||
23 | + }); | ||
24 | +} | ||
38 | 25 | ||
39 | if (goodsConsultsHammer) { | 26 | if (goodsConsultsHammer) { |
40 | 27 | ||
@@ -48,22 +35,23 @@ if (goodsConsultsHammer) { | @@ -48,22 +35,23 @@ if (goodsConsultsHammer) { | ||
48 | if (!$this.hasClass('highlight')) { | 35 | if (!$this.hasClass('highlight')) { |
49 | 36 | ||
50 | if ($this.hasClass('fav')) { | 37 | if ($this.hasClass('fav')) { |
51 | - url = '/product/opt/fav'; | ||
52 | - } else if ($this.hasClass('usefull')) { | ||
53 | - url = '/product/opt/usefull'; | 38 | + url = '/product/detail/consultupvote'; |
39 | + } else if ($this.hasClass('useful')) { | ||
40 | + url = '/product/detail/consultuseful'; | ||
54 | } | 41 | } |
55 | 42 | ||
56 | $.ajax({ | 43 | $.ajax({ |
57 | method: 'post', | 44 | method: 'post', |
58 | url: url, | 45 | url: url, |
59 | data: { | 46 | data: { |
60 | - consult_id: id | 47 | + id: id |
61 | } | 48 | } |
62 | }).done(function(data) { | 49 | }).done(function(data) { |
63 | if (data.code === 200) { | 50 | if (data.code === 200) { |
51 | + showCountPlus($this); | ||
64 | $this.addClass('highlight'); | 52 | $this.addClass('highlight'); |
65 | $this.find('.count').html(count + 1); | 53 | $this.find('.count').html(count + 1); |
66 | - } else if (data.code === 400) { | 54 | + } else if (data.code === 401) { |
67 | location.href = data.data;//未登录跳转登录页 | 55 | location.href = data.data;//未登录跳转登录页 |
68 | } | 56 | } |
69 | }).fail(function(data) { | 57 | }).fail(function(data) { |
@@ -72,4 +60,4 @@ if (goodsConsultsHammer) { | @@ -72,4 +60,4 @@ if (goodsConsultsHammer) { | ||
72 | 60 | ||
73 | } | 61 | } |
74 | }); | 62 | }); |
75 | -} | ||
63 | +} |
@@ -55,6 +55,7 @@ | @@ -55,6 +55,7 @@ | ||
55 | height: pxToRem(120px); | 55 | height: pxToRem(120px); |
56 | background-color: #ffffff; | 56 | background-color: #ffffff; |
57 | border-bottom: 1px solid $borderC; | 57 | border-bottom: 1px solid $borderC; |
58 | + z-index: 10; | ||
58 | i, | 59 | i, |
59 | span, | 60 | span, |
60 | a { | 61 | a { |
@@ -137,8 +138,32 @@ | @@ -137,8 +138,32 @@ | ||
137 | padding-right: 5px; | 138 | padding-right: 5px; |
138 | font-size: inherit; | 139 | font-size: inherit; |
139 | } | 140 | } |
141 | + position: relative; | ||
142 | + .animate-count { | ||
143 | + display: none; | ||
144 | + position: absolute; | ||
145 | + top: 0; | ||
146 | + font-size: pxToRem(20px); | ||
147 | + z-index: 5; | ||
148 | + } | ||
149 | + i.count { | ||
150 | + position: absolute; | ||
151 | + } | ||
152 | + } | ||
153 | + li.fav { | ||
154 | + .animate-count { | ||
155 | + right: 65px; | ||
156 | + } | ||
157 | + } | ||
158 | + | ||
159 | + li.useful { | ||
160 | + .animate-count { | ||
161 | + right: 57px; | ||
162 | + } | ||
140 | } | 163 | } |
141 | } | 164 | } |
165 | + | ||
166 | + | ||
142 | } | 167 | } |
143 | } | 168 | } |
144 | .readmore{ | 169 | .readmore{ |
@@ -6,39 +6,40 @@ | @@ -6,39 +6,40 @@ | ||
6 | <a href="javascript:;" class="iconfont enter-consult-page"></a> | 6 | <a href="javascript:;" class="iconfont enter-consult-page"></a> |
7 | </div> | 7 | </div> |
8 | {{# consults}} | 8 | {{# consults}} |
9 | - <div class="goods-consults" id="goods-consults"> | 9 | + <div class="goods-consults" id="goods-consults"> |
10 | {{#list}} | 10 | {{#list}} |
11 | - <div class="consult-item" data-id="{{consult-id}}"> | ||
12 | - <div class="question"> | ||
13 | - <span class="iconfont"></span> | ||
14 | - <p> | ||
15 | - {{question}}<br> | ||
16 | - <span class="time">{{time}}</span> | ||
17 | - </p> | ||
18 | - </div> | 11 | + <div class="consult-item" data-id="{{id}}"> |
12 | + <div class="question"> | ||
13 | + <span class="iconfont"></span> | ||
14 | + <p> | ||
15 | + {{question}}<br> | ||
16 | + <span class="time">{{time}}</span> | ||
17 | + </p> | ||
18 | + </div> | ||
19 | 19 | ||
20 | - <div class="answer"> | ||
21 | - <span class="iconfont"></span> | ||
22 | - <p>{{answer}}</p> | ||
23 | - </div> | 20 | + <div class="answer"> |
21 | + <span class="iconfont"></span> | ||
22 | + <p>{{answer}}</p> | ||
23 | + </div> | ||
24 | 24 | ||
25 | - <ul class="operation"> | ||
26 | - <li class="fav {{#if fav}}highlight{{/if}}"> | 25 | + <ul class="operation"> |
26 | + <li class="fav {{#if isLike}}highlight{{/if}}"> | ||
27 | <i class="iconfont "></i> | 27 | <i class="iconfont "></i> |
28 | 赞 | 28 | 赞 |
29 | - <i class="count">{{#if favNum}}{{favNum}}{{/if}}</i> | ||
30 | - </li> | ||
31 | - <li class="usefull {{#if usefull}}highlight{{/if}}"> | ||
32 | - <i class="iconfont "></i> | ||
33 | - 有用 | ||
34 | - <i class="count">{{#if usefullNum}}{{usefullNum}}{{/if}}</i> | ||
35 | - </li> | ||
36 | - </ul> | 29 | + <i class="count">{{#if like}}{{like}}{{/if}}</i> |
30 | + <span class="animate-count">+1</span> | ||
31 | + </li> | ||
37 | 32 | ||
38 | - </div> | 33 | + <li class="useful {{#if isUseful}}highlight{{/if}}"> |
34 | + <i class="iconfont "></i> | ||
35 | + 有用 | ||
36 | + <i class="count">{{#if useful}}{{useful}}{{/if}}</i> | ||
37 | + <span class="animate-count">+1</span> | ||
38 | + </li> | ||
39 | + </ul> | ||
39 | 40 | ||
40 | - | ||
41 | - {{/list}} | 41 | + </div> |
42 | + {{/list}} | ||
42 | </div> | 43 | </div> |
43 | {{/ consults}} | 44 | {{/ consults}} |
44 | 45 | ||
@@ -49,7 +50,7 @@ | @@ -49,7 +50,7 @@ | ||
49 | 常见问题 | 50 | 常见问题 |
50 | </h1> | 51 | </h1> |
51 | {{/faq}} | 52 | {{/faq}} |
52 | - | 53 | + |
53 | {{#faq}} | 54 | {{#faq}} |
54 | <div class="goods-consults" style="margin-top:0"> | 55 | <div class="goods-consults" style="margin-top:0"> |
55 | {{#list}} | 56 | {{#list}} |
-
Please register or login to post a comment