define(["app"],function(app){

return app.controller("transactionsFundController", function($scope,$compile,$location) {
$scope.transactionsFund={};//定义对象
$scope.transactionsFundList=[];//定义对象数组

$scope.pages = 1; //默认查询总页数
$scope.size = 0; //默认每页显示条数
$scope.total = 0;


//清空模态框
$(".modal").on("hidden.bs.modal",function(){
$(this).removeData("bs.modal");
});
$('#myModal').on('shown.bs.modal', function () {

$("#myModal").html($compile($("#myModal").html())($scope));
});
$('#myModalModify').on('shown.bs.modal', function () {
$("#myModalModify").html($compile($("#myModalModify").html())($scope));
});

/************加载执行方法*******************/
$scope.load = function() {

$scope.queryList();

};
/************查询列表*******************/
$scope.queryList=function (){

$scope.transactionsFund.page=1;
$scope.transactionsFund.size=20;
DataCenter.find("TransactionsFund", $scope.transactionsFund);
}
/************列表返回*******************/
DataCenter.addEventListener("TransactionsFundList", function(e){
console.log("XXXXXXXXXXXXXXXXXXX"+e.data);
$scope.transactionsFundList = e.data.list;
$scope.pages = e.data.pages;
$scope.page = e.data.pageNum;
$scope.size= e.data.size;
$scope.total= e.data.total;
$scope.$apply();
});
DataCenter.addEventListener("TranFundList", function(){
$scope.transactionsFund.page=1;
$scope.transactionsFund.size=20;
DataCenter.find("TransactionsFund", $scope.transactionsFund);
});

//==================modify=======================

$scope.modifys = function (id) {
$location.search('FUND_ID_MDF', id);
}

//=====================删除==============================

//删除
$scope.del = function (id) {
$location.search('FUND_ID_MDF', id);
console.log("##################",id);


if(confirm('确认删除?')){
DataCenter.modify("TransactionsFund/del", {ID: id, STT: 99}, id);
}

};
DataCenter.addEventListener("delFund",function(e){

DataCenter.find("TransactionsFund", $scope.transactionsFund);
DataCenter.addEventListener("delFund",function(e){
alert('删除成功!');

});
});

//--------------页数选择--------------
$scope.selectPage = function(page){
if(page!=null&&page>0&&page<=$scope.pages){
$scope.transactionsProcesss.page=page;
$scope.transactionsProcesss.size=5;

DataCenter.find("TransactionsProcess", $scope.transactionsProcesss);
}else if(page>$scope.pages){
$("#errInfo").html("输入页数不能大于总页数!");
$('#errModal').modal('show');
}else if(page==0){
$("#errInfo").html("没有记录!");
$('#errModal').modal('show');
}else{
$("#errInfo").html("页数不能为空!");
$('#errModal').modal('show');
}
};

}).directive('pagination', function(){//动态分页显示
return {
restrict: 'E',
scope: {
numPages: '=',
currPage: '=',
onSelectPage: '&'
},

template: '<ul class="pagination">'
+'<li ng-class="{disabled: noPreviousPage()}">'
+'<a ng-click="selectHomePage()" href="">首页</a>'
+'</li>'

+'<li ng-class="{disabled: noPreviousPage()}">'
+'<a ng-click="selectPreviousPage()" href="">上一页</a>'
+'</li>'

+'<li ng-repeat="page in pages" ng-class="{active: isActivePage(page)}">'
+'<a ng-click="selectPage(page)" href="">{{page}}</a>'
+'</li>'

+'<li ng-class="{disabled: noNextPage()}">'
+'<a ng-click="selectNextPage()" href="">下一页</a>'
+'</li>'

+'<li ng-class="{disabled: noNextPage()}">'
+'<a ng-click="selectBackPage()" href="">尾页</a>'
+'</li>'
+'</ul>',

replace: true,
link: function(s){
/***************currPage监听事件*********************/
s.$watch('currPage', function(value){
s.pages = []; //定义一个数组供ng-repeat使用
if(s.numPages>=10){ //当总页数大于10的时候 (以10为分界线是因为每次显示的页面进制为10)

if(s.currPage>=Math.floor((s.numPages)/10)*10){ //当前页大于Math.floor((最后一页)/10)*10) 。将与最后一页十位相同的所有页数遍历出来

if(s.numPages%10!=0){
for(var i=-1;i<=s.numPages%10;i++){
s.pages.push(Math.floor(s.numPages/10)*10+i);
}
}else{
for(var i=-10;i<=0;i++){
s.pages.push(Math.floor(s.numPages/10)*10+i);
}
}

}else if(s.currPage<Math.floor(s.numPages/10)*10){ //当前页小于Math.floor((最后一页)/10)*10) 。将与当前页十位相同的所有页数遍历出来

for(var i=-1;i<=10;i++){
if(Math.floor(s.currPage/10)*10+i>0){
s.pages.push(Math.floor(s.currPage/10)*10+i);
}
};
//最后一页显示出来 提示总页数
}

}else if(s.numPages<10){ //当总页数小于10的时候 把所有页数都显示出来

for(var i=1;i<=s.numPages;i++){
s.pages.push(i);
}

}

if(s.currPage > value){
s.selectPage(value);
}
});

/***************numPages监听事件*********************/
s.$watch('numPages', function(value){
s.pages = []; //定义一个数组供ng-repeat使用
if(s.numPages>=10){ //当总页数大于10的时候 (以10为分界线是因为每次显示的页面进制为10)

if(s.currPage>=Math.floor((s.numPages)/10)*10){ //当前页大于Math.floor((最后一页)/10)*10) 。将与最后一页十位相同的所有页数遍历出来

if(s.numPages%10!=0){
for(var i=-1;i<=s.numPages%10;i++){
s.pages.push(Math.floor(s.numPages/10)*10+i);
}
}else{
for(var i=-10;i<=0;i++){
s.pages.push(Math.floor(s.numPages/10)*10+i);
}
}

}else if(s.currPage<Math.floor(s.numPages/10)*10){ //当前页小于Math.floor((最后一页)/10)*10) 。将与当前页十位相同的所有页数遍历出来

for(var i=-1;i<=10;i++){
if(Math.floor(s.currPage/10)*10+i>0){
s.pages.push(Math.floor(s.currPage/10)*10+i);
}
};
//最后一页显示出来 提示总页数
}

}else if(s.numPages<10){ //当总页数小于10的时候 把所有页数都显示出来

for(var i=1;i<=s.numPages;i++){
s.pages.push(i);
}

}

if(s.currPage > value){
s.selectPage(value);
}
});


//判断是否有上一页
s.noPreviousPage = function(){
return s.currPage === 1;
};

//判断是否有下一页
s.noNextPage = function(){
return s.currPage === s.numPages;
};

//判断当前页是否被选中
s.isActivePage = function(page){
return s.currPage===page;
};

//选择页数
s.selectPage = function(page){
if(!s.isActivePage(page)){
s.currPage = page;
s.onSelectPage({ page:page });
}
};

//选择下一页
s.selectNextPage = function(){
if(!s.noNextPage()){
s.selectPage(s.currPage+1);
}
};

//选择上一页
s.selectPreviousPage = function(){
if(!s.noPreviousPage()){
s.selectPage(s.currPage-1);
}
};
//选择首页
s.selectHomePage = function(){
s.selectPage(1);
};
//选择尾页
s.selectBackPage = function(){
s.selectPage(s.numPages);
};
}
};
});//end page

});;

posted on 2016-06-15 00:58  顺子2016  阅读(1190)  评论(0编辑  收藏  举报