index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // pages/pay/index.js
  2. const api = require('../../utils/api.js')
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. referrerInfo: null,
  10. orderInfo: {}
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. console.log('pay order info', options)
  17. this.setData({
  18. referrerInfo: app.globalData.referrerInfo || '',
  19. orderInfo: options
  20. })
  21. let timer = setInterval(() => {
  22. if (app.globalData.PageCallback) {
  23. api.getPayInfo({
  24. data: {
  25. 'order-order_id': this.data.orderInfo.orderId
  26. }
  27. }).then(res => {
  28. console.log('get pay info success', res)
  29. this.setData({
  30. orderInfo: res.data
  31. })
  32. api.payCheck({
  33. data: {
  34. 'order-order_id': this.data.orderInfo.order_id,
  35. 'payway': 'wxpay'
  36. }
  37. }).then(res => {
  38. console.log('pay check success', res)
  39. }, err => {
  40. console.log('pay check fail', err)
  41. })
  42. }, err => {
  43. console.log('get pay info fail', err)
  44. })
  45. clearInterval(timer)
  46. }
  47. }, 200)
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function () {
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh: function () {
  73. },
  74. /**
  75. * 页面上拉触底事件的处理函数
  76. */
  77. onReachBottom: function () {
  78. },
  79. pay: function () {
  80. api.payCheck({
  81. data: {
  82. 'order-order_id': this.data.orderInfo.order_id,
  83. 'payway': 'wxpay'
  84. }
  85. }).then(res => {
  86. console.log(res)
  87. }, err => {
  88. console.log(err)
  89. })
  90. }
  91. })