/**
 * create by robot 
 * date Thu Sep 12 16:16:36 CST 2019 
 */ 

$(document).ready(function(){
	//form表单样式
	layui.use(['layer', 'form'], function() {
		var layer = layui.layer,
			form = layui.form;
		form.render();
	});
	//li 切换事件
	$(".nav-tabs>li").click(function() {
		var index = $(".nav-tabs>li").index(this);
		$(this).addClass("active").siblings("li").removeClass("active");
		
	})
	//弹出一个提示层
	$('.fa-save').on('click', function() {
		saveDevice();
	});

	//绑定标签栏事件
	$(document).on('click','.nav-tabs li',function(){

		var action =$(this).data('action');
		 switch (action) {
			case "base"://基本资料
				goBase();
				break;  
			case "functions"://多功能
				goFunctions();
				break;
			case "extends"://扩展    
				goExtends();         
				break;           
		 }
	})

	//加载第一个标签
	$('.nav-tabs li').eq(0).click();
	
});


//跳转基本信息 
function goBase(){
	var url=ctx+'/device/queryDeviceBaseInfo?id='+$('#deviceId').val();
	$('.tab-content').load(url);
	              
}
//跳转多功能输入
function goFunctions(){ 
	var url=ctx+'/device/queryDeviceFunctionsInfo?id='+$('#deviceId').val();
	$('.tab-content').load(url);  
	
}
//跳转到扩展   
function goExtends(){
	
	var url=ctx+'/device/queryDeviceExtendsInfo?id='+$('#deviceId').val();
	$('.tab-content').load(url);          
}  
  

 
//保存
function saveDevice(){
	var id =$("#id").val();
	var name =$("#name").val();
	var deviceLogo =$("#deviceLogo").val();
	var detail=UM.getEditor('detail').getContent().trim();
	var unitPrice =$("#unitPrice").val();
	var venderName =$("#venderName").val();
	var venderModel =$("#venderModel").val();
	var aisleModel =$("#aisleModel").val();
	var introDesc =$("#introDesc").val();
	var seq =$("#seq").val();
	var status =$("#status").val();
	if(StringUtil.isBlank(name)){
		layer.msg('请输入设备名称');
		return;
	}
	if(StringUtil.isBlank(deviceLogo)){
		layer.msg('请上传图片');
		return;
	}
	if(StringUtil.isBlank(detail)){
		layer.msg('请输入设备详情');
		return;
	}
	if(StringUtil.isBlank(venderName)){
		layer.msg('请输入厂家名称');
		return;
	}
	if(StringUtil.isBlank(venderModel)){
		layer.msg('请输入厂家型号');
		return;
	}
	if(StringUtil.isBlank(aisleModel)){
		layer.msg('请输入通道机器型号');
		return;
	}
	if(StringUtil.isBlank(introDesc)){
		layer.msg('请输入简介');
		return;
	}
	if(StringUtil.isNotJustInteger(seq)){
		if(StringUtil.isBlank(seq)){
			layer.msg('请输入排序');
			return;
		}
		layer.msg('请输入正确的排序格式');
		return;
	}
	if(StringUtil.isBlank(status)){
		layer.msg('请选择状态');
		return;
	}
	$(".fa-save").attr("disabled","disabled");
	$('.fa-save').html('正在保存...')
	$.ajax({
		url:ctx+"/device/saveDevice",
		type:"POST",
		dataType:'json',
		data:{
			"id":id,
			"name":name,
			"deviceLogo":deviceLogo,
			"detail":detail,
			"unitPrice":unitPrice,
			"venderName":venderName,
			"venderModel":venderModel,
			"aisleModel":aisleModel,
			"introDesc":introDesc,
			"seq":seq,
			"status":status,
		},
		complete:function(){
			$(".fa-save").removeAttr("disabled");
			$('.fa-save').html('保存')
		},        
		success:function(service){ 
		
			layer.confirm('保存成功,是否前往列表？', {
				  btn: ['确认','取消'] //按钮
				}, function(){
					$('#goback span').trigger('click'); 
				}, function(){         
					layer.closeAll();
			});  
			
		}
	});  
}

function uploadImage2(){
	$.seocooUpload(function(data){
		var url=data.url;
		$('#demo2').attr("src",url);
		$('#deviceLogo').val(url);
	})
}
 

