/** * Created by Administrator on 2016/9/7. */ $(document).on('click','.submitform',function(){ var serialize=$(this).parents('form').serialize(); var action=$(this).parents('form').attr('action'); qls.loading(); $.post(action,serialize,function(data){ qls.close(); if(data.code==1) { qls.success(data.msg,data.url); } else { qls.error(data.msg); } },'json'); }); $(document).on('click','.deleteall',function(){ var length= $('input[type="checkbox"].i-checks:checked').length; var ids=''; for(var i=0;ilevel) { $('#'+ids+' select.form-control.m-b').eq(i).remove(); continue; } i++; } var filed=$(obj).attr('field'); $.post(jscascadeUrl,{model:tabelname,column:column,parentId:$(obj).val(),filed:JSON.parse(filed)},function(data){ if(data.data!=null) { var htm=''; if(data.data.length>0) $(obj).after(htm); } },'json'); } function sendGetAjax(url,datas,fun) { qls.loading(); if(datas==null)datas={}; $.get(url,datas,function(data){ qls.close(); if(fun!=null) { fun(data); } else { if(data.code==1) { layer.msg(data.msg, {icon: 1, time: 2000}); setTimeout(function(){ location.href=data.url; },2000); } else { layer.msg(data.msg, {icon: 2, time: 2000}); } } },'json'); } var qls_location_url=''; var qls={ "success":function(msg,url,fun1,fun2){ qls_location_url=url; var html=' '; $('#modal-dialog').remove(); $('body').append(html); $('#modal-dialog .modal-dialog').animate({'margin-top':'30px'},400,function(){ setTimeout(function(){ $('#modal-dialog .modal-dialog').animate({'margin-top':'-233px'},400,function(){ $('#modal-dialog').remove(); if(qls_location_url!='') { location.href=qls_location_url; } else if(qls_location_url=='')location.reload(); }) },1300); }); } , "error":function(msg,url,fun1,fun2){ qls_location_url=url!=null?url:''; var html=' '; $('#modal-dialog').remove(); $('body').append(html); $('#modal-dialog .modal-dialog').animate({'margin-top':'30px'},400,function(){ setTimeout(function(){ $('#modal-dialog .modal-dialog').animate({'margin-top':'-233px'},400,function(){ $('#modal-dialog').remove(); if(qls_location_url!='') { location.href=qls_location_url; } }) },1300); }); }, "waring":function(func){//警告 swal({ title: "您确定要执行该操作吗?", text: "数据操作后将无法还原,请谨慎操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "执行", closeOnConfirm: false }, func); }, "prompt":function(title,fun,type,val){ parent.layer.prompt({ title: title, value:val!=null?val:'', formType: type!=null?type:2 //prompt风格,支持1-2 }, fun); }, "confirm":function(title,fun1,fun2){ var html=''; $('#modal-dialog').remove(); $('body').append(html); parent.layer.confirm(title, { btn: ['确认','取消'], //按钮 shade: false //不显示遮罩 }, function(){ if(fun1!=null) fun1(); $('#modal-dialog').remove(); }, function(){ if(fun2!=null)fun2(); $('#modal-dialog').remove(); }); }, "loading":function(){ parent.layer.load(1, { shade: [0.5,'#fff'] //0.1透明度的白色背景 }); }, "msg":function(title,icon){//icon 1成功 2失败 3疑问 4锁定 parent.layer.msg(title, {icon: icon!=null?icon:1}); }, "open":function(title,html,wh){ if(wh==null) { wh=['420px', '240px']; } parent.layer.open({ title:title, type: 1, area: [wh[0], wh[1]], //宽高 skin: 'layui-layer-demo', //样式类名 closeBtn: true, //不显示关闭按钮 shift: 2, shadeClose: true, //开启遮罩关闭 content: html }); }, "poenifrm":function(title,url,wh){ if(wh==null)wh=['80%', '60%']; layer.open({ type: 2, title: title, shadeClose: true, shade: 0.8, area:wh , content: url //iframe的url }); }, "close":function(){ layer.closeAll(); parent.layer.closeAll(); }, /** * 级联 * @param 元素id * @param tabelname 表名 * @param column 关联键名 * @param parentId 上级id * @param filed 查询的字段对象{"name":"","id":""} */ "cascade":function(slecteds,tabelname,column,parentId,filed,val,html,level)//qls.cascade('slecteds','area','parent_id',0,{"name":'area_name',"id":"area_id"},'15,16'); { if(parentId==='')return false; var vals=val!=null?val.split(','):[]; var levels=level!=null?level:0; //if(vals.length<=leves+1)return html; var htmls=html!=null?html:''; var str=JSON.stringify(filed); var htm=''; } htmls+=htm; if(vals.length>levels&&pid!='') { qls.cascade(slecteds,tabelname,column,pid,filed,val,htmls,levels+1); } if(data.data.length>0) { $('#'+slecteds).html(htmls); } },'json'); } }; /** * post 请求 * @param url * @param data * @param func */ function sendajax(url,data,func) { qls.loading(); $.post(url,data,function(datas){ qls.close(); if(func!=null)func(datas); else { if(datas.code==1) { swal(datas.msg, "你执行的操作已成功,数据已更新。", "success"); setTimeout(function(){ location.href=datas.url; },2000); } else { swal(datas.msg, "你执行的操作失败,数据未更新。", "error"); } } },'json') }