socialforge/public/javascripts/wechat/controllers/activity.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-06-14 14:24:39 +08:00
app.controller('ActivityController',
['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common','alertService',
function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common, alertService){
2016-06-14 14:24:39 +08:00
$scope.replaceUrl = function(url){
return url;
};
$scope.alertService = alertService.create();
2016-06-14 14:24:39 +08:00
console.log("ActivityController load");
$scope.page = rms.get('page') || 0;
$scope.activities = rms.get("activities") || [];
$scope.has_more = rms.get("has_more");
$scope.loadActData = function(page){
$scope.page = page;
$http({
method: 'POST',
url: apiUrl+ "activities",
data: {token: auth.token(), page: page}
2016-06-14 14:24:39 +08:00
}).then(function successCallback(response) {
if(response.data.page >0) {
$scope.activities = $scope.activities.concat(response.data.data);
} else {
$scope.activities = response.data.data;
}
rms.save("activities", $scope.activities);
$scope.has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
rms.save('has_more', $scope.has_more);
rms.save('page', response.data.page);
console.log(response.data);
}, function errorCallback(response) {
});
};
if($scope.activities.length<=0){
$scope.loadActData(0);
2016-06-14 14:24:39 +08:00
} else {
$timeout(function(){
window.scrollTo(0, rms.get("yoffset"));
});
}
//跳到详情页
$scope.goDetail = function(type, act_id,id){
rms.save("yoffset", window.document.body.scrollTop);
$location.path('/'+type+'/'+act_id);
}
$scope.addPraise = function(act){
common.addCommonPraise(act);
};
$scope.decreasePraise = function(act){
common.decreaseCommonPraise(act);
};
}]);