You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

receiveTicket.js 3.4KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // pages/receiveTicket/receiveTicket.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. yesGet: true,//是否被领取
  9. ticketUser:[],//优惠券信息
  10. titleWord:"",
  11. presentId:"",//接受的id
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. app.globalData.present_id = options.shareId;
  18. this.data.presentId = options.shareId;
  19. app.globalData.number = options.number;
  20. this.getTicketUser(options.shareId, options.number);
  21. // wx.showToast({
  22. // title: options.number,
  23. // duration:2000
  24. // })
  25. },
  26. getTicketUser: function (id,number) {//获取优惠券信息
  27. app.wxRequest(app.globalData.httpUrl + 'couponbuy/presentstate', { present_id: id, present_num: number }, e => {
  28. console.log(e)
  29. if (e.code == 201) {
  30. this.setData({
  31. ticketUser: e.data,
  32. yesGet: true
  33. })
  34. } else if (e.code == 202){
  35. this.setData({
  36. yesGet: false,
  37. titleWord:"此券已被领取"
  38. })
  39. } else if (e.code == 203){
  40. this.setData({
  41. yesGet: false,
  42. titleWord: "此券已失效"
  43. })
  44. } else if (e.code == -201) {
  45. this.setData({
  46. yesGet: false,
  47. titleWord: "没有相关赠送记录"
  48. })
  49. } else if (e.code == 204) {
  50. this.setData({
  51. yesGet: false,
  52. titleWord: "赠送优惠券不足,无法领取"
  53. })
  54. } else if (e.code == 205) {
  55. this.setData({
  56. yesGet: false,
  57. titleWord: "优惠券超限,无法领取"
  58. })
  59. }
  60. }, this)
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. },
  97. // "p1583395285z86"
  98. getTicketFn:function(){//点击领取优惠券
  99. var id = this.data.presentId;
  100. app.wxRequest(app.globalData.httpUrl + 'couponbuy/receive', { present_id: id }, e => {
  101. console.log(e)
  102. if (e.code == 200) {
  103. wx.showToast({
  104. title: '领取成功',
  105. duration:500
  106. })
  107. setTimeout(()=>{
  108. wx.switchTab({
  109. url: '/pages/index/index'
  110. })
  111. },500)
  112. } else if (e.code == -201) {//用户未注册
  113. console.log(e.message)
  114. } else if (e.code == -202) {//没有相应赠品记录
  115. console.log(e.message)
  116. }else if (e.code == -203){//无法领取自己的优惠券
  117. console.log(e.message)
  118. wx.showToast({
  119. title: '领取失败',
  120. duration: 500
  121. })
  122. } else if (e.code == -204) {//赠送优惠券已领取
  123. console.log(e.message)
  124. } else if (e.code == -205) {//优惠券已失效
  125. console.log(e.message)
  126. wx.showToast({
  127. title: '优惠券已失效',
  128. duration: 500
  129. })
  130. }
  131. }, this,"POST")
  132. },
  133. backIndex:function(){//优惠券已被领取,点击确定返回首页
  134. },
  135. })