angular.module("myModule",[]).controller('myCtrl',function($scope) {
$scope.kaohzbTitle = "考核指标维护";
$scope.search = new Object();
$scope.isdisabled=false;
$scope.isInfo=false;
$scope.saveDate="";//用于保存得到的原始数据
// $http.post请求表格数据
// 模仿请求得到的数据
var datalist=[{
id:1,zbname:"中亚赛区比赛",zbtime:"2015-12-03",zbrul1:"胜利",zbrul2:"失败",por:"请输入说明
内容",
score:"2:1",type:"
支持红方"},{
id:2,zbname:"日韩赛区比赛",zbtime:"2015-11-11",zbrul2:"胜利",type:"
支持蓝方"},{
id:3,zbname:"欧美赛区比赛",zbtime:"2015-3-03",zbrul1:"失败",type:"双方相同"},{
id:4,zbname:"中东赛区比赛",zbtime:"2016-1-05",{
id:5,zbname:"北京赛区比赛",zbtime:"2014-12-23",{
id:6,zbname:"韩国赛区比赛",zbtime:"2015-11-01",{
id:7,zbname:"日本赛区比赛",zbtime:"2011-1-23",{
id:8,zbtime:"2013-12-15",{
id:9,zbtime:"2015-10-17",{
id:10,zbtime:"2015-11-21",{
id:11,zbtime:"2015-2-02",{
id:12,zbtime:"2015-2-05",type:"双方相同"}];
$scope.fun=function(){
var e=window.event||arguments[0];
var src=e.srcElement||e.target;
if(src.nodeName=="TD"){
var par=src.parentNode;
var sd=par.getElementsByTagName("td")[0];
if(sd.firstChild.checked==true){
sd.firstChild.checked=false;
}else{
$("tr td").attr("checked",false);
sd.firstChild.checked=true;
}
}
}
$scope.refresh=function(){//点击刷新按钮
显示表格
$scope.saveDate=datalist;
// console.log("结束赋予数据");
$scope.$watch("saveDate",function(){//2016.1.20监听列表
生成数据,当发生变化时执行刷新列表
table_page();
$scope.isshow=true;
});
}
$scope.save=function(){//页面提交按钮
console.log("准备保存");
console.log($scope.saveDate);//只要数据改变,自动保存到原始数据列表中
}
//表格分页功能
function table_page(){
var show_page=5;//每页显示的条数
var page_all=$("#page").children().size();//总条数
var current_page=1;//当前页
// console.log(page_all);
var page_num=Math.ceil(page_all/show_page);//总页数
var current_num=0;//用于生成页标的计数器
var li="";//页标元素
while(page_num>current_num){//循环生成页标元素
li+='<li class="page_num"><a href="javasctip:(0)">'+(current_num+1)+'';
current_num++;
}
$("#page_num_all").html(li);//添加页标到页面
$('#page tr').css('display','none');//设置隐藏
$('#page tr').slice(0,show_page).css('display','');//设置显示
$("#current_page").html(""+current_page+"");//显示当前页
$("#page_all").html(""+page_num+"");//显示总页数
$("#prevIoUs").click(function(){//上一页
var new_page=parseInt($("#current_page").text())-1;
if(new_page>0){
$("#current_page").html(""+new_page+"");
tab_page(new_page);
}
});
$("#next").click(function(){//下一页
var new_page=parseInt($("#current_page").text())+1;//当前页标
if(new_page<=page_num){//判断是否为最后或第一页
$("#current_page").html(""+new_page+"");
tab_page(new_page);
}
});
$(".page_num").click(function(){//页标跳转
var new_page=parseInt($(this).text());
tab_page(new_page);
});
function tab_page(index){//切换对应页标的页面
var start=(index-1)*show_page;//开始截取的页标
var end=start+show_page;//截取个数
$('#page').children().css('display','none').slice(start,end).css('display','');
current_page=index;
$("#current_page").html(""+current_page+"");
}
}
}).directive('contenteditable',function() {//自定义ngModel的属性可以用在div等其他元素中
return {
restrict: 'A',// 作为属性使用
require: '?ngModel',// 此指令所代替的函数
link: function(scope,element,attrs,ngModel) {
if (!ngModel) {
return;
} // do nothing if no ng-model
// Specify how UI should be updated
ngModel.$render = function() {
element.html(ngModel.$viewValue || '');
};
// Listen for change events to enable binding
element.on('blur keyup change',function() {
scope.$apply(readViewText);
});
// No need to initialize,AngularJS will initialize the text based on ng-model attribute
// Write data to the model
function readViewText() {
var html = element.html();
// When we clear the content editable the browser leaves a
behind
// If strip-br attribute is provided then we strip this out
if (attrs.stripBr && html === '
') {
html = '';
}
ngModel.$setViewValue(html);
}
}
};
})