pay.page.js
4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var $ = require('yoho-jquery'),
dialog = require('../common/dialog');
var payPage = {};
var $btnby = $('input.btnby'),
$tabConbox = $('ul.tab-conbox'),
$payWay = $('.pay-way'),
$lightBox = $('.light-box'),
orderCode = $btnby.data('order'),
amount = $btnby.data('amount'),
$formGo = $('.form-go'),
Alert = dialog.Alert,
C_ID;
require('../simple-header');
payPage = {
init: function() {
C_ID = window._ChannelVary[window.cookie('_Channel')] || 1;
this.setEvent();
this.goPay();
},
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');
});
// 支付方式选中事件
$tabConbox.on('click', '.mode', function() {
$(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'));
});
// 支付弹框隐藏
$lightBox.find('.close,.change').click(function() {
$lightBox.hide();
});
// 单击完成,发送支付确认
$lightBox.find('.over').on('click', function() {
$.post('//www.yohobuy.com/shopping/newpay/sendPayConfirm', {
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() {
var $this = $(this);
// 防止频繁点击
if ($this.data('use')) {
return false;
}
$this.data('use', true);
payType = $tabConbox.find('.mode.active').data('value');
// 埋点
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);
$.ajax({
url: '//www.yohobuy.com/shopping/newpay/go',
type: 'POST',
dataType: 'json',
async: false,
timeout: 6000,
data: {
code: orderCode,
payType: payType
},
success: function(d) {
$this.data('use', false);
if (d.code !== 200) {
return new Alert(d.message).show();
}
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 + '" />');
});
$formGo.submit();
setTimeout(function() {
$formGo.attr('action', '');
$formGo.html('');
}, 10);
return true;
} else if (!d.href) {
return new Alert('订单信息获取失败!').show();
}
$lightBox.show();
$open = window.open();
$open.location = d.href;
},
error: function() {
$this.data('use', false);
}
});
});
}
};
$(function() {
payPage.init();
// 默认埋点
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);
});