From eb996280a6048388bcda33219506894bd4edc1a8 Mon Sep 17 00:00:00 2001 From: txz Date: Thu, 7 Apr 2016 15:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/javascripts/wechat/app.js | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index 6061b665e..0a7e80d16 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -10,7 +10,7 @@ app.factory('auth', function($http,$routeParams, $cookies, $q){ var _openid = ''; if(debug===true){ - _openid = "1"; + _openid = "2"; } var getOpenId = function() { @@ -61,7 +61,7 @@ app.factory('rms', function(){ return {save: save, get: get}; }); -app.controller('ActivityController',function($scope, $http, auth, rms){ +app.controller('ActivityController',function($scope, $http, auth, rms, common){ $scope.replaceUrl = function(url){ return "http://www.trustie.net/" + url; }; @@ -90,23 +90,22 @@ app.controller('ActivityController',function($scope, $http, auth, rms){ } ); - $scope.addPraise = function(act){ - act.activity_praise_count += 1; - act.has_praise = true; - - //$http - - }; - $scope.decreasePraise = function(act){ - act.activity_praise_count -= 1; - act.has_praise = false; - }; $scope.loadActData = loadActData; + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act,'activities'); + } + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act,'activities'); + } + }); -app.factory('common', function($http, auth){ +app.factory('common', function($http, auth, $routeParams){ var addCommonReply = function(id, type, data, cb){ console.log(data.comment); @@ -140,7 +139,36 @@ app.factory('common', function($http, auth){ }) }; - return {addCommonReply: addCommonReply, loadCommonData: loadCommonData}; + var addCommonPraise = function(act, type){ + act.activity_praise_count += 1; + act.has_praise = true; + + $http({ + method: 'POST', + url: apiUrl, + data:{openid:auth.openid(),type:type,id:$routeParams.id} + }).then(function successCallback(response) { + console.log("点赞成功"); + }, function errorCallback(response) { + }); + + }; + + var decreaseCommonPraise = function(act, type){ + act.activity_praise_count -= 1; + act.has_praise = false; + + $http({ + method: 'POST', + url: apiUrl , + data:{openid:auth.openid(),type:type,id:$routeParams.id} + }).then(function successCallback(response) { + console.log("取消赞成功"); + }, function errorCallback(response) { + }); + }; + + return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise}; }); app.controller('IssueController', function($scope, $http, $routeParams, auth, common){