layui.use(['layer', 'form', 'laypage'], function(){ var form = layui.form; // alert弹窗方法 window.layerAlert = function (type, text, href, width, state,id) { if(width == undefined || width == '') width = 700; if(id) href = href + id; var load = layer.load(2); $.ajax({ type : type, url : href, data : {}, headers: { //'X-CSRF-TOKEN': _token }, success: function(data){ if (data.code !== undefined && !isNaN(data.code) && data.code != 0) { layer.close(load); layer.msg(data.msg, {time: 2000}) } else { layer.open({ type : 1, title : text, shadeClose: true, area : ''+width+'px', //宽高 maxmin : true, move : false, content : data, success : function(layero, index) { layer.close(load); //renderMultiSelect(); form.render(); //重新渲染form //tinymceEditor(); //文本编辑器 //判断弹框内容高度 if($(window).height() - 180 < $('.layui-layer-content .layui-card-body:first').height()) { layer.style(index, { height: $(window).height() - 80, top : 40 }) $('.layui-layer-content').height($(window).height()-123) $('.layui-layer-content').css('max-height','85vh'); $('.eject-layuiBox').height($(window).height()-123) $('.eject-layuiBox').css('max-height','85vh'); } else { $('.layui-layer-content').css('max-height','79vh;padding-bottom: 10px;'); $('.eject-layuiBox').css('max-height','79vh'); } }, end:function(){ if(state == 'edit') $('.layui-edit-btn').remove(); } }); } } }); } //编辑或者添加按钮 $(document).on('click','a.layui-btn',function() { var text = $(this).attr('title'); var href = $(this).data('href'); var width = $(this).data('width'); var state = $(this).data('state'); var id = $(this).data('id'); if(href && text) layerAlert('get', text, href, width, state,id); }); form.on('submit(submitAll)', function(data){ var url = $(data.elem).parents('form').data('action'); formSubmit(url,data.field); return false; }); //表单ajax提交 function formSubmit(url, fromdata) { $.ajax(url, { data : fromdata, dataType: 'json', //服务器返回json格式数据 type : 'post', //HTTP请求类型 timeout : 10000, //超时时间设置为10秒; async : false, headers : { //'X-CSRF-TOKEN': _token }, success:function(data){ if(data.code == 0) { layer.msg('提交成功!') setTimeout(function(){ parent.layer.closeAll(); parent.location.reload() }, 500) } else { layer.msg(data.msg) } }, error:function(xhr,type,errorThrown){ } }); } });