pay.js 2.0 KB

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