1
0

pay.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // 测试领取优惠券
  34. // wx.redirectTo({
  35. // url: '/pages/payResult/payResult?status=1&orderId=' + that.data.orderId,
  36. // })
  37. // todo
  38. util.request(api.PayPrepayId, {
  39. orderIds: that.data.orderIds, payType: 1,
  40. isMergePay: that.data.isMergePay
  41. }).then(function (res) {
  42. if (res.errno === 0) {
  43. let payParam = res.data;
  44. wx.requestPayment({
  45. 'timeStamp': payParam.timeStamp,
  46. 'nonceStr': payParam.nonceStr,
  47. 'package': payParam.package,
  48. 'signType': payParam.signType,
  49. 'paySign': payParam.paySign,
  50. 'success': function (res) {
  51. wx.redirectTo({
  52. url: '/pages/payResult/payResult?status=1&orderIds=' + that.data.orderIds,
  53. })
  54. },
  55. 'fail': function (res) {
  56. wx.redirectTo({
  57. url: '/pages/payResult/payResult?status=0&orderIds=' + that.data.orderIds,
  58. })
  59. }
  60. })
  61. }else {
  62. // util.showErrorToast(res.errmsg)
  63. wx.showModal({
  64. title: '',
  65. content: res.errmsg,
  66. showCancel: false
  67. });
  68. }
  69. });
  70. },
  71. startPay() {
  72. this.requestPayParam();
  73. }
  74. })