00017-layui 对话框 layer.open 点击保存,按钮失效,保存完后,再恢复
原创认真的coder2020-05-30 22:28:43©著作权
var dialog = layer.open({
type: 2
,title: '客户订单'
,content: 'ordersForm.jsp'
,maxmin: true
,area: layui.setter.area
,btn: ['保存', '取消']
,btnAlign: 'c'
,yes: function(index, layero){
var iframeWindow = window['layui-layer-iframe'+ index]
,submit = layero.find('iframe').contents().find("#ordersForm-submit");
iframeWindow.layui.form.on('submit(ordersForm-submit)', function(data){
var btn = $("a.layui-layer-btn0");
if(btn.hasClass("layui-btn-disabled")){
return;
}
btn.addClass("layui-btn-disabled");
var field = data.field;
field.id = rec.id;
var orderServiceList = window.formData.orderServiceList;
if(!orderServiceList || orderServiceList.length==0){
btn.removeClass("layui-btn-disabled");
return layer.msg('请添加合同事项');
}
field = $.extend(field,{orderServiceJson:JSON.stringify(orderServiceList)})
var orderAttachmentList = window.formData.orderAttachmentList;
if(!orderAttachmentList|| orderAttachmentList.length==0){
btn.removeClass("layui-btn-disabled");
return layer.msg('请上传合同附件');
}
field = $.extend(field,{orderAttachmentJson:JSON.stringify(orderAttachmentList)})
field.status = 1;
var rtn = admin.syncReq(ctx+"/order/orders/modify",field);
console.log("field",field);
if(rtn && rtn.code==0){
layer.msg('操作成功');
active.reload();
form.render();
btn.removeClass("layui-btn-disabled");
layer.close(index);
}else{
layer.msg('操作失败');
btn.removeClass("layui-btn-disabled");
}
});
submit.trigger('click');
}
});
关键代码:一开始直接添加禁用样式
var btn = $("a.layui-layer-btn0");
if(btn.hasClass("layui-btn-disabled")){
return;
}
btn.addClass("layui-btn-disabled");
操作完后,恢复:
btn.removeClass("layui-btn-disabled");
标签:layer,对话框,layui,保存,disabled,field,var,btn
From: https://www.cnblogs.com/webSnow/p/16873096.html