pay-result.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. var http = require('../../utils/http.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. sts: 0,
  8. orderNumbers: ''
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. this.setData({
  15. sts: options.sts,
  16. orderNumbers: options.orderNumbers
  17. });
  18. },
  19. toOrderList: function () {
  20. const pages = getCurrentPages()
  21. let deltaNum = 0
  22. pages.forEach((page, pageIndex) => {
  23. if (page.route == 'pages/orderList/orderList') {
  24. deltaNum = pages.length - pageIndex
  25. }
  26. })
  27. wx.redirectTo({
  28. url: '/pages/orderList/orderList?sts=' + (this.data.sts == 0 ? '1' : '2')
  29. })
  30. },
  31. toIndex: function () {
  32. wx.switchTab({
  33. url: '/pages/index/index'
  34. })
  35. },
  36. payAgain: function () {
  37. wx.showLoading({
  38. mask: true
  39. });
  40. var params = {
  41. url: "/p/order/pay",
  42. method: "POST",
  43. data: {
  44. payType: 1,
  45. orderNumbers: this.data.orderNumbers
  46. },
  47. callBack: (res) => {
  48. //console.log(res);
  49. wx.hideLoading();
  50. wx.requestPayment({
  51. timeStamp: res.timeStamp,
  52. nonceStr: res.nonceStr,
  53. package: res.packageValue,
  54. signType: res.signType,
  55. paySign: res.paySign,
  56. success: e => {
  57. //console.log("支付成功");
  58. this.setData({
  59. sts : 1
  60. })
  61. wx.redirectTo({
  62. url: '/pages/pay-result/pay-result?sts=' + this.data.sts + '&orderNum=' + orderNumbers + "&orderType=" + this.data.orderType,
  63. })
  64. },
  65. fail: err => {
  66. }
  67. })
  68. }
  69. };
  70. http.request(params);
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面隐藏
  84. */
  85. onHide: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面卸载
  89. */
  90. onUnload: function () {
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. },
  102. /**
  103. * 用户点击右上角分享
  104. */
  105. onShareAppMessage: function () {
  106. }
  107. })