pay.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. payType: 'wx'
  10. },
  11. onLoad: function (options) {
  12. // 页面初始化 options为页面跳转所带来的参数
  13. this.setData({
  14. orderIds: options.orderIds,
  15. actualPrice: options.actualPrice,
  16. isMergePay: options.isMergePay
  17. })
  18. console.log(this.data.orderIds);
  19. },
  20. onReady: function () {
  21. },
  22. onShow: function () {
  23. // 页面显示
  24. },
  25. onHide: function () {
  26. // 页面隐藏
  27. },
  28. onUnload: function () {
  29. // 页面关闭
  30. },
  31. //改变支付方式
  32. changePayType: function (e) {
  33. console.log(e.currentTarget.id);
  34. this.setData({
  35. payType: e.currentTarget.id
  36. });
  37. },
  38. //向服务请求支付参数
  39. requestPayParam() {
  40. let that = this;
  41. wx.showLoading({
  42. title: '加载中...',
  43. });
  44. console.log(this.data.payType);
  45. let url = '';
  46. if (this.data.payType == 'wx') {
  47. url = api.PayPrepayId;
  48. } else if (this.data.payType == 'pingan') {
  49. url = api.Payorder;
  50. } else if (this.data.payType == 'wxGlobal') {
  51. url = api.GlobalPayorder;
  52. }
  53. // 测试领取优惠券
  54. // wx.redirectTo({
  55. // url: '/pages/payResult/payResult?status=1&orderId=' + that.data.orderId,
  56. // })
  57. // todo
  58. util.request(url, {
  59. orderIds: that.data.orderIds, payType: 1,
  60. isMergePay: that.data.isMergePay
  61. }).then(function (res) {
  62. wx.hideLoading();
  63. if (res.errno === 0) {
  64. let payParam = res.data;
  65. wx.requestPayment({
  66. 'timeStamp': payParam.timeStamp,
  67. 'nonceStr': payParam.nonceStr,
  68. 'package': payParam.package,
  69. 'signType': payParam.signType,
  70. 'paySign': payParam.paySign,
  71. 'success': function (res) {
  72. wx.redirectTo({
  73. url: '/pages/payResult/payResult?status=1&orderIds=' + that.data.orderIds,
  74. })
  75. },
  76. 'fail': function (res) {
  77. wx.redirectTo({
  78. url: '/pages/payResult/payResult?status=0&orderIds=' + that.data.orderIds,
  79. })
  80. }
  81. })
  82. }else {
  83. // util.showErrorToast(res.errmsg)
  84. wx.showModal({
  85. title: '',
  86. content: res.errmsg,
  87. showCancel: false
  88. });
  89. }
  90. });
  91. },
  92. startPay(e) {
  93. this.requestPayParam();
  94. }
  95. })