layui本页面弹框、表格写法

var src_,departmentDate=[],groupDate=[],terminalStateDate=[],devTypeDate=[],form,laydate,layer,upload,judge=true;
$(function(){
	layui.use(["element","form","laydate","layer","upload"],function(){//用了layui表单,必须引用表单插件form,时间选择器同理
		element=layui.element,form = layui.form,laydate=layui.laydate,layer=layui.layer,upload=layui.upload;
		//右边内容容器添加
		ajax({
			url:path+"/energyMonitor/Equipment/getInfo",
			func:function(data){
				departmentDate=data.department;
				groupDate=data.Group;
				devTypeDate=data.dev_type;  
				terminalStateDate=data.TerminalState;
			}
		})
		form.render();
		//右边内容容器添加
		getData();
	});
});
function getData(){
	var form_=form,laydate_=laydate,layer_=layer,upload_=upload;
	var elem={
		"equipmentName":$("#sbmc").val()
	};
	fillTable(form_,laydate_,layer_,upload_,elem);
}
function fillTable(form,laydate,layer,upload,data){
	$("#table1").datagrid({
		url:path+"/energyMonitor/getAllEquipment",
	    columns:[[ 
			{field : "id",align : "center",align : "center",title : "id",checkbox:true},
		    {field : "terminal_ormeterid",align : "center",width:10,title : "资产编码"},
			{field : "equipment_name",align:"center",width:20,title : "资产名称"}, 
			{field : "terminal_no",align : "center",title : "资产标识"},
			{field:"department_id",align : "center",title:"所属部门",width:10,
	    		formatter:function(value,rowData,index){
	    			for(var i=0;i"+terminalStateDate[i].text+"");
                    $("#terminal_state").append(option);
                    form.render("select");
                }
            	$("#dev_type").empty();
            	for(var i=0;i"+devTypeDate[i].text+"");
                    $("#dev_type").append(option);
                    form.render("select");
                }
            	$("#group_id").empty();
            	for(var i=0;i"+groupDate[i].field_name+"");
                    $("#group_id").append(option);
                    form.render("select");
                }
            	/*for(var i=0;i"+terminalStateDate[i].text+"");
                    $("#mp_id").append(option);
                    form.render("select");
                }*/
            	$("#department_id").empty();
            	for(var i=0;i"+departmentDate[i].text+"");
                    $("#department_id").append(option);
                    form.render("select");
                }
            	if(judge){
            		judge=false;
            	}else{
            		uploadoption.config.auto=false;
                	upload.render(uploadoption);
            	}
            	var uploadoption=upload.render({//图片选择
            	    elem: '#file',
            	    auto:false,
            	    choose: function(obj){//预读本地文件示例,不支持ie8
            	    	obj.preview(function(index, file, result){
            	    		$('#uploadimg').attr('src', result); //图片链接(base64)
            	    		src_=result;
            	    	});
            	    }
            	});
            	$("#submit").unbind("click");
				$("#submit").on("click",function(){
                	var elem=$("#addwindow").serializeObject();
                	elem["url"]=src_;
                	if(elem.terminal_ormeterid == "" || elem.equipment_name == "" || elem.working_hours == ""){
                		return;
                	}
                	ajax({
                		url:path+"/energyMonitor/Equipment/save",
                		data:elem,
                		func:function(data){
                			msg({
                				layer:layer,
                				title:data.msg
                			});
                			if(data.success){
                				$("#table1").datagrid("reload");//重新加载数据但留在当前页
                			}
                		}
                	})
                	$('#uploadimg').removeAttr('src');
                    layer.closeAll();//关闭弹窗
                	$("#topLuck",parent.document).hide();
                	$("#bottomLuck",parent.document).hide();
                	return false;
                });
				$('#cancel').unbind();
            	$('#cancel').click(function(){//取消
            		$('#uploadimg').removeAttr('src'); 
            		$("#reset").click();
            		$("#topLuck",parent.document).hide();
            		$("#bottomLuck",parent.document).hide();
            		layer.closeAll();//关闭弹窗
            	});
            }
		})
	});
	$("#edit").unbind("click");
	$("#edit").on("click",function(){
		if(!$("#table1").datagrid("getSelected")){
			msg({
				layer:layer,
				title:"请选择要编辑的信息"
			});
			return;
		}else{
			var tbSelect=$("#table1").datagrid("getSelected");
			layerr({
				title:"编辑资产信息",
				content:$('#addwindow'),
                area:["700px","690px"],
//                btn:["保存","取消"],
                offset:($(window).height()*1-690)*0.5-$("#topLuck",parent.document).height()/2+$("#bottomLuck",parent.document).height()/2+"px",
                success:function(){
                	$("#terminal_ormeterid").attr("disabled","");
                	$("#terminal_ormeterid").css("background","#ccc");
                	$("#terminal_state").empty();
                	for(var i=0;i"+terminalStateDate[i].text+"");
                        $("#terminal_state").append(option);
                        form.render("select");
                    }
                	$("#dev_type").empty();
                	for(var i=0;i"+devTypeDate[i].text+"");
                        $("#dev_type").append(option);
                        form.render("select");
                    }
                	$("#group_id").empty();
                	for(var i=0;i"+groupDate[i].field_name+"");
                        $("#group_id").append(option);
                        form.render("select");
                    }
                	/*for(var i=0;i"+terminalStateDate[i].text+"");
                        $("#mp_id").append(option);
                        form.render("select");
                    }*/
                	$("#department_id").empty();
                	for(var i=0;i"+departmentDate[i].text+"");
                        $("#department_id").append(option);
                        form.render("select");
                    }
                	var start=laydate.render({
                		elem:"#operation_date",
                		max:s2,
                		done:function(value,dates,endDate){
                			end.config.min={
            					year:dates.year,
            		            month:dates.month-1,
            		            date:dates.date
                			}
                		}
                	});
                	var end=laydate.render({
                		elem:"#fade_date",
                		max:s2,
                		done:function(value,dates,endDate){
                			start.config.max={
            					year:dates.year,
            		            month:dates.month-1,
            		            date:dates.date
                			}
                		}
                	});
                	laydate.render({elem:"#product_date",max:s2});
                	laydate.render({elem:"#install_time",max:s2});
                	$("input[name='terminal_ormeterid']").val(tbSelect.terminal_ormeterid);
    				$("#equipment_name").val(tbSelect.equipment_name);
    				$("#terminal_state").val(tbSelect.terminal_state);
    				$("#dev_type").val(tbSelect.dev_type);
    				$("input[name='operation_date']").val(tbSelect.operation_date);
    				$("input[name='fade_date']").val(tbSelect.fade_date);
    				$("input[name='asset_no']").val(tbSelect.asset_no);
    				$("input[name='specif_type']").val(tbSelect.specif_type);
    				$("#group_id").val(tbSelect.group_id);
    				$("#mp_id").val(tbSelect.mp_id);
    				$("input[name='terminal_no']").val(tbSelect.terminal_no);
    				$("#department_id").val(tbSelect.department_id);
    				$("#working_hours").val(tbSelect.working_hours);
    				$("input[name='product_date']").val(tbSelect.product_date);
    				$("#purch_price").val(tbSelect.purch_price);
    				$("input[name='acc_terminal']").val(tbSelect.acc_terminal);
    				$("input[name='install_time']").val(tbSelect.install_time);
    				$("input[name='ter_addr']").val(tbSelect.ter_addr);
    				$("input[name='ter_manufacturer']").val(tbSelect.ter_manufacturer);
    				$('#uploadimg').attr('src',tbSelect.url); //图片链接(base64)
    				$("#submit").unbind("click");
    				$("#submit").on("click",function(){//保存
                    	var edit1=$("#addwindow").serializeObject();
                    	edit1["id"]=tbSelect.id;
                    	edit1["url"]=tbSelect.url;
                    	if(edit1.terminal_ormeterid == "" && edit1.equipment_name == "" && edit1.working_hours == ""){
                    		return;
                    	}
                    	ajax({
                    		url:path+"/energyMonitor/Equipment/edit",
                    		data:edit1,
                    		func:function(data){
                    			msg({
                    				layer:layer,
                    				title:data.msg
                    			});
                    			if(data.success){
                    				$("#table1").datagrid("reload");//重新加载数据但留在当前页
                    			}
                    		}
                    	})
                        layer.closeAll();//关闭弹窗
                    	$("#topLuck",parent.document).hide();
                    	$("#bottomLuck",parent.document).hide();
                    	$('#uploadimg').removeAttr('src'); 
                    	return false;
                    });
    				$('#cancel').unbind();
    				$('#cancel').click(function(){//取消
                		$("#reset").click();
                		$("#topLuck",parent.document).hide();
                		$("#bottomLuck",parent.document).hide();
                		$('#uploadimg').removeAttr('src'); 
                		layer.closeAll();//关闭弹窗
                	});
                }
			})
		}
	});
	$("#remove").unbind("click");
	$("#remove").on("click",function(){
		if($("#table1").datagrid("getChecked").length==0){
			msg({
				layer:layer,
				title:"请选择要删除的信息"
			});
			return;
		}else{
			var remove1={"ids[]":[]}
			var len=$("#table1").datagrid("getChecked").length;
			for(var i=0;i

 

你可能感兴趣的:(layui,easyui)