您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

149 行
3.3KB

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