Commit db94cbf21622f488ed3596bbfd7b87580f8c3079

Authored by yvan.ni
1 parent d94b5a2e

在支付的时候,避免重复点击

Showing 2 changed files with 30 additions and 3 deletions
utils/pay.js
1   -var t = getApp(), n = t.request;
  1 +var t = getApp(), n = t.request,wx_paying=0;
2 2  
3 3 module.exports = {
4 4 url: "/api/weshop/order/pay/createOrder",
... ... @@ -20,6 +20,10 @@ module.exports = {
20 20 });
21 21 },
22 22 pay: function(t, e, a,sto,type) {
  23 +
  24 + if(wx_paying) return false;
  25 + wx_paying=1;
  26 +
23 27 var i = this;
24 28 var dd = {
25 29 parent_sn: t,
... ... @@ -28,9 +32,11 @@ module.exports = {
28 32 };
29 33 if (type == 1) dd.type = 1;
30 34  
  35 + wx.showLoading();
31 36 n.post(this.url, {
32 37 data: dd,
33 38 success: function(t) {
  39 + wx.hideLoading();
34 40 if(t.data.code==0){
35 41 i.weixinPay(t.data.data, e, a);
36 42 }else{
... ... @@ -39,14 +45,19 @@ module.exports = {
39 45 wx.redirectTo({
40 46 url: "/pages/user/order_list/order_list",
41 47 });
42   - },1000)
  48 + },1000)
  49 + wx_paying=0;
43 50 }
44 51 return false;
45 52 },
46 53 fail: function() {
  54 + wx.hideLoading();
  55 + wx_paying=0;
47 56 "function" == typeof a && a();
48 57 },
49 58 failStatus: function() {
  59 + wx.hideLoading();
  60 + wx_paying=0;
50 61 "function" == typeof a && a();
51 62 }
52 63 });
... ... @@ -64,9 +75,11 @@ module.exports = {
64 75 paySign: n.paySign,
65 76 orderInfo: n.orderInfo, // 需要新增的 订单 信息
66 77 success (n) {
  78 + wx_paying=0;
67 79 t.showSuccess("支付成功!", e);
68 80 },
69 81 fail (n) {
  82 + wx_paying=0;
70 83 if(!n.errMsg ) {
71 84 getApp().showWarning("支付失败");
72 85 "function" == typeof fail && fail();
... ... @@ -87,9 +100,11 @@ module.exports = {
87 100 signType: n.signType,
88 101 paySign: n.paySign,
89 102 success: function (n) {
  103 + wx_paying=0;
90 104 console.log(n), t.showSuccess("支付成功!", e);
91 105 },
92 106 fail: function (n) {
  107 + wx_paying=0;
93 108 console.log(n), "requestPayment:fail" == n.errMsg ? t.showWarning("支付失败") : "requestPayment:fail cancel" == n.errMsg ? t.showWarning("您已取消支付") :
94 109 t.confirmBox("支付失败:" + n.errMsg.substr("requestPayment:fail ".length)),
95 110 "function" == typeof a && a();
... ...
utils/pay2.js
1   -var t = getApp(), n = t.request;
  1 +var t = getApp(), n = t.request,wx_paying=0;
2 2  
3 3 module.exports = {
4 4 url: "/api/weshop/plus/create/plus/order",
5 5 pay: function(dd, succ,fail) {
  6 +
  7 + if(wx_paying) return false;
  8 + wx_paying=1;
  9 +
  10 + wx.showLoading();
6 11 var i = this;
7 12 n.post(this.url, {
8 13 data: dd,
9 14 success: function(t) {
  15 + wx.hideLoading();
10 16 if(t.data.code==0){
11 17 if(t.data.data=="升级成功"){
12 18 "function" == typeof succ && succ(1);
... ... @@ -19,9 +25,13 @@ module.exports = {
19 25 return false;
20 26 },
21 27 fail: function() {
  28 + wx.hideLoading();
  29 + wx_paying=0;
22 30 "function" == typeof fail && fail();
23 31 },
24 32 failStatus: function() {
  33 + wx.hideLoading();
  34 + wx_paying=0;
25 35 "function" == typeof fail && fail();
26 36 }
27 37 });
... ... @@ -35,9 +45,11 @@ module.exports = {
35 45 signType: n.signType,
36 46 paySign: n.paySign,
37 47 success: function(n) {
  48 + wx_paying=0;
38 49 "function" == typeof succ && succ();
39 50 },
40 51 fail: function(n) {
  52 + wx_paying=0;
41 53 "function" == typeof fail && fail();
42 54 }
43 55 });
... ...