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.

151 lines
3.2KB

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