Blame view

public/js/shopping/pay.page.js 4.56 KB
郝肖肖 authored
1
var $ = require('yoho-jquery'),
郝肖肖 authored
2
    dialog = require('../common/dialog');
郝肖肖 authored
3
郝肖肖 authored
4 5 6 7
var payPage = {};
var $btnby = $('input.btnby'),
    $tabConbox = $('ul.tab-conbox'),
    $payWay = $('.pay-way'),
郝肖肖 authored
8
    $lightBox = $('.light-box'),
郝肖肖 authored
9 10
    orderCode = $btnby.data('order'),
    amount = $btnby.data('amount'),
郝肖肖 authored
11
    $formGo = $('.form-go'),
郝肖肖 authored
12
    Alert = dialog.Alert,
郝肖肖 authored
13
    C_ID;
郝肖肖 authored
14
郝肖肖 authored
15
require('../simple-header');
郝肖肖 authored
16 17 18

payPage = {
    init: function() {
郝肖肖 authored
19
        C_ID = window._ChannelVary[window.cookie('_Channel')] || 1;
郝肖肖 authored
20
        this.setEvent();
郝肖肖 authored
21
        this.goPay();
郝肖肖 authored
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    },
    setEvent: function() {
        // tab切 事件
        $('ul.tabs').on('click', function(e) {
            var $li = $(e.target).closest('li');

            if ($li.length <= 0) {
                return false;
            }

            $li.addClass('active').siblings().removeClass('active');
            $tabConbox.find('li').eq($li.index()).removeClass('hide').siblings().addClass('hide');
        });

        // 支付方式选中事件
郝肖肖 authored
37
        $tabConbox.on('click', '.mode', function() {
郝肖肖 authored
38 39 40 41 42
            $(this).closest('.tab-conbox').find('.mode').removeClass('active');
            $(this).addClass('active');
            $payWay.find('img').attr('src', $(this).find('img').attr('src'));
            $btnby.val('前往' + $(this).data('name'));
        });
郝肖肖 authored
43 44 45 46 47 48

        // 支付弹框隐藏
        $lightBox.find('.close,.change').click(function() {
            $lightBox.hide();
        });
郝肖肖 authored
49
        // 单击完成,发送支付确认
郝肖肖 authored
50
        $lightBox.find('.over').on('click', function() {
郝肖肖 authored
51
            $.post('//www.yohobuy.com/shopping/newpay/sendPayConfirm', {
郝肖肖 authored
52 53 54 55 56 57 58 59 60 61 62
                code: orderCode,
                payment: $tabConbox.find('.mode.active').data('id')
            }, function() {
                document.location.href = '//www.yohobuy.com/home/orders';
            });
        });
    },
    goPay: function() {
        var payType, $open;

        $btnby.on('click', function() {
63 64 65 66 67 68 69 70
            var $this = $(this);

            // 防止频繁点击
            if ($this.data('use')) {
                return false;
            }

            $this.data('use', true);
郝肖肖 authored
71 72
            payType = $tabConbox.find('.mode.active').data('value');
郝肖肖 authored
73 74 75 76 77 78 79 80 81 82 83
            // 埋点
            window._yas && window._yas.sendCustomInfo && window._yas.sendCustomInfo({
                op: 'YB_SC_PAYMENT_TOPAY_CLICK',
                param: JSON.stringify({
                    C_ID: C_ID,
                    ORDER_CODE: orderCode,
                    ORDER_AMOUNT: amount,
                    PAY_STYLE: $tabConbox.find('.mode.active').data('id')
                })
            }, true);
郝肖肖 authored
84
            $.ajax({
郝肖肖 authored
85
                url: '//www.yohobuy.com/shopping/newpay/go',
郝肖肖 authored
86 87
                type: 'POST',
                dataType: 'json',
88 89
                async: false,
                timeout: 6000,
郝肖肖 authored
90 91 92 93 94
                data: {
                    code: orderCode,
                    payType: payType
                },
                success: function(d) {
95 96
                    $this.data('use', false);
郝肖肖 authored
97 98 99 100
                    if (d.code !== 200) {
                        return new Alert(d.message).show();
                    }
郝肖肖 authored
101 102 103 104 105 106 107 108 109 110 111
                    d = d.data;

                    if (d.reqType) {
                        $lightBox.show();
                        $formGo.attr('action', d.reqType);
                        $.each(d, function(key, val) {
                            if (key === 'reqType') {
                                return true;
                            }
                            $formGo.append('<input type="text" name="' + key + '" value="' + val + '" />');
                        });
郝肖肖 authored
112 113 114
                        $formGo.submit();
                        setTimeout(function() {
                            $formGo.attr('action', '');
郝肖肖 authored
115
                            $formGo.html('');
郝肖肖 authored
116 117
                        }, 10);
                        return true;
郝肖肖 authored
118 119
                    } else if (!d.href) {
                        return new Alert('订单信息获取失败!').show();
郝肖肖 authored
120 121
                    }
郝肖肖 authored
122 123
                    $lightBox.show();
郝肖肖 authored
124
                    $open = window.open();
郝肖肖 authored
125
                    $open.location = d.href;
126 127 128
                },
                error: function() {
                    $this.data('use', false);
郝肖肖 authored
129 130 131
                }
            });
        });
郝肖肖 authored
132 133 134 135 136
    }
};

$(function() {
    payPage.init();
郝肖肖 authored
137 138 139 140 141 142 143 144 145 146

    // 默认埋点
    window._yas && window._yas.sendCustomInfo && window._yas.sendCustomInfo({
        op: 'YB_SC_PAYMENT',
        param: JSON.stringify({
            C_ID: C_ID,
            ORDER_CODE: orderCode,
            ORDER_AMOUNT: amount
        })
    }, true);
郝肖肖 authored
147
});