//初始存数据
$http.get("querySportteryLeagues.do")
.success(function (result) {
localStorage.setItem ("a",result);
})
$("#endDate").blur(function(){
if($("#startDate").val() =="" && $("#endDate").val() ==""){
$scope.datar=true;
}else{
$scope.datar=false;
};
});
$scope.league = function () {
$scope.startDate = $("#startDate").val();
$scope.endDate = $("#endDate").val();
$http.get('listPheasantLeague.do?startDate=' + $scope.startDate + "&endDate=" + $scope.endDate)
.success(function(result){
//逻辑代码
//console.log(result); //看此参数返回的是什么数据
if (localStorage.getItem("leagues")) {
var lea =localStorage.getItem("leagues").split(",");
var html = "<div id='list' class='pad'>";
for (var i in result) {//用javascript的for/in循环遍历对象的属性
html += "<div class='move clearfix'><b>" + i + "</b>";
for (var j = 0; j < result[i].length; j++) {
var a = true;
for (var e = 0; e < lea.length; e++) {
if (lea[e] == result[i][j]) {
html += "<p><input type='checkbox' checked='checked' name='lista' value='" + result[i][j] + "' lay-skin='primary' />" + result[i][j] + "</p>"
a = false;
}
}
if (a == true) {
html += "<p><input type='checkbox' id='a' name='lista' value='" + result[i][j] + "' lay-skin='primary' />" + result[i][j] + "</p>"
}
}
html += "</div>";
}
html += "</div>";
} else {
var html = "<div id='list' class='pad'>";
for (var i in result) {
html += "<div class='move clearfix'><b>" + i + "</b>";
for (var j = 0; j < result[i].length; j++) {
var b = true;
for (var q = 0; q<array.length;q++){
if(result[i][j] == array[q]){
html += "<p><input type='checkbox' checked='checked' name='lista' value='" + result[i][j] + "' lay-skin='primary' />" + result[i][j] + "</p>"
b = false;
}
}
if(b = true){
html += "<p><input type='checkbox' name='lista' value='" + result[i][j] + "' lay-skin='primary' />" + result[i][j] + "</p>"
}
}
html += "</div>";
}
html += "</div>";
}
layer.confirm(html, {
area: ['40%', 'auto'],
btn: ['竞赛','二期','全选', '全不选', '确定', '取消'],
btn1: function () {
var jing = localStorage.getItem("a").split(",");
/* $('input:checkbox').each(function() {
if ($(this).prop('checked') ==true) {
$(this).prop("checked",false)
}
}); */
$.each(jing,function(i,item){
$("input[name='lista'][value="+item+"]").prop("checked","true");
});
}, btn2: function () {
/* var jing = localStorage.getItem("a").split(",");
$("input[name='lista']").each(function(){
var checkFlag = true;
for(var q=0;q<jing.length;q++){
if($(this).val() == jing[q]) {
checkFlag = false;
}
}
if(checkFlag) {
$(this).prop("checked",true);
}
});*/
/* $('input:checkbox').each(function() {
if ($(this).prop('checked') ==true) {
$(this).prop("checked",false)
}
}); */
$("input[name='checkbox']").each(function(){
if($(this).prop("checked")) {
$(this).prop("checked",false);
}
});
$.each(pheasantLeaguesS2,function(i,item){
$("input[name='lista'][value="+item+"]").prop("checked","true");
});
return false;
}, btn3: function () {
$("#list :checkbox").prop("checked", true);
return false;
}, btn4: function () {
$("#list :checkbox").prop("checked", false);
return false;
}, btn5: function () {
var valArr = new Array;
$("input[name='lista']:checked").each(function (i) {
valArr[i] = $(this).val();
});
var leagues = "";
if (valArr.join(',')) {
leagues = valArr.join(',');//转换为逗号隔开的字符串'
}
/* var obj ="";
if(leagues !=""){
obj = leagues.split(",");
} */
localStorage.setItem("leagues",leagues);
}, end: function () {
}
});
})
//console.log(localStorage.getItem("leagues").split(",").length,"aaa");
}