cashier.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // pages/my/cashier/cashier.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. order_no:"",
  9. pageinfo:{},
  10. price:0,
  11. give_price:0,
  12. is_online:1,
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. var that=this;
  19. this.setData({
  20. order_no:options.order_no,
  21. is_online:wx.getStorageSync('is_online')
  22. });
  23. app.api.useApi(app.globalData.baseAppUrl + "api/recharge/order", {
  24. order_no: options.order_no,
  25. }, "get").then(function (res) {
  26. console.log(res)
  27. if (res.code != 200) {
  28. wx.showLoading({
  29. title: res.message.msg,
  30. })
  31. setTimeout(function () {
  32. wx.hideLoading({
  33. success: (res) => { },
  34. })
  35. }, 1000);
  36. } else {
  37. that.setData({
  38. pageinfo: res.message.data,
  39. })
  40. }
  41. }).catch(function (err) {console.log(err)})
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady: function () {
  47. },
  48. pay(){
  49. var price=this.data.price;
  50. if(price>0){
  51. this.wxPay();
  52. }else{
  53. this.opay();
  54. }
  55. },
  56. opay(){
  57. var that=this;
  58. var no=that.data.order_no
  59. app.api.useApi(app.globalData.baseAppUrl + "api/payment", {
  60. order_no: no,
  61. }, "post").then(function (res) {
  62. console.log(res)
  63. if (res.code != 200) {
  64. wx.showLoading({
  65. title: res.message.msg,
  66. })
  67. setTimeout(function () {
  68. wx.hideLoading({
  69. success: (res) => { },
  70. })
  71. }, 1000);
  72. } else {
  73. wx.navigateTo({
  74. url: '/pages/order/detail/detail?order_no='+no
  75. })
  76. }
  77. }).catch(function (err) {console.log(err)})
  78. // wx.switchTab({
  79. // url: '/pages/tabber/order/index',
  80. // })
  81. },
  82. click(e){
  83. // this.pageinfo.price=e.currentTarget.dataset.price;
  84. this.setData({
  85. price:e.currentTarget.dataset.price,
  86. give_price:e.currentTarget.dataset.gprice,
  87. })
  88. },
  89. wxPay(){
  90. var that=this;
  91. var no=that.data.price
  92. app.api.useApi(app.globalData.baseAppUrl + "api/recharge/charge", {
  93. price: no,
  94. }, "post").then(function (res) {
  95. console.log(res)
  96. if (res.code != 200) {
  97. wx.showLoading({
  98. title: res.message.msg,
  99. })
  100. setTimeout(function () {
  101. wx.hideLoading({
  102. success: (res) => { },
  103. })
  104. }, 1000);
  105. } else {
  106. var paydata=res.message.data
  107. wx.requestPayment({
  108. timeStamp: paydata.timeStamp,
  109. nonceStr: paydata.nonceStr,
  110. package: paydata.package,
  111. signType: paydata.signType,
  112. paySign: paydata.paySign,
  113. success (res) {
  114. console.log(res);
  115. if(res.errMsg=="requestPayment:ok"){
  116. that.opay();
  117. }
  118. },
  119. fail (res) {
  120. wx.showLoading({
  121. title: "失败,请重试!",
  122. })
  123. setTimeout(function () {
  124. wx.hideLoading({
  125. success: (res) => { },
  126. })
  127. }, 1000);
  128. console.log(res)}
  129. })
  130. }
  131. }).catch(function (err) {console.log(err)})
  132. },
  133. back:function(){
  134. wx.redirectTo({
  135. url: '/pages/order/detail/detail?order_no='+this.data.order_no,
  136. })
  137. }
  138. })