discount.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. Page({
  2. data: {
  3. list:[]
  4. },
  5. onLoad: function (options) {
  6. var that = this;
  7. wx.request({
  8. url: 'https://yutang.web.ximengnaikang.com/api/coupons',
  9. method: 'GET',
  10. header: {
  11. 'content-type': 'application/x-www-form-urlencoded',
  12. 'Authorization':wx.getStorageSync('token')
  13. },
  14. success: function (res) {
  15. console.log(res)
  16. if (res.statusCode == 200) {
  17. that.setData({list:res.data.data})
  18. }
  19. }
  20. })
  21. },
  22. buy:function(e){
  23. console.log(e)
  24. var data = {
  25. 'coupon_id':e.currentTarget.dataset.id
  26. }
  27. wx.request({
  28. url: 'https://yutang.web.ximengnaikang.com/api/coupon/pay',
  29. method: 'POST',
  30. data:data,
  31. header: {
  32. 'content-type': 'application/x-www-form-urlencoded',
  33. 'Authorization':wx.getStorageSync('token')
  34. },
  35. success: function (res) {
  36. console.log(res)
  37. if (res.statusCode == 200) {
  38. wx.requestPayment({ //调用微信支付
  39. timeStamp: res.data.data.timeStamp.toString(),
  40. nonceStr: res.data.data.nonceStr,
  41. package: res.data.data.package,
  42. signType: res.data.data.signType,
  43. paySign: res.data.data.paySign,
  44. success(resp) {
  45. console.log(resp)
  46. wx.showToast({
  47. title: '购买成功',
  48. icon: 'none'
  49. })
  50. },
  51. fail(err) {
  52. console.log(err)
  53. wx.showToast({
  54. title: '支付失败',
  55. icon: 'none'
  56. })
  57. }
  58. })
  59. }
  60. }
  61. })
  62. },
  63. onReady: function () {
  64. },
  65. onShow: function () {
  66. },
  67. onHide: function () {
  68. },
  69. onUnload: function () {
  70. },
  71. onPullDownRefresh: function () {
  72. var that = this;
  73. wx.showNavigationBarLoading();
  74. wx.request({
  75. url: 'https://yutang.web.ximengnaikang.com/api/coupons',
  76. method: 'GET',
  77. header: {
  78. 'content-type': 'application/x-www-form-urlencoded',
  79. 'Authorization':wx.getStorageSync('token')
  80. },
  81. success: function (res) {
  82. console.log(res)
  83. if (res.statusCode == 200) {
  84. that.setData({list:res.data.data})
  85. wx.hideNavigationBarLoading();
  86. wx.stopPullDownRefresh();
  87. }
  88. }
  89. })
  90. },
  91. onReachBottom: function () {
  92. },
  93. onShareAppMessage: function () {
  94. }
  95. })