<%@ page language="java" pageEncoding="utf-8"%>
<%@ page language="java" import="com.fadu.web.util.Constant" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% 
	String token = (String)session.getAttribute(Constant.Session.TOKEN) ;
	String openid = (String)session.getAttribute(Constant.Session.DWLSD_OPENID);
%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="wap-font-scale" content="no">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <title>多问</title>
	<script src="${contextPath}/static/js/flexible.min.js"></script>
	<link rel="stylesheet" type="text/css" href="${contextPath}/static/weixin/cd/css/sprite.css">
	<link rel="stylesheet" type="text/css" href="${contextPath}/static/weixin/cd/css/common.css">
	<link rel="stylesheet" type="text/css" href="${contextPath}/static/weixin/cd/css/main.css">
</head>
<body>
	<div class="page">
		<header class="top bg-blue text-center fc-white fs-16 ub ub-pj">
			<a href="javascript:history.back(-1);" class="pad-l-30">
				<span class="icon icon-back"></span>
			</a>
			<span>查档服务</span>
			<span class="pad-l-40 pad-r-30"></span>
		</header>
		<div class="pad-lr-25 ub bg-blue fs-12 service-progress">
			<div class="ub-f1 service-progress-item">
				<div class="bg-white service-progress-bar"></div>
				<div class="bg-white fc-white fs-12 text-center service-progress-dotted"></div>
				<p class="fc-white">律师申请</p>
			</div>
			<div class="ub-f1 service-progress-item">
				<div class="bg-white service-progress-bar"></div>
				<div class="bg-white fc-white fs-12 text-center service-progress-dotted"></div>
				<p class="fc-white">平台确认</p>
			</div>
			<div class="ub-f1 service-progress-item active">
				<div class="bg-white service-progress-bar"></div>
				<div class="bg-white fc-white fs-12 text-center service-progress-dotted"></div>
				<p class="fc-white">律师付款</p>
			</div>
			<div class="ub-f1 service-progress-item">
				<div class="bg-white service-progress-bar"></div>
				<div class="bg-white fc-white fs-12 text-center service-progress-dotted"></div>
				<p class="fc-white">进行查档</p>
			</div>
		</div>	
		<a href="#" class="mar-b-25 pad-r-20 bg-white ub ub-ac ub-pj search-top">
			<span class="mar-l-15 br br-orange br-radius5 text-center fc-orange search-state">待付款</span>
			<p class="mar-l-15 pad-lr-5 fs-12 fc-grey ub-f1 text-overflow">${price}元</p>
			<div class="pad-l-5">
				<span class="mar-r-5 fc-xxxlgrey">订单详情</span>
				<span class="icon icon-top icon-turn-right"></span>
			</div>
		</a>
		
		<form id="payForm" action="" method="post">
			<div class="mar-t-35 bg-white pos-relate br-top1">
				<div class="pos-relate br-bottom1">
					<div class="pad-lr-25 pos-relate br-bottom1 ub ub-ac ub-pj service-height">
						<p>
							<span>1.填写收货信息</span>
							<span class="fc-dgrey fs-12">（查询结果材料按以下信息寄送）</span>
						</p>
					</div>
					<div class="bg-white pos-relate list-bottom service-info-form">
						<ul>
							<li class="pad-tb-20 pad-l-25 pos-relate br-bottom1 ub ub-ac"> 
								<lebel class="fc-xlgrey">收货人:</lebel>
								<input type="text" name="rpName" class="fc-xxxlgrey pad-lr-15 ub-f1">
							</li>
							<li class="pad-tb-20 pad-l-25 pos-relate br-bottom1 ub ub-ac"> 
								<lebel class="fc-xlgrey">电话:</lebel>
								<input type="tel" name="rpTel" class="fc-xxxlgrey pad-lr-15 ub-f1">
							</li>
							<li class="pad-tb-20 pad-l-25 pos-relate br-bottom1 ub ub-ac"> 
								<lebel class="fc-xlgrey">收货地址:</lebel>
								<input type="text" name="rpAddress" class="fc-xxxlgrey pad-lr-15 ub-f1">
							</li>
						</ul>
						<input name="orderId" type="hidden" value="${orderId}"/>
					</div>
				</div>
			</div>
			<div class="bg-white">
				<div class="pos-relate br-bottom1">
					<div class="pad-lr-25 ub ub-ac ub-pj service-height">
						<p>
							<span>2.选择付款方式</span>
						</p>
					</div>
					<div class="bg-white pos-relate list-bottom service-info-form">
						<ul>
							<li class="pad-r-20 pad-tb-20 pad-l-25 pos-relate br-top1 ub ub-ac ub-pj">
								<div>
									<span class="icon icon-wechat icon-top1"></span> 
									<span class="fc-xlgrey">微信</span>
								</div>
								<span class="radio-signle icon icon-radio-blue on" data-radio="pay" data-value="1"></span>
							</li>
							<input type="hidden" name="pay" data-type="pay">
						</ul>
					</div>
				</div>
			</div>
			<a href="javascript:void(0)" class="mar-lr-25 bg-blue fc-white fs-16 text-center br-radius5 btn-pay" >付款</a>
		</form>
		<div class="mar-t-35 bg-white pos-relate br-top1 hide">
			<div class="pos-relate br-bottom1">
				<div class="pad-lr-25 ub ub-ac ub-pj service-height">
					<p>
						<span>您的收货信息</span>
					</p>
				</div>
				<div class="bg-white pos-relate list-bottom service-info-form">
					<ul>
						<li class="pad-tb-20 pad-l-25 pos-relate br-top1 ub ub-ac"> 
							<span class="fc-xlgrey">收货人：</span>
							<span></span>
						</li>
						<li class="pad-tb-20 pad-l-25 pos-relate br-top1 ub ub-ac"> 
							<span class="fc-xlgrey">电话：</span>
							<span></span>
						</li>
						<li class="pad-tb-20 pad-l-25 pos-relate br-top1 ub ub-ac"> 
							<span class="fc-xlgrey">收货地址：</span>
							<span></span>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript" src="${contextPath}/static/js/jquery-1.12.0.min.js"></script>
	<script type="text/javascript" src="${contextPath}/static/weixin/cd/js/main.js"></script>
	<script type="text/javascript" src="${contextPath}/static/js/jstorage.js"></script>
	<script type="text/javascript" src="${contextPath}/static/weixin/cd/js/util.js"></script>
		<script type="text/javascript">
		var baseUrl = '<%=com.fadu.app.util.AppConfig.url_duowenapp_b%>';
		var openid = '<%=openid==null?"":openid%>';
		var token = '<%=token==null?"":token%>';
		$(document).ready(function() {			
			$(".search-top").attr("href", '${contextPath}/web/cd/toOrderDetail?orderId=${orderId}&step=0');
			$(".btn-pay").bind("click", submitInfo);
			
			$("[name=rpName]").val(localStorage.getItem('rpName'));
			$("[name=rpTel]").val(localStorage.getItem('rpTel'));
			$("[name=rpAddress]").val(localStorage.getItem('rpAddress'));
			if($("[name=rpName]").val()==""){
				var b105 = {"token":token, "actionCode":"B105"};
				postData(baseUrl + '/B/android', JSON.stringify(b105), b105Succ, postDataDefaultErrorCallback);
			}
		});	
		
		function b105Succ(data){
			//console.log(data);
			if(data && data.success){
				$("[name=rpName]").val(data.realName);
				$("[name=rpTel]").val(data.mobile);
				$("[name=rpAddress]").val(data.address);
			}
		}
		
		function submitInfo(){
			$(".btn-pay").unbind("click", submitInfo);
			var orderId = '${orderId}';
			var rpName = $("[name=rpName]").val();
			var rpTel = $("[name=rpTel]").val();
			var rpAddress = $("[name=rpAddress]").val();
			var payType = $("[name=pay]").val();
			if(rpName==null||rpName==""){
				showMsg('请输入收货人!');
				return false;
			}
			if(rpTel==null||rpTel==""){
				showMsg('请输入电话!');
				return false;
			}			
			if(rpTel.length!=11){
				showMsg('请输入11位手机号码!');
				return false;
			}
			if(rpAddress==null||rpAddress==""){
				showMsg('请输入收货地址!');
				return false;
			}		
			if(payType==null||payType==""){
				payType = 1;
			}
			localStorage.setItem('rpName', rpName);
			localStorage.setItem('rpTel', rpTel);
			localStorage.setItem('rpAddress', rpAddress);
			var B611 = {
					actionCode:'B611',
					token:token,
					openid: openid,
					channel:"JS",
					orderId : orderId,	
					rpName : rpName,	
					rpTel : rpTel,	
					rpAddress : rpAddress,	
					payType : parseInt(payType)
				}	
			//调用微信运支付预处理接口
			postData(baseUrl + '/B/android', JSON.stringify(B611), payWeixinB611, postDataDefaultErrorCallback);
		}
		
		function payWeixinB611(data) {
			if(data){
				if(data.success){
					if (typeof WeixinJSBridge == "undefined") {
						if (document.addEventListener) {
							document.addEventListener('WeixinJSBridgeReady',onBridgeReadyB611, false);
						} else if (document.attachEvent) {
							document.attachEvent('WeixinJSBridgeReady', onBridgeReadyB611);
							document.attachEvent('onWeixinJSBridgeReady', onBridgeReadyB611);
						}
					} else {
						var payInfo = JSON.parse(data.payInfo);
						onBridgeReadyB611(payInfo);
					}
				}else {
					showMsg(data.message);
				}
			}else{
				showMsg("网络异常！");
			}
			$(".btn-pay").bind("click", submitInfo);
		}
		
		function onBridgeReadyB611(payInfo) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', {
				"appId" : payInfo.appId, //公众号名称，由商户传入     
				"timeStamp" : payInfo.timeStamp, //时间戳，自1970年以来的秒数     
				"nonceStr" : payInfo.nonceStr, //随机串     
				"package" : "prepay_id=" + payInfo.prepay_id,
				"signType" : payInfo.signType,
				"paySign" : payInfo.paySign
			//微信签名 
			}, function(res) {
				if (res.err_msg == "get_brand_wcpay_request:ok") {					
					//支付成功
					window.location.href=baseUrl + "/web/cd/toCdIng?orderId=${orderId}&price=${price}";
				} else if (res.err_msg == "get_brand_wcpay_request:cancel") {//cancel 用户取消
					//window.location.href=baseUrl + "/web/cd/toLawyerPay?orderId="+orderId+ "&price=" + price;				
				} else if (res.err_msg == "get_brand_wcpay_request:fail") {//支付失败
					//window.location.href=baseUrl + "/web/cd/toLawyerPay?orderId="+orderId+ "&price=" + price;
				}
			});
		}
	</script>
</body>
</html>