pay.js 2.41 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,
    showDiv,
    imgAlt,
    imgSrc,
    orderCode;

$.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();
    showDiv = $modeData.id;
    $showValue = $modeData.value;
    imgAlt = $('#' + $showValue).attr('alt');
    imgSrc = $('#' + $showValue).attr('src');

    $mode.removeClass('choose-type');
    $(this).addClass('choose-type');
    $choseTag.removeClass('choosed-tag');
    $('#' + showDiv).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() {
    var payment = $('.choose-type').attr('data-id');

    orderCode = $('.order-num').text();
    getData(payment, orderCode);
    window.open($payUrl + '?order_code=' + orderCode + '&payment_type=' + $showValue);
    $lightBox.show();
});