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.

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