<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<!DOCTYPE html>
<html>
<jsp:include page="../../common.jsp" />
<style type="text/css">
    .weui-cell{
        justify-content: space-between;
    }

    .middle-inner {
        display: table-cell;
        vertical-align: middle;
        text-align: center;
    }
    .backdrop {
        position: fixed;
        z-index: 998;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        background-color: rgba(0,0,0,.1);
    }
</style>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>去充值</title>
</head>
<body>
        <div id='loading' class="backdrop" style="display: none; padding-top: 70%; text-align: center;">
            <div>
                <img src="${resourcePath}/images/loading-2.gif" alt="loading" />
            </div>
            <div style="font-family:'Microsoft YaHei';color:#000000;font-size: 1rem;">支付中...</div>
            <!--自己放loding图片-->
        </div>
        <div class="page-title tcenter h40 bluebg white">
            <span>去充值</span>
            <a href="${ctx }/vip/myVIPCard?storeId=${sessionScope.sessionMerchantMenber.storeId}&phone=${sessionScope.sessionMerchantMenber.phone}" class="white f21 h40 left0 top0 positiona">
                <span class="dblock w40 h40 icon icon-59 white f22"></span>
            </a>
        </div>
        <div class="weui-cells weui-cells_form bdb5">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">当前余额:</label></div>
                <div class="weui-cell__bd tright f-red">
                    ¥<fmt:formatNumber type="number" value="${merchantMenber.usableRechargeFee + merchantMenber.usableGiveFee }" pattern="0.00" maxFractionDigits="2"/>
                </div>
            </div>
        </div>
        <div class="weui-cells weui-cells_form bdbe">
            <div class="weui-cell weui-cell_warn">
                <div class="weui-cell__hd"><label for="" class="weui-label f-black f22">¥</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input tright" type="text" id="rechargeMoney"   placeholder="请输入充值金额">
                </div>
            </div>
        </div>
        <div class="weui-cells weui-cells_form bdbe pb20">
            <div class="tcenter clearfix payTab">
                <c:forEach items="${activityRechargeList }" var="activityRecharge">
                    <div class="f16 fl tcenter pt20 wp33">
                        <a href="javascript:void(0);" class="dblock radius5 pt10 pb10 ml10 mr10 option">
                            <div class="middle-inner">${activityRecharge.rechargeMoney}元<br/>送${activityRecharge.giveMoney}元</div>
                        </a>
                    </div>
                </c:forEach>
                <div class="f16 fl tcenter pt20 wp33">
                    <a href="javascript:void(0);" class="dblock radius5 pt10 pb10 ml10 mr10 option">
                        <div class="middle-inner">50元</div>
                    </a>
                </div>
                <div class="f16 fl tcenter pt20 wp33">
                    <a href="javascript:void(0);" class="dblock radius5 pt10 pb10 ml10 mr10 option">
                        <div class="middle-inner">100元</div>
                    </a>
                </div>
                <div class="f16 fl tcenter pt20 wp33">
                    <a href="javascript:void(0);" class="dblock radius5 pt10 pb10 ml10 mr10 option">
                        <div class="middle-inner">150元</div>
                    </a>
                </div>
                <div class="f16 fl tcenter pt20 wp33">
                    <a href="javascript:void(0);" class="dblock radius5 pt10 pb10 ml10 mr10 option">
                        <div class="middle-inner">200元</div>
                    </a>
                </div>
                <div class="f16 fl tcenter pt20 wp33">
                    <a href="javascript:void(0);" class="dblock radius5 pt10 pb10 ml10 mr10 option">
                        <div class="middle-inner">500元</div>
                    </a>
                </div>
            </div>
        </div>
        <div class="weui-cells weui-cells_form bdbe">
            <div class="weui-cell weui-cell_warn">
                <div class="weui-cell__hd"><span class="icon icon-14 f22 vm f-green"></span><span class="f-black vm f14 ml10">微信充值</span></div>
                <div class="weui-cells weui-cells_checkbox">
                    <label class="weui-cell weui-check__label" style="padding:0;">
                        <div class="weui-cell__hd">
                            <input type="checkbox" class="weui-check" name="checkbox1" checked="checked">
                            <i class="weui-icon-checked"></i>
                        </div>
                    </label>
                </div>
            </div>
        </div>
        <div class="btn mt60 ml20 mr20">
            <a href="javascript:wechatPay()" class="weui-btn weui-btn_primary radius10 f14 pt15 pb15">去充值</a>
        </div>
 <script>
     $(function(){
         $(".payTab>div").click(function(){
             $(this).addClass("current").siblings("div").removeClass("current");
             var a=$(".current a>div").text();
             var money=a.split('元');
             var rechargeMoney=money[0];
             $("#rechargeMoney").val(rechargeMoney);
         })

         var maxHeight = 0;
         $(".option").each(function() {
            var height = $(this).height();
            maxHeight = Math.max(maxHeight, height);
         });

         $(".option").height(maxHeight);

         $(".option>div").height(maxHeight);
         $(".option>div").width($(".option").width());

         // $(".option").css('line-height', maxHeight);
     })
    function wechatPay(){
        var rechargeMoney=$("#rechargeMoney").val();
        if(StringUtil.isNotTwo(rechargeMoney)){
            if(StringUtil.isBlank(rechargeMoney)){
            alert("请输入金额");
            return;
            }
            alert('请输入正确的金额格式(正整数或小数)');
            return;
        }
        if(StringUtil.isNotBlank(rechargeMoney)){
            if(rechargeMoney<0.01){
                alert('充值金额必须大于0.01');
                return;
            }
        }
        $('#loading').css('display','block');
        $.ajax({
            url:ctx+"/vip/wechatPay",
            type:"POST",
            dataType:'json',
            data:{
            	"rechargeMoney":rechargeMoney,
            },
            success:function(res){
                $('#loading').css('display','none');
                var rdata = res.data;
                if(res.code=="1"){
                    WeixinJSBridge.invoke('getBrandWCPayRequest', {
                        // 商品名称
                        "appId":rdata.appId,
                        "timeStamp":rdata.timeStamp,
                        "nonceStr":rdata.nonceStr,
                        "package":rdata.packageMsg,
                        "signType":rdata.signType,
                        "paySign":rdata.paySgin,
                    }, function(res) {
                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                            window.location = ctx +'/vip/rechargeSuccess';
                        } else {
                        	 window.location = ctx +'/vip/rechargeFail';
                        }
                    })
                }else if(res.code=="2"){
                    if(res.aisleSwitch == "1"){
                        window.location=res.jspay_url;
                    }else if(res.aisleSwitch == "2"){
                        WeixinJSBridge.invoke('getBrandWCPayRequest', {
                            // 商品名称
                            "appId" : rdata.payAppId,
                            "timeStamp" : rdata.payTimeStamp,
                            "nonceStr" : rdata.paynonceStr,
                            "package" : rdata.payPackage,
                            "signType" : rdata.paySignType,
                            "paySign" : rdata.paySign,
                        }, function(res) {
                            if (res.err_msg == "get_brand_wcpay_request:ok") {
                                //成功之后跳转地址
                                window.location = ctx +'/vip/rechargeSuccess';
                            } else {
                                window.location = ctx +'/vip/rechargeFail';
                            }
                        })
                    }
                }else{
                    $.toast(res.msg,"text");
                }
            }
        });  
    }
 </script>
    </body>

</html>