$(function(){
	
 	  $(document).ready(function () {
		
		
		  $(".btnUpload").height($(".btnUpload").width()) 
		  	var getspan=$(".imguploadspan").html();
			$(".imguploadspan").append(getspan)
			$(".imguploadspan").append(getspan)
			
			var list=$(".imguploadlist").html();
			$(".imguploadlist").append(list);
			$(".imguploadlist").append(list);
			
			
			
		   var btnUpload=null;
	    $('.btnUpload').click(function () {
			if(bl){
				$('#imagePic').click();
				btnUpload=$(this);
			}else{
				bl=true
			}
	    
	    });
		var bl=true;
		$('.imgdel').click(function () {
			bl=false
			$(this).parent().css("background", "url(/lanhu-bootstrap/assets/img/img_add.png) no-repeat center")
			$(this).parent().css("border", '0')
			$(this).parent().css("background-size", "100% 100%")
			
			$(this).hide()
			$(this).parent().removeAttr("disabled")
			
			$(this).parent().find(".imginput").val("")
			
		});
		
	    $("#imagePic").on("change", function (e) {
			
	      var file = e.target.files[0]; //获取图片资源
	      var fileTypes = ["bmp", "jpg", "png", "jpeg"];
	      var bTypeMatch = false
	      for (var i = 0; i < fileTypes.length; i++) {
	        var start = file.name.lastIndexOf(".");
	        var fileType = file.name.substring(start + 1);
	        if (fileType.toLowerCase() == fileTypes[i]) {
	          bTypeMatch = true;
	          break;
	        }
	      }
	      if (bTypeMatch) {
	        if (file.size <= 1024 * 1024 * 10) {
	          var reader = new FileReader();
	          reader.readAsDataURL(file); // 读取文件
	          // 渲染文件
	          reader.onload = function (arg) {
				 
	            $(btnUpload).css("background", "url("+arg.target.result+")   no-repeat center")
				$(btnUpload).css("background-size", "100% 100%")
				
				$(btnUpload).css("border", '1px solid #b8b9ba')
				$(btnUpload).css("border-radius",'10px')
				$(btnUpload).attr("disabled","disabled")
				$(btnUpload).find(".imgdel").show()
				$(btnUpload).find(".imginput").val(arg.target.result)
				$("#imagePic").val("")
	          }
	        } else {
				jpalert($(".head_10M").val(),null,"alert");
	     
 	       	$("#imagePic").val("")
	          // btnUploadText = '上传'
	          // $("#uploadButton").text(btnUploadText)
	          return false;
	        }
	      } else {
	       
			jpalert($(".head_jpgpng").val(),null,"alert");
			
			 	$("#imagePic").val("")
	        // btnUploadText = '上传'
	        // $("#uploadButton").text(btnUploadText)
	        return false;
	      }
	    });
	  })
	//---------初始化数据部分-----------
	var  contact_number_list=["+86","+87","+88"]
	var  location=[{
		icon:"🇨🇳",
		name:"China"
	},{
		icon:"🇺🇸",
		name:"USA"
	},{
		icon:"🇪🇸",
		name:"Spain"
	}
	]
	
	var province=["aaa","bbb","ccc"]
	var city=["aaa1","bbb2","ccc3"]
	//---------初始化数据部分end-----------
	//页面初始化
	contact_number_list.forEach(item=>{
		var li=$("<option>"+item+"</option>")
		$(".showqulist").append(li)
	})
	location.forEach(item=>{
		var li=$("<option>"+item.icon+' '+item.name+"</li>")
		$(".showlistLocation1").append(li)
	})
	province.forEach(item=>{
		//var li=$("<li class='contact_location2_li' txt="+item+"><a >"+item+"</a></li>")
		var li=$("<option>"+item+"</option>")
		$(".showlistLocation2").append(li)
	})
	city.forEach(item=>{
		//var li=$("<li class='contact_location3_li' txt="+item+"><a >"+item+"</a></li>")
		var li=$("<option>"+item+"</option>")
		$(".showlistLocation3").append(li)
	})
	
		$.validator.setDefaults({
		    submitHandler: function() {
				var bl=true;
				$(".imginput").each(function(){
					if($(this).val()!=''){
						bl=false;
						return
					}
				});
				
				var success = $(".head_success").val();
				var warning = $(".head_warning").val();
				var success1 = $(".signin_success").val();
				var warning1 = $(".signin_warning").val()
				
				
		       if(bl){
					zeroModal.alert({
						unique: '1',
						opacity: 0.8,
						content: warning,
						contentDetail: warning1,
						width: '300px',
						height: '260px',
						cancel:true,
						ok: false,
						onClosed: function() {
							; //location.href='../signin/signin.html'
						},
						onComplete: function(evn) {
							console.log('onComplete')
							setTimeout(function() {
					
								zeroModal.close('1');
							}, 3000);
						}
					})
		       }else{
				  zeroModal.success({
				  	unique: '1',
				  	opacity: 0.8,
				  	content: success,
				  	contentDetail: success1,
				  	width: '300px',
				  	height: '280px',
				  	//okTitle: headcommon2,
				    ok:false,
				  	okFn: function() {
				  
				  		window.location.href = '../lanhu/index.html'
				  	},
				  	onClosed: function() {
				  		; //location.href='../signin/signin.html'
				  	},
				  	onComplete: function(evn) {
				  		//submitCompany()
				  		console.log('onComplete')
				  		setTimeout(function(){
				  		window.location.href = '../lanhu/index.html'
				  			zeroModal.close('1');
				  		},3000);
				  	}
				  })
			   }
		    }
		});
		$("#form").validate()
	
		
	//页面初始化end
})