luck 2 éve
szülő
commit
4bf9bf78b9
2 módosított fájl, 113 hozzáadás és 111 törlés
  1. 111 108
      pages/my/cashier/cashier.js
  2. 2 3
      pages/order/detail/detail.js

+ 111 - 108
pages/my/cashier/cashier.js

@@ -1,54 +1,54 @@
 // pages/my/cashier/cashier.js
-const app=getApp();
+const app = getApp();
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-        order_no:"",
-        pageinfo:{},
-        price:0,
-        give_price:0,
-        is_online:1,
+        order_no: "",
+        pageinfo: {},
+        price: 0,
+        give_price: 0,
+        is_online: 1,
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-        var that=this;
+        var that = this;
         this.setData({
-            order_no:options.order_no,
-            is_online:wx.getStorageSync('is_online')
+            order_no: options.order_no,
+            is_online: wx.getStorageSync('is_online')
         });
         app.api.useApi(app.globalData.baseAppUrl + "api/recharge/order", {
-          order_no: options.order_no,
-      }, "get").then(function (res) {
-          console.log(res)
-          if (res.code != 200) {
-              wx.showLoading({
-                  title: res.message.msg,
-              })
-              setTimeout(function () {
-                  wx.hideLoading({
-                      success: (res) => { },
-                  })
-              }, 1000);
-          } else {
-            var pageinfo=res.message.data
-              that.setData({
-                  pageinfo: pageinfo,
-              })
+            order_no: options.order_no,
+        }, "get").then(function (res) {
+            console.log(res)
+            if (res.code != 200) {
+                wx.showLoading({
+                    title: res.message.msg,
+                })
+                setTimeout(function () {
+                    wx.hideLoading({
+                        success: (res) => { },
+                    })
+                }, 1000);
+            } else {
+                var pageinfo = res.message.data
+                that.setData({
+                    pageinfo: pageinfo,
+                })
 
-              if(pageinfo.total_money<=0 || parseFloat(pageinfo.total_money) - parseFloat(pageinfo.price)<=0){
-          
-                var price=parseFloat(pageinfo.price)-parseFloat(pageinfo.total_money)
-    
-                that.setData({price:price})
+                if (pageinfo.total_money <= 0 || parseFloat(pageinfo.total_money) - parseFloat(pageinfo.price) <= 0) {
+
+                    var price = parseFloat(pageinfo.price) - parseFloat(pageinfo.total_money)
+
+                    that.setData({ price: price })
                 }
-          }
-      }).catch(function (err) {console.log(err)})
+            }
+        }).catch(function (err) { console.log(err) })
     },
 
     /**
@@ -58,100 +58,103 @@ Page({
 
     },
 
-    pay(){
+    pay() {
         let that = this
 
-            if(that.data.price>0){
-                this.wxPay();
-            }else{
-                this.opay();
-            }
-        
-    },
-    opay(){
-      var that=this;
-      var no=that.data.order_no
-      app.api.useApi(app.globalData.baseAppUrl + "api/payment", {
-        order_no: no,
-    }, "post").then(function (res) {
-        console.log(res)
-        if (res.code != 200) {
-            wx.showLoading({
-                title: res.message.msg,
-            })
-            setTimeout(function () {
-                wx.hideLoading({
-                    success: (res) => { },
-                })
-            }, 1000);
+        if (that.data.price > 0) {
+            this.wxPay();
         } else {
-            wx.navigateTo({
-                url: '/pages/order/detail/detail?order_no='+no
-            })
+            this.opay();
         }
-    }).catch(function (err) {console.log(err)})
+
+    },
+    opay(pay_trade_no = "") {
+        var that = this;
+        var no = that.data.order_no
+        app.api.useApi(app.globalData.baseAppUrl + "api/payment", {
+            order_no: no,
+            pay_trade_no: pay_trade_no
+        }, "post").then(function (res) {
+            console.log(res)
+            if (res.code != 200) {
+                wx.showLoading({
+                    title: res.message.msg,
+                })
+                setTimeout(function () {
+                    wx.hideLoading({
+                        success: (res) => { },
+                    })
+                }, 1000);
+            } else {
+                wx.navigateTo({
+                    url: '/pages/order/detail/detail?order_no=' + no
+                })
+            }
+        }).catch(function (err) { console.log(err) })
 
         // wx.switchTab({
         //   url: '/pages/tabber/order/index',
         // })
     },
-    click(e){
-       // this.pageinfo.price=e.currentTarget.dataset.price;
+    click(e) {
+        // this.pageinfo.price=e.currentTarget.dataset.price;
         this.setData({
-            price:e.currentTarget.dataset.price,
-            give_price:e.currentTarget.dataset.gprice,
+            price: e.currentTarget.dataset.price,
+            give_price: e.currentTarget.dataset.gprice,
         })
     },
-    wxPay(){
-        var that=this;
-        var no=that.data.price
+    wxPay() {
+        var that = this;
+        var no = that.data.price
         app.api.useApi(app.globalData.baseAppUrl + "api/recharge/charge", {
             price: no.toFixed(2),
-      }, "post").then(function (res) {
-          console.log(res)
-          if (res.code != 200) {
-              wx.showLoading({
-                  title: res.message.msg,
-              })
-              setTimeout(function () {
-                  wx.hideLoading({
-                      success: (res) => { },
-                  })
-              }, 1000);
-          } else {
-            var paydata=res.message.data
-            wx.requestPayment({
-                timeStamp: paydata.timeStamp,
-                nonceStr: paydata.nonceStr,
-                package: paydata.package,
-                signType: paydata.signType,
-                paySign: paydata.paySign,
-                success (res) { 
-                    console.log(res);
-            if(res.errMsg=="requestPayment:ok"){
-                that.opay();
-            }
-                },
-                fail (res) { 
-                    wx.showLoading({
-                        title: "失败,请重试!",
+        }, "post").then(function (res) {
+            console.log(res)
+            if (res.code != 200) {
+                wx.showLoading({
+                    title: res.message.msg,
+                })
+                setTimeout(function () {
+                    wx.hideLoading({
+                        success: (res) => { },
                     })
-                    setTimeout(function () {
-                        wx.hideLoading({
-                            success: (res) => { },
+                }, 1000);
+            } else {
+                var paydata = res.message.data
+                wx.requestPayment({
+                    timeStamp: paydata.timeStamp,
+                    nonceStr: paydata.nonceStr,
+                    package: paydata.package,
+                    signType: paydata.signType,
+                    paySign: paydata.paySign,
+                    success(res) {
+                        console.log(res);
+                        if (res.errMsg == "requestPayment:ok") {
+
+                            that.opay(paydata.pay_trade_no);
+                        }
+                    },
+                    fail(res) {
+                        wx.showLoading({
+                            title: "失败,请重试!",
                         })
-                    }, 1000);
-                    console.log(res)}
-              })
+                        setTimeout(function () {
+                            wx.hideLoading({
+                                success: (res) => { },
+                            })
+                        }, 1000);
+                        console.log(res)
+                    }
+                })
+
+            }
+        }).catch(function (err) { console.log(err) })
 
-          }
-      }).catch(function (err) {console.log(err)})
-       
     },
- 
-    back:function(){
+
+    back: function () {
         wx.redirectTo({
-          url: '/pages/order/detail/detail?order_no='+this.data.order_no,
+            url: '/pages/order/detail/detail?order_no=' + this.data.order_no,
         })
     }
 })

+ 2 - 3
pages/order/detail/detail.js

@@ -214,11 +214,10 @@ Page({
             if (res.code != 200) {
                 console.log(res.message.msg)
                 wx.showToast({
-                  title: '取消成功',
+                  title: res.message.msg,
                 })
 
-            
-                that.detail(that.data.order_no);
+                // that.detail(that.data.order_no);
         
         
             } else {