wxpay.page.js
2.12 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
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'),
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);
},
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;
}
}
});
}
};
$(function() {
wxPage.init();
});