payResult.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. status: false,
  7. orderId: 0
  8. },
  9. onLoad: function(options) {
  10. // 页面初始化 options为页面跳转所带来的参数
  11. this.setData({
  12. orderId: options.orderId,
  13. status: options.status === '1' ? true : false
  14. })
  15. },
  16. onReady: function() {
  17. },
  18. onShow: function() {
  19. // 页面显示
  20. },
  21. onHide: function() {
  22. // 页面隐藏
  23. },
  24. onUnload: function() {
  25. // 页面关闭
  26. },
  27. payOrder() {
  28. let that = this;
  29. util.request(api.OrderPrepay, {
  30. orderId: that.data.orderId
  31. }, 'POST').then(function(res) {
  32. if (res.errno === 0) {
  33. const payParam = res.data;
  34. console.log("支付过程开始")
  35. wx.requestPayment({
  36. 'timeStamp': payParam.timeStamp,
  37. 'nonceStr': payParam.nonceStr,
  38. 'package': payParam.packageValue,
  39. 'signType': payParam.signType,
  40. 'paySign': payParam.paySign,
  41. 'success': function(res) {
  42. console.log("支付过程成功")
  43. that.setData({
  44. status: true
  45. });
  46. },
  47. 'fail': function(res) {
  48. console.log("支付过程失败")
  49. util.showErrorToast('支付失败');
  50. },
  51. 'complete': function(res) {
  52. console.log("支付过程结束")
  53. }
  54. });
  55. }
  56. });
  57. }
  58. })