// pages/my/cashier/cashier.js const app=getApp(); Page({ /** * 页面的初始数据 */ data: { order_no:"", pageinfo:{}, price:0, give_price:0, is_online:1, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that=this; this.setData({ 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 { that.setData({ pageinfo: res.message.data, }) } }).catch(function (err) {console.log(err)}) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, pay(){ var price=this.data.price; if(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); } 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; this.setData({ price:e.currentTarget.dataset.price, give_price:e.currentTarget.dataset.gprice, }) }, wxPay(){ var that=this; var no=that.data.price app.api.useApi(app.globalData.baseAppUrl + "api/recharge/charge", { price: 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 { 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: "失败,请重试!", }) setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 1000); console.log(res)} }) } }).catch(function (err) {console.log(err)}) }, back:function(){ wx.redirectTo({ url: '/pages/order/detail/detail?order_no='+this.data.order_no, }) } })