Authored by biao

咨询页面增加点赞/有用功能。 code review by Zhang Zhen

@@ -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) {
@@ -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;
140 } 151 }
141 } 152 }
  153 + li.fav {
  154 + .animate-count {
  155 + right: 65px;
  156 + }
  157 + }
  158 +
  159 + li.useful {
  160 + .animate-count {
  161 + right: 57px;
  162 + }
  163 + }
  164 + }
  165 +
  166 +
142 } 167 }
143 } 168 }
144 .readmore{ 169 .readmore{
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
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}}"> 11 + <div class="consult-item" data-id="{{id}}">
12 <div class="question"> 12 <div class="question">
13 <span class="iconfont">&#xe639;</span> 13 <span class="iconfont">&#xe639;</span>
14 <p> 14 <p>
@@ -23,21 +23,22 @@ @@ -23,21 +23,22 @@
23 </div> 23 </div>
24 24
25 <ul class="operation"> 25 <ul class="operation">
26 - <li class="fav {{#if fav}}highlight{{/if}}"> 26 + <li class="fav {{#if isLike}}highlight{{/if}}">
27 <i class="iconfont ">&#xe601;</i> 27 <i class="iconfont ">&#xe601;</i>
28 28
29 - <i class="count">{{#if favNum}}{{favNum}}{{/if}}</i> 29 + <i class="count">{{#if like}}{{like}}{{/if}}</i>
  30 + <span class="animate-count">+1</span>
30 </li> 31 </li>
31 - <li class="usefull {{#if usefull}}highlight{{/if}}"> 32 +
  33 + <li class="useful {{#if isUseful}}highlight{{/if}}">
32 <i class="iconfont ">&#xe605;</i> 34 <i class="iconfont ">&#xe605;</i>
33 有用 35 有用
34 - <i class="count">{{#if usefullNum}}{{usefullNum}}{{/if}}</i> 36 + <i class="count">{{#if useful}}{{useful}}{{/if}}</i>
  37 + <span class="animate-count">+1</span>
35 </li> 38 </li>
36 </ul> 39 </ul>
37 40
38 </div> 41 </div>
39 -  
40 -  
41 {{/list}} 42 {{/list}}
42 </div> 43 </div>
43 {{/ consults}} 44 {{/ consults}}