Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

189 lines
4.6KB

  1. // pages/receiveTicket/receiveTicket.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. yesGet: true,//是否被领取
  9. ticketUser:[],//优惠券信息
  10. userPhone:"",//手机号
  11. titleWord:"",
  12. presentId:"",//接受的id
  13. ticketNum:0,
  14. moreClick:false,//防止重复点击领取
  15. showAll:false,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. app.globalData.present_id = options.shareId;
  22. this.data.presentId = options.shareId;
  23. app.globalData.number = options.number;
  24. this.setData({
  25. ticketNum: options.number
  26. })
  27. var state = wx.getStorageSync('state');
  28. if (state == 1) {//已注册
  29. if (app.globalData.openId) {
  30. this.getTicketUser();
  31. } else {
  32. app.globalData.openidSuccessFuc = this.getTicketUser;
  33. }
  34. this.setData({
  35. showAll:true
  36. })
  37. } else if (state == 0) {//未注册
  38. wx.switchTab({
  39. url: '/pages/register/register'
  40. })
  41. } else if (state == -1) {
  42. app.globalData.userInfoBackFn = res => {//等待结果
  43. if (res) {
  44. if (app.globalData.openId) {
  45. this.getTicketUser();
  46. } else {
  47. app.globalData.openidSuccessFuc = this.getTicketUser;
  48. }
  49. this.setData({
  50. showAll: true
  51. })
  52. } else {
  53. wx.switchTab({
  54. url: '/pages/register/register'
  55. })
  56. }
  57. }
  58. }
  59. },
  60. getTicketUser: function () {//获取赠送优惠券信息
  61. app.wxRequest(app.globalData.httpUrl + 'couponbuy/presentvisit', { present_id: app.globalData.present_id, present_num: app.globalData.number }, e => {
  62. console.log(e)
  63. if (e.code == 201) {
  64. var partPhone = e.data.user_phone.slice(0, 3) + "****" + e.data.user_phone.slice(7)
  65. this.setData({
  66. ticketUser: e.data,
  67. yesGet: true,
  68. userPhone: partPhone
  69. })
  70. } else if (e.code == 202) {
  71. var partPhone = e.data.user_phone.slice(0, 3) + "****" + e.data.user_phone.slice(7)
  72. this.setData({
  73. yesGet: false,
  74. ticketUser: e.data,
  75. titleWord: e.message,
  76. userPhone: partPhone
  77. })
  78. } else if (e.code == 203) {
  79. var partPhone = e.data.user_phone.slice(0, 3) + "****" + e.data.user_phone.slice(7)
  80. this.setData({
  81. yesGet: false,
  82. ticketUser: e.data,
  83. titleWord: e.message,
  84. userPhone: partPhone
  85. })
  86. } else if (e.code == 204) {
  87. var partPhone = e.data.user_phone.slice(0, 3) + "****" + e.data.user_phone.slice(7)
  88. this.setData({
  89. yesGet: false,
  90. ticketUser: e.data,
  91. titleWord: e.message,
  92. userPhone: partPhone
  93. })
  94. } else if (e.code == 205) {
  95. var partPhone = e.data.user_phone.slice(0, 3) + "****" + e.data.user_phone.slice(7)
  96. this.setData({
  97. yesGet: false,
  98. ticketUser: e.data,
  99. titleWord: e.message,
  100. userPhone: partPhone
  101. })
  102. }
  103. }, this)
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. },
  140. // "p1583474312b94"
  141. getTicketFn: function () {//点击领取优惠券
  142. var id = this.data.presentId;
  143. if (!this.data.moreClick) {
  144. app.wxRequest(app.globalData.httpUrl + 'couponbuy/receivepresent', { present_id: id }, e => {
  145. console.log(e)
  146. this.data.moreClick = true;
  147. if (e.code == 200) {
  148. wx.showToast({
  149. title: '领取成功',
  150. duration: 500
  151. })
  152. setTimeout(() => {
  153. wx.switchTab({
  154. url: '/pages/index/index'
  155. })
  156. }, 500)
  157. } else {
  158. wx.showToast({
  159. title: e.message,
  160. duration: 500
  161. })
  162. }
  163. }, this, "POST")
  164. }
  165. },
  166. backIndex:function(){//优惠券已被领取,点击确定返回首页
  167. wx.switchTab({
  168. url: '/pages/index/index'
  169. })
  170. },
  171. })