pay.js 2.81 KB
/**
 * 支付页面
 */

//切换选项卡
var $ = require('yoho.jquery'),
    $choseTag = $('.mode div'),
    $mode = $('.mode'),
    $showPayImg = $('#show-pay-img'),
    $btnty = $('#btnby'),
    $lightBox = $('.light-box'),
    $choosePay = $('#choosePay').val(),
    $chooseMoid = $('.mode div[id="' + $choosePay + '"]').parent().data('value'),
    $showValue = $choosePay ? $chooseMoid : $('.mode').eq(0).data('value'),
    $payUrl = $('#payUrl').val(),
    $modeData,
    activeTab,
    imgAlt,
    imgSrc,
    orderCode,
    payment;

$.jqtab = function(tabtit, tabcon) {

    $(tabtit + ' li').click(function() {
        activeTab = $(this).find('a').attr('tab');

        $(tabtit + ' li').removeClass('thistab');
        $(this).addClass('thistab');
        $(tabcon).hide();
        $('#' + activeTab).fadeIn();
        return false;
    });
};


$.jqtab('#tabs', '.tab-con');

//选项卡点击
function choosed() {
    if ($choosePay) {
        $('.mode div[id="' + $choosePay + '"]').addClass('choosed-tag').parent().addClass('choose-type');
    } else {
        $mode.eq(0).addClass('choose-type').show();
        $mode.eq(0).find('div').addClass('choosed-tag');
    }
    $btnty.attr('value', '前往' + $('#' + $chooseMoid).attr('alt'));
    $showPayImg.attr('src', $('#' + $chooseMoid).attr('src'));
}

choosed();

$mode.click(function() {
    $modeData = $(this).data();
    $showValue = $modeData.value;
    imgAlt = $('#' + $showValue).attr('alt');
    imgSrc = $('#' + $showValue).attr('src');

    $mode.removeClass('choose-type');
    $(this).addClass('choose-type');
    $choseTag.removeClass('choosed-tag');
    $(this).find('.borer-tag').addClass('choosed-tag');
    $btnty.attr('value', '前往' + imgAlt);
    $showPayImg.attr('src', imgSrc);
    return false;
});


$('.close').click(function() {
    $lightBox.hide();
});

$('.change').click(function() {
    $lightBox.hide();
});

//支付方式选择按钮
function getData(payment, orderCode) {
    $.ajax({
        type: 'get',
        url: '/common/addpaymentinterval',
        dataType: 'json',
        data: {
            orderCode: orderCode,
            payment: payment
        }
    });
}

$('#btnby').click(function() {
    payment = $('.choose-type').attr('data-id');
    orderCode = $('.order-num').text();
    getData(payment, orderCode);
    window.open($payUrl + '?order_code=' + orderCode + '&payment_type=' + $showValue);
    $lightBox.show();
});

//发送支付确认
$('.pay-over').unbind('click').bind('click', function() {
    var _this = this;

    $.post('/shopping/pay/sendPay',
        {
            orderCode: orderCode,
            paymentId: payment
        },
        function() {
            window.location.href = $(_this).data('url');
        }
    );
});