payMoney.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/payMoney/payMoney.js
  2. import utils from '../../utils/util'
  3. import orderApi from "../../api/order"
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. show:false
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: async function (options) {
  16. console.log(options)
  17. const self = this
  18. if(!app.globalData.userInfo){
  19. await app.wxLogin({"type":"slince"})
  20. }
  21. const url = decodeURIComponent(options.q)
  22. console.log(url)
  23. const order = utils.getQueryString('https://llzlovesh.top?orderId=412,413')
  24. console.log(order)
  25. const info = await orderApi.payOrder(order.orderId)
  26. self.setData({
  27. info,
  28. orderIds:order.orderId,
  29. show:true
  30. })
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面隐藏
  44. */
  45. onHide: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面卸载
  49. */
  50. onUnload: function () {
  51. },
  52. /**
  53. * 页面相关事件处理函数--监听用户下拉动作
  54. */
  55. onPullDownRefresh: function () {
  56. },
  57. /**
  58. * 页面上拉触底事件的处理函数
  59. */
  60. onReachBottom: function () {
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. async moneyPay() {
  68. const money = this.data.info.money
  69. const total = this.data.info.total
  70. if (money < total) {
  71. wx.showToast({
  72. title: '余额不足支付',
  73. })
  74. }
  75. let data = {
  76. orderIds:this.data.orderIds,
  77. type: 'balance'
  78. }
  79. const rs = await orderApi.createMasterOrder(data)
  80. wx.showModal({
  81. title: '提示',
  82. content: '支付成功',
  83. }).then(()=> {
  84. wx.switchTab({
  85. url: '/pages/personorder/personorder',
  86. })
  87. })
  88. },
  89. async pay() {
  90. let data = {
  91. orderIds:this.data.orderIds,
  92. type: 'xcx'
  93. }
  94. const rs = await orderApi.createMasterOrder(data)
  95. wx.requestPayment({
  96. timeStamp: rs.timeStamp,
  97. nonceStr: rs.nonceStr,
  98. package: rs.package,
  99. signType: rs.signType,
  100. paySign: rs.paySign,
  101. success (res) {
  102. wx.showModal({
  103. title: '提示',
  104. content: '支付成功',
  105. }).then(()=> {
  106. wx.switchTab({
  107. url: '/pages/personorder/personorder',
  108. })
  109. })
  110. },
  111. fail (res) {
  112. wx.showToast({
  113. title: '您取消了支付',
  114. })
  115. }
  116. })
  117. }
  118. })