wxpay.page.js
2.74 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
var $ = require('yoho-jquery'),
dialog = require('../common/dialog');
var wxPage = {}, inter;
var $wOdetail = $('.w-odetail'),
$wPayment = $('.w-payment'),
$wAddrinfo = $('.w-addrinfo'),
$wPerm = $('.w-p-erm'),
time = $('.js-time').data('time'),
timeInterval,
$timer = $('.js-timer'),
orderCode = $wPayment.data('order');
require('../simple-header');
require('yoho-jquery-qrcode');
wxPage = {
init: function() {
$wPerm.qrcode({
render: 'table', // 显示方式,canvas,image和div
text: $wPerm.data('url'), // 二维码的内容
size: 250
});
this.setEvent();
inter = setInterval(this.checkPayStatus, 3000);
this.setTimer();
timeInterval = setInterval(() => {
this.setTimer();
}, 1000);
},
setEvent: function() {
$wOdetail.on('click', function() {
$wAddrinfo.slideToggle('slow');
if ($(this).find('i').hasClass('up')) {
$(this).html('收起详情<i class="down"></i>');
} else {
$(this).html('订单详情<i class="up"></i>');
}
});
},
checkPayStatus: function() {
$.ajax({
url: '//www.yohobuy.com/shopping/newpay/weixin/state',
dataType: 'json',
type: 'post',
data: {
code: orderCode
},
success: function(d) {
if (d.code === 401) {
clearInterval(inter);
return new dialog.Dialog({
content: d.message,
closeIcon: false,
className: 'alert-dialog',
btns: [{
id: 'alert-sure',
btnClass: ['alert-sure'],
name: '查看我的订单',
cb: function() {
window.location.href = '//www.yohobuy.com/home/orders';
}
}]
}).show();
} else if (d.code === 200) {
clearInterval(inter);
window.location.href = d.data.href;
}
}
});
},
setTimer: function() {
if (time < 0) {
return clearInterval(timeInterval);
}
let hour = Math.floor(time / 3600);
let minus = Math.floor((time % 3600) / 60);
let second = time % 60;
let text = '';
if (hour > 0) {
text += hour + '小时';
}
text += minus + '分' + second + '秒';
$timer.text(text);
time--;
}
};
$(function() {
wxPage.init();
});