<div id="centre" class="layout">
    <div class="centreInner ">
        <div class="mainInner radius5 ">
            <?php require APPPATH . 'views/'.TEMPLATE_NAME.'/payment_common.php';?>
            <div class="belongBox radius5">
                <div class="house_beans_form">
                    <!--2017-10-18 支付宝 微信-->
                    <div class="paytit">
                        <p class="f16 c3 bold">微信支付</p>
                        <div>
                            <input type="hidden" name="out_trade_no" id="out_trade_no" value="<?=$para['transaction_id']?>"/>
                            <span class="f16 c6 bold">支付金额：</span><span class="f18 red bold"><?=$para['price']?></span>
                            <span class="f16 c6 bold">元</span>&nbsp;&nbsp;&nbsp;&nbsp;
                            <span class="f12 red" style="display:none" id="expire_span">
                                二维码已过期，
                                <a class="blue hand" onclick="codeInit()">刷新</a>页面重新获取二维码。
                            </span>
                            <span class="f12" id="valid_span">
                                距离二维码过期还剩<span id="time" class="red">60</span>秒，过期后请刷新页面重新获取二维码。
                            </span>
                        </div>
                    </div>
                    <style>
                        .payewmi{ position: relative}
                        .payrwm{padding:20px 0 50px 0;}
                    </style>
                    <div class="payrwm">
                        <div class="payewmi hand" id="code_valid">
                            <img src="<?=$url?>" width="298" height="298" />
                        </div>
                        <div class="payewmi hand" style="display: none;" id="code_expire" onclick="codeInit()">
                            <img src="<?=STATIC_SOURCE_URL?>/zsb/images/v1.0/payewmn.png"width="298" height="298"  />
                        </div>

                    </div>
                    <!--2017-10-18 支付宝 微信-->
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        setInterval("ajaxstatus()", 3000);
    });

    function ajaxstatus() {
        if ($("#out_trade_no").val() != 0) {
            $.ajax({
                url: "/payment/orderQuery/?out_trade_no=<?=$para['transaction_id']?>",
                type: "GET",
                dataType:"json",
                data: "",
                success: function (data) {
                    if (data.status == 1) { //订单状态为1表示支付成功
                        window.location.href = "/payment/successNew/<?=$para['id']?>"; //页面跳转
                    }
                },
                error: function () {
                    alert("请求订单状态出错");
                }
            });
        }

    }
    var timer =60;
    Countdown();
    function Countdown() {
        if (timer >= 1) {
            timer -= 1;
            $('#time').html(timer);
            setTimeout(function() {
                Countdown();
            }, 1000);
        }else{
            $('#expire_span').show();
            $('#valid_span').hide();
            $('#code_expire').show();
            $('#code_valid').hide();
        }
    }
    function codeInit(){
        $.ajax({
            url: "/payment/refreshWxPayCode/?id=<?=$para['id']?>",
            type: "GET",
            dataType:"json",
            data: "",
            success: function (data) {
                if (data.status == 1) { //订单状态为1表示支付成功
                    $('#code_valid img').attr('src',data.url);
                    timer =60;
                    $('#expire_span').hide();
                    $('#valid_span').show();
                    $('#code_valid').show();
                    $('#code_expire').hide();
                    Countdown();
                }else{
                    alert("数据异常！");
                }
            },
            error: function () {
                alert("请求订单状态出错");
            }
        });
    }
</script>
<?=$page_js?>