pay.page.js
3.27 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
/**
* Created by TaoHuang on 2016/7/18.
*/
var $ = require('yoho-jquery');
var $orderDetail = $('.order-detail'),
$orderDetailCtrl = $('#order-detail-ctrl');
var Dialog = require('../plugins/dialog');
var $payTypeIcon = $('.pay-type-icon'),
$payIconContent = $('.pay-icon-content'),
$goPayBtn = $('#go-pay-btn'),
$payTypeName = $goPayBtn.find('#pay-type-name'),
$payIcon = $payIconContent.find('.pay-icon');
var tpl = '<div class="pay-page-tips">' +
'<h3>请您在新打开的页面完成付款</h3>' +
'<p>付款完成前请不要关闭此窗口</p>' +
'<p>完成付款后请根据您的情况点击下面的按钮</p>' +
'<div><a href="javascript:void(0);" class="pay-over"><span class="btn">已完成付款</span></a>' +
'<span class="btn white close-btn">更换支付方式</span>' +
'</div>' +
'</div>';
var infoDaialog = new Dialog.Dialog({
className: 'pay-info-dialog',
content: tpl,
keep: true
});
// 展开详情/收起详情
$orderDetailCtrl.click(function() {
var $this = $(this);
if ($orderDetail.is(':hidden')) {
// 展开状态
$this.html('收起详情<i class="iconfont up"></i>');
} else {
// 收起状态
$this.html('订单详情<i class="iconfont down"></i>');
}
$orderDetail.slideToggle('slow');
});
$payTypeIcon.click(function() {
var $this = $(this);
if ($this.hasClass('active')) {
return;
}
// 切换选中状态
$payTypeIcon.removeClass('active');
$this.addClass('active');
$payTypeName.text('去' + $this.data('name').replace(/支付$/g, '') + '支付');
});
// 支付按钮 设置默认文字
if ($payIconContent.find('.pay-type-icon.active').length) {
$payTypeName.text('去' + $payIconContent.find('.pay-type-icon.active').data('name').replace(/支付$/g, '') + '支付');
}
// 切换支付方式tabs 委托事件
$('.pay-nav .tabs').click(function(event) {
var $li = $(event.target).closest('li');
if ($li.length <= 0) {
return true;
}
$li.addClass('active').siblings('li').removeClass('active');
$payIcon.eq($li.index()).removeClass('hide').siblings('.pay-icon').addClass('hide');
});
function showDialog() {
infoDaialog.show();
$('.pay-page-tips .btn.close-btn').off().on('click', function() {
infoDaialog.close();
});
}
// 去支付
$goPayBtn.click(function() {
var payType = $('.pay-type-icon.active').data('value');
var order = $(this).data('order');
$.ajax({
type: 'POST',
url: '/shopping/pay/online/go',
async: false,
data: {
code: order,
payType: payType
}
}).then(function(data) {
if (data.code === 200) {
window.open(data.data.href);
showDialog();
} else {
new Dialog.Alert(data.message).show();
}
});
});
// 发送支付确认
$('.pay-info-dialog').on('click', '.pay-over', function() {
var payment = $('.pay-type-icon.active').data('id');
var order = $goPayBtn.data('order');
$.ajax({
type: 'POST',
url: '/shopping/pay/online/sendPayConfirm',
data: {
code: order,
payment: payment
}
}).then(function() {
location.href = '/me/order';
});
});