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