123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // 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,
- })
- }
- })
|