/**
 * create by robot 
 * date Tue Sep 10 15:03:55 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() {
		saveMerchantStore();
	});

	//绑定标签栏事件
	$(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+'/merchantStore/queryMerchantStoreBaseInfo?id='+$('#merchantStoreId').val();
	$('.tab-content').load(url);
	              
}
//跳转多功能输入
function goFunctions(){ 
	var url=ctx+'/merchantStore/queryMerchantStoreFunctionsInfo?id='+$('#merchantStoreId').val();
	$('.tab-content').load(url);  
	
}
//跳转到扩展   
function goExtends(){
	var url=ctx+'/merchantStore/queryMerchantStoreExtendsInfo?id='+$('#merchantStoreId').val();
	$('.tab-content').load(url);          
} 
 
//保存
function saveMerchantStore(){
	var isAdmin=$("#isAdmin").val();
	if(isAdmin=='1'){
		var merchantCode=$("#merchantCode option:selected").val();
		if(StringUtil.isBlank(merchantCode)){
			layer.msg('请选择商户');
			return;
		}
	}
	if(isAdmin=='0'){
		var merchantCode=$("#merchantCode").val();
		if(StringUtil.isBlank(merchantCode)){
			layer.msg('您尚未开通商户');
			return;
		}
	}
	
	var storeName=$("#storeName").val();
	if(StringUtil.isBlank(storeName)){
		layer.msg('请输入店铺名称');
		return;
	}
	var address=$("#address").val();
	if(StringUtil.isBlank(address)){
		layer.msg('请输入门店地址');
		return;
	}
	
	var linkPhone=$("#linkPhone").val();
	if(StringUtil.isBlank(linkPhone)){
		layer.msg('请输入联系电话');
		return;
	}
	if(StringUtil.isNotPhone(linkPhone)){
		layer.msg('请输入正确的联系方式');
		return;
	}
	var productDesc=$("#productDesc").val();
	if(StringUtil.isBlank(productDesc)){
		layer.msg('请选择经营类目');
		return;
	}
	var openingTime=$("#openingTime").val();
	if(StringUtil.isBlank(openingTime)){
		layer.msg('请输入营业时间');
		return;
	}
	var storeDesc=$("#storeDesc").val();
	if(StringUtil.isBlank(storeDesc)){
		layer.msg('请输入门店简介');
		return;
	}
	
	var logo=$("#logo").val();
	if(StringUtil.isBlank(logo)){
		layer.msg('请上传门店logo');
		return;
	}
	
	var storeHeadPic=$("#storeHeadPic").val();
	if(StringUtil.isBlank(storeHeadPic)){
		layer.msg('请上传门头照');
		return;
	}
	var cashPic=$("#cashPic").val();
	if(StringUtil.isBlank(cashPic)){
		layer.msg('请上传收银台照');
		return;
	}
	var storeInsidePic=$("#storeInsidePic").val();
	if(StringUtil.isBlank(storeInsidePic)){
		layer.msg('请上传店内环境照');
		return;
	}
	
	var status=$("#status option:selected").val();
	if(StringUtil.isBlank(status)){
		layer.msg('请选择店铺状态');
		return;
	}
	 
	$(".fa-save").attr("disabled","disabled");
	$('.fa-save').html('正在保存...')
	$.ajax({
		url:ctx+"/merchantStore/saveMerchantStore",
		type:"POST",
		dataType:'json',
		data:$("#data_form").serializeArray(),
		complete:function(){
			$(".fa-save").removeAttr("disabled");
			$('.fa-save').html('保存')
		},        
		success:function(service){ 
			layer.confirm('保存成功,是否前往列表？', {
				  btn: ['确认','取消'] //按钮
				}, function(){
					$('#goback span').trigger('click'); 
				}, function(){         
					layer.closeAll();
			});  
			
		}
	});  
}

function uploadImage1(){
	$.seocooUpload(function(data){
		var url=data.url;
		$('#demo1').attr("src",url);
		$('#logo').val(url);
	})
}

function uploadImage2(){
		$.seocooUpload(function(data){
			var url=data.url;
			$('#demo2').attr("src",url);
			$('#storeHeadPic').val(url);
		})
}
function uploadImage3(){
	$.seocooUpload(function(data){
		var url=data.url;
		$('#demo3').attr("src",url);
		$('#cashPic').val(url);
	})
}
function uploadImage4(){
	$.seocooUpload(function(data){
		var url=data.url;
		$('#demo4').attr("src",url);
		$('#storeInsidePic').val(url);
	})
}
 

