<script type = "text/javascript">
var app = angular.module('pinyougou',['pagination']);
app.controller('brandController',function($scope,$http){
//查询品牌列表
$scope.findAll=function(){
$http.get('../brand/findAll.do').success(
function(response){
$scope.list = response;
}
);
}
$scope.paginationConf = {
currentPage: 1, //当前页
totalItems: 10, //总记录数
itemsPerPage: 10,//每页的记录数
perPageOptions: [10, 20, 30, 40, 50],//每页显示多少行,分页选项
onChange: function(){ //当页码重启变更的时候,自动触发方法
$scope.reloadList();
}
};
$scope.reloadList=function(){
$scope.search( $scope.paginationConf.currentPage , $scope.paginationConf.itemsPerPage );
}
//分页
$scope.findPage=function(page,size){
$http.get('../brand/findPage.do?page='+page+'&size='+size).success(
function(response){
$scope.list=response.rows;//显示当前页数据
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
//增加
$scope.save=function(){
var methodName = 'add';
if($scope.entity.id!=null){
methodName='update';
}
$http.post('../brand/'+methodName+'.do',$scope.entity).success(
function(response){
if(response.success){
alert(response.message);
$scope.reloadList();
}else{
alert(response.message);
}
}
);
}
//查询
$scope.findOne=function(id){
$http.get('../brand/findOne.do?id='+id).success(
function(response){
$scope.entity=response;
}
);
}
$scope.selectIds = [];//用户勾选的ID集合
//用户勾选复选框
$scope.updateSelection=function($event,id){
if($event.target.checked){
$scope.selectIds.push(id);//向集合(数组)中添加元素
}else{
var index = $scope.selectIds.indexOf(id);
$scope.selectIds.splice(index,1);
}
}
//删除
$scope.dele=function(){
$http.get('../brand/delete.do?ids='+$scope.selectIds).success(
function(response){
if(response){
alert(response.message);
$scope.reloadList();
}else{
alert(response.message);
}
}
);
}
$scope.searchEntity={};
$scope.search=function(page,size){
$http.post('../brand/serch.do?page='+page+'&size='+size,$scope.searchEntity).success(
function(response){
$scope.list=response.rows;//显示当前页数据
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
});
</script>