<%@page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false" %>
<%@ page import="com.sino.weixin.oauth.util.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">  
<title>照片上传</title>
<link rel="stylesheet" href="/SinoGYS/weixincss/weui.min.css">
<link rel="stylesheet" href="/SinoGYS/weixincss/jquery-weui.css">
<link rel="stylesheet" href="/SinoGYS/css/newCss/reset.css" />
<link rel="stylesheet" href="/SinoGYS/css/newCss/uploadPhoto.css" />
<script src="/SinoGYS/js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="/SinoGYS/js/jquery-weui.js"></script>
<script src="/SinoGYS/js/ajaxHelper.js" type="text/javascript"></script>
<script src="/SinoGYS/js/json2.js" type="text/javascript"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

 <script type="text/javascript">
        var ohtml=document.documentElement;
        function getWidth(){
            var screenWidth=ohtml.clientWidth;
            if(screenWidth<320){
                ohtml.style.fontSize="13.3333px";
            }else if(screenWidth>1080){
                ohtml.style.fontSize="45px";
            }else{
                ohtml.style.fontSize=screenWidth/(1080/45)+"px";
            }
        }
        getWidth();
        window.onresize=function(){
            getWidth();
        };
    </script>
</head>

<body>
	<form >
		<input type="hidden" id="orderId" name="orderId" value="${param.orderId}">
		<input type="hidden" id="state" name="state" value="${param.state}">
		<input type="hidden" id="image_0" name="image_0" value="">
		<input type="hidden" id="image_1" name="image_1" value="">
		<input type="hidden" id="image_2" name="image_2" value="">
		<input type="hidden" id="image_3" name="image_3" value="">
	</form>
	
	<div class="uploadWrapper">
		<div class="uploadTitle">
			照片最多上传4张
		</div>
		<div class="photoWrapper clearfix">
			<div class="photo">
				
			</div>
			<div class="imgWrapper" id="chooseImage">
					<a href="#"><img src="/SinoGYS/images/newImage/addIcon.png" /></a>
			</div>
		</div>
		
		
		<div class="inputWrapper">
  			<input class="loginFormSubmit loginBtnActive" type="button" value="确       定">
  		</div>
	</div>
</body>

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"> </script>
<script>
$(document).ready(function() {
	checkWeixinApi();
});


function checkWeixinApi(){
	var targetUrl = window.location.href;
	var action = "/SinoGYS/ApiSignatureAction.do?CMD=signature&url="+targetUrl+"&d="+((new Date()).getTime());
	ajaxRequest(action,function(_response){
		var data = _response.responseTEXT;
		if (data!=null){
		     var obj = new Function("return" + data)();
		      wx.config({
			      debug: false,
			      appId: obj.appId,
			      timestamp: obj.timestamp,
			      nonceStr: obj.nonce,
			      signature: obj.signature,
			      jsApiList:[
			        'chooseImage',
			        'uploadImage',
			      ]
		 	 });	  
		} else {
			alert("失败");
		}
	},false);
}

var url=new Array();
function showImage(data,i){
	var imageUrl=null;
    imageUrl = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=<%=Constants.ACCESS_TOKEN  %>&media_id="+data;
    console.log(imageUrl);
    $(".photo").append('<div class="imgWrapper"><img src="'+imageUrl+'"/><input type="hidden" name="img_div" value="'+data+'"></div>');
 } 
 
  
$(".loginBtnActive").click(function(){
	var images=document.getElementsByName("img_div");
	for(var i=0;i<images.length;i++){
		$("#image_"+i).val(images[i].value);
	}
	
	$.ajax({
	        async: true,
	        url:"/SinoGYS/DownLoadImageAction.do?CMD=upload",
	        dataType: "json",
	        type: "POST",
	        data: $("form").serialize(),
	        success: function (jsonObject) {
				if(jsonObject.code==true){
					$.alert("成功上传照片",function(){
						window.history.go(-2);
					});
				}else{
					$.alert("照片上传失败，请重新上传",function(){
						window.history.go(-2);
					});
				}
	        }
	});
});
 
</script>
<script src="/SinoGYS/js/weixin-api-6.1_1.js?d=<%=new Date().getTime() %>"> </script>
</html>