pay.page.js 1.18 KB
/**
 * Created by TaoHuang on 2016/7/18.
 */

var $ = require('yoho-jquery');

var $orderDetail = $('.order-detail');

// 展开详情/收起详情
$('#order-detail-ctrl').click(function() {
    var $this = $(this);

    $this.toggleClass('shrink');

    if ($this.hasClass('shrink')) {

        // 收起状态
        $this.find('em').text('展开详情');

    } else {

        // 展开状态
        $this.find('em').text('收起详情');
    }

    $orderDetail.toggleClass('hide');
});

$('.pay-type-icon').click(function() {
    var $this = $(this);

    if ($this.hasClass('active')) {
        return;
    }

    // 切换选中状态
    $this.siblings('.active').removeClass('active');
    $this.addClass('active');

    $('#pay-type-name').text($this.data('name'));
});

// 去支付
$('#go-pay-btn').click(function() {
    var payType = $('.pay-type-icon.active').data('id');
    var order = $(this).data('order');

    $.ajax({
        type: 'POST',
        url: '/shopping/pay/online/go',
        data: {
            code: order,
            method: payType
        }
    }).then(function(data) {
        if (data.code === 200) {
            location.href = data.data.href;
        }
    });
});