Browse Source

列表数量bug

liting2017 6 years ago
parent
commit
1736e6833d
1 changed files with 11 additions and 13 deletions
  1. 11 13
      src/js/newMenu/adviserList.js

+ 11 - 13
src/js/newMenu/adviserList.js

@@ -200,18 +200,22 @@ $(function () {
     function colFun(){
         $('.txt .heart').click(function (e) {
             e.preventDefault();
-             e.stopPropagation();
-             let heart = $(this);
-             let id=$(this).parents('.txt').attr('data-id')
+            e.stopPropagation();
+            let nub=parseInt($(this).siblings().text()),
+                heart = $(this),
+                id=$(this).parents('.txt').attr('data-id')
              if (heart.hasClass('active')) {
-                 collectionApi(0,id) //取消关注
+                 $(this).removeClass('active')
+                 $(this).siblings().text(nub-1);
+                 collectionApi(0,id,nub) //取消关注
              } else {
-                 collectionApi(1,id) //关注
+                 $(this).addClass('active');
+                 $(this).siblings().text(nub+1);
+                 collectionApi(1,id,nub) //关注
              }
          })
     }
-    function collectionApi(index,ids) {
-        let nub=parseInt($('.nubCollect').text());
+    function collectionApi(index,ids,nub) {
         let url = index?'/api/user/portal/expertInterest':'/api/user/portal/expertCancelInterest';
         $.ajax({
             method: "post",
@@ -225,14 +229,8 @@ $(function () {
 		            msg(data.error[0].message);
                 }else{
                     if(!index){
-                        $('.heart').removeClass('active');
-                        $('.collectionN').removeClass('active');
-                        $('.nubCollect').text((nub-1))
                         $('#msg').val('取消关注')
                     }else{
-                        $('.heart').addClass('active');
-                        $('.collectionN').addClass('active');
-                        $('.nubCollect').text((nub+1));
                         $('#msg').val('关注成功,请至个人中心-我的关注查看.');
                     }
 		            msg(index?'关注成功,请至个人中心-我的关注查看.':'取消关注');