// Generated by CoffeeScript 1.8.0
function fileUpload(){
	 $(".toast").show();
}
(function() {
	
  $(function() {
    $(".toast").hide();
    $("#text").html("上传凭证");
    
    var flag=GetQueryString("flag");
    if(flag==1){
    	 $("#text").html("上传投资人签署页");
    	
    }
    if(flag==2){
    	 $("#text").html("上传打款凭证");
    }
    if(flag==3){
    	 $("#text").html("上传投资人身份证正面");
    }
    if(flag==4){
    	 $("#text").html("上传投资人身份证反面");
    }
    if(flag==5){
    	 $("#text").html("上传投资人银行卡正面");
    }
    var orderId=localStorage.getItem("orderId");
    var flag=GetQueryString("flag");
    $("#img").attr("onclick","location.href='./certificate.html?id="+orderId+"'");
    var orginImg = null;
    Ajax({
    	url:baseUrl+"/api/order/find_certificate.do",
        data:{
        	orderId:orderId,
        	reserveId:flag
        	},
        success:function(data){
        	if(data.status==200){
        		var atta=data.data.atta;
        		orginImg = atta.uri;
        		//查看原图
        	    if (orginImg != null && orginImg.length > 10) {
        		    $("#orginImg").on("tap",function(){
        		    	return location.href="./previewCertificate.html?src="+orginImg;
        		    });
        		    $("#orginImg").show();
        	    } else {
        	    	$("#orginImg").hide();
        	    }
        	}
        
        }
    });
    
	$(".head,.card").click(function() {
	 
	  $("#camera").click();
    });
	
	 
    $("#camera").localResizeIMG({
      width: 640,
      quality: 0.8,
      success: function(res) {
    	 $(".toast").hide();
        var img;
        img = new Image();
        img.src = res.base64;
        res.clearBase64;
        $(".head")[0].src = res.base64;
        $("[name='imgBase64']")[0].value = res.base64;
        if ($(".head").length > 0) {
          $(".head").css({
            "background-image": "url(" + res.base64 + ")"
          }).addClass("radius");
        }
        return $(".card").css({
          "background-image": "url(" + res.base64 + ")"
        });
      },
    });
    
    
    $("#photo").on("click", function() {
    	tipTpl.loading='<div class="am-toast-text loading"> <span class="am-icon-loading"></span> <span id="loading">上传中</span> </div>';
    	if(!isNotNull($("[name='imgBase64']")[0],"照片")){
    		return;
    	}
    	var orderId=localStorage.getItem("orderId");
    	var flag=GetQueryString("flag");
    	if(orderId!=null&&orderId!="null"){
    		var img=$("#card").val();
    		Ajax({
                url:baseUrl+"/api/order/add_certificate.do",
                data:{
                	imgBase64:img,
                	flag:flag,
                	orderId:orderId
                 },
                callback: function(res) {
                	if(res.status==200){
                		toast.success({msg:"上传成功"});
                		setTimeout(function(){
                			localStorage.clear();
        	                return location.href ="./../product/certificate.html?id="+orderId;
                		},1000);
                	}else{
                		wrongMsg(res.message);
                	}
                }
              });       
    	}else{
    		return history.back();
    	}
    	    
     });
    
  });

}).call(this);
