| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- 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;
- }
|