layui.use('form', function(){ var form = layui.form; form.on('checkbox(check)', function(data){ // console.log(data.elem); //得到checkbox原始DOM对象 // console.log(data.elem.checked); //是否被选中,true或者false // console.log(data.value); //复选框value值,也可以通过data.elem.value得到 // console.log(data.othis); //得到美化后的DOM对象 if(data.elem.checked){ if (!contains(topicid, $(this).parents('tr').find('.itemId').html())) { topicid.push($(this).parents('tr').find('.itemId').html()); } if(topicid.length == 10){ $('#checkAll').prop("checked", true); } }else{ removeByValue(topicid, $(this).parents('tr').find('.itemId').html()) if(topicid.length < 10){ $('#checkAll').prop("checked", false); } } layui.use('form', function(){ var form = layui.form; form.render(); //更新全部 }); }); form.on('checkbox(checkAll)', function(data){ if(data.elem.checked){ $('.check').each(function () { $(this).prop("checked", true); $(this).parents('tr').addClass('selectedColor'); if (!contains(topicid, $(this).parents('tr').find('.itemId').html())) { topicid.push($(this).parents('tr').find('.itemId').html()); } }); }else{ $('.check').each(function () { $(this).parents('tr').removeClass('selectedColor'); $(this).prop("checked", false); }); topicid = []; } layui.use('form', function(){ var form = layui.form; form.render(); //更新全部 }); }); }); var topicid = []; //imei数组 //遍历当前是否已经有选中状态 function isCheck(){ $('.check').each(function () { if($(this).prop("checked") == true){ topicid.push($(this).parents('tr').find('.itemId').html()); } }) } //移除数组元素 function removeByValue(arr, val) { for (var i = 0; i < arr.length; i++) { if (arr[i] == val) { arr.splice(i, 1); break; } } } //判断数组中是否包含元素 function contains(arr, obj) { var i = arr.length; while (i--) { if (arr[i] === obj) { return true; } } return false; } // 分页初始化 layui.use('laypage', function () { var laypage = layui.laypage; var uname = $('#uname').val() laypage.render({ elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号 // , count: 30 , count: $('#totalPage').val() ,theme: '#428BCA' , layout: ['prev', 'page', 'next', 'skip'] , jump: function (obj) { topicid = []; $.ajax({ url: 'allot_equip_list?uname=' + uname + '&page=' + obj.curr, type: 'get', success: function (data) { $('#table tbody').html(''); $('#table tbody').html(data); if ($('#totalPage').val() > 0) { $('.nullData').hide(); $('#page').parent().show(); } else { $('.nullData').show(); $('#page').parent().hide(); } isCheck(); layui.use('form', function(){ var form = layui.form; form.render(); //更新全部 //各种基于事件的操作,下面会有进一步介绍 }); } }) } }); }); //设备筛选: function sub_filter() { var uname = $('#uname').val(); var type = $('#type').val(); var f_id = $('#identity').val(); var begin = $('#begin').val(); var end = $('#end').val(); $("#data_table tr:not(:first)").html(""); $.ajax({ url: 'allot_equip_list', type: 'post', data: { req: "filter", uname: uname, type: type, f_id: f_id, begin: begin, end: end, page:1 }, success: function (data) { $('#table tbody').html(''); $('#table tbody').html(data); if ($('#total_nums').val() > 0) { $('.nullData').hide(); $('#page').parent().show(); } else { $('.nullData').show(); $('#page').parent().hide(); } layui.use('form', function(){ var form = layui.form; form.render(); //更新全部 //各种基于事件的操作,下面会有进一步介绍 }); var datas = { req: "filter", uname: uname, type: type, f_id: f_id, begin: begin, end: end } initSearchPage($('#total_nums').val(),'allot_equip_list', datas); } }) } //设备搜索分页 function initSearchPage(page, url, datas) { layui.use('laypage', function () { var laypage = layui.laypage; var uname = $('#uname').val() laypage.render({ elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号 // , count: 30 , count: page ,theme: '#428BCA' , layout: ['prev', 'page', 'next', 'skip'] , jump: function (obj, first) { datas.page = obj.curr; topicid = []; if (!first) { $.ajax({ url: url, type: 'post', data: datas, success: function (data) { $('#table tbody').html(''); $('#table tbody').html(data); if ($('#total_nums').val() > 0) { $('.nullData').hide(); $('#page').parent().show(); } else { $('.nullData').show(); $('#page').parent().hide(); } layui.use('form', function(){ var form = layui.form; form.render(); //更新全部 //各种基于事件的操作,下面会有进一步介绍 }); } }) } } }); }); } // 返回 function goback(){ var currPage = $('#currPage').val(); var f_name = $('#f_name').val(); window.location.href = 'equipallot?uname='+f_name+'&page='+currPage; }