pay.js 1.8 KB

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