1
0

pay.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var api = require('../../config/api.js');
  4. Page({
  5. data: {
  6. orderId: 0,
  7. actualPrice: 0.00
  8. },
  9. onLoad: function (options) {
  10. // 页面初始化 options为页面跳转所带来的参数
  11. this.setData({
  12. orderId: options.orderId,
  13. actualPrice: options.actualPrice
  14. })
  15. },
  16. onReady: function () {
  17. },
  18. onShow: function () {
  19. // 页面显示
  20. },
  21. onHide: function () {
  22. // 页面隐藏
  23. },
  24. onUnload: function () {
  25. // 页面关闭
  26. },
  27. //向服务请求支付参数
  28. requestPayParam() {
  29. let that = this;
  30. // 测试领取优惠券
  31. // wx.redirectTo({
  32. // url: '/pages/payResult/payResult?status=1&orderId=' + that.data.orderId,
  33. // })
  34. // todo
  35. util.request(api.PayPrepayId, { orderId: that.data.orderId, payType: 1 }).then(function (res) {
  36. if (res.errno === 0) {
  37. let payParam = res.data;
  38. wx.requestPayment({
  39. 'timeStamp': payParam.timeStamp,
  40. 'nonceStr': payParam.nonceStr,
  41. 'package': payParam.package,
  42. 'signType': payParam.signType,
  43. 'paySign': payParam.paySign,
  44. 'success': function (res) {
  45. wx.redirectTo({
  46. url: '/pages/payResult/payResult?status=1&orderId=' + that.data.orderId,
  47. })
  48. },
  49. 'fail': function (res) {
  50. wx.redirectTo({
  51. url: '/pages/payResult/payResult?status=0&orderId=' + that.data.orderId,
  52. })
  53. }
  54. })
  55. }else {
  56. util.showErrorToast(res.errmsg)
  57. }
  58. });
  59. },
  60. startPay() {
  61. this.requestPayParam();
  62. }
  63. })