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.

138 lines
3.0KB

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