1
0

pay.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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&orderId=' + that.data.orderId,
  48. })
  49. },
  50. 'fail': function (res) {
  51. wx.redirectTo({
  52. url: '/pages/payResult/payResult?status=0&orderId=' + that.data.orderId,
  53. })
  54. }
  55. })
  56. }else {
  57. util.showErrorToast(res.errmsg)
  58. }
  59. });
  60. },
  61. startPay() {
  62. this.requestPayParam();
  63. }
  64. })