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.1KB

  1. // pages/givePage/givePage.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. buyNumber: 1,
  9. ticketNum: 1,
  10. ticketUser: [],//优惠券信息
  11. getBackData:"",//赠送回传字段
  12. surplusNum:0,//剩余张数
  13. yesMask:false,//提示赠送弹框
  14. shareId:"",//获取用户标识
  15. sellId:"",//优惠券券码
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. console.log(options.id)
  22. if (app.globalData.openId) {
  23. this.getTicketUser(options.id, 2)
  24. } else {
  25. app.globalData.openidSuccessFuc = this.getTicketUser;
  26. }
  27. this.data.sellId = options.id;
  28. },
  29. getTicketUser: function (id, from) {//获取优惠券信息
  30. app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: id, from: from }, e => {
  31. console.log(e)
  32. if (e.code == 200) {
  33. this.setData({
  34. ticketUser: e.data,
  35. surplusNum:e.data.num,
  36. shareId: e.data.present_id
  37. })
  38. }
  39. }, this)
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh: function () {
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function (options) {
  75. var shareUrl = "";//分享指定路径
  76. if (options.from === "button"){
  77. shareUrl = '/pages/receiveTicket/receiveTicket?shareId=' + this.data.shareId + "&number=" + this.data.buyNumber
  78. }
  79. return{
  80. title:"赠送给好友",
  81. imageUrl: this.data.ticketUser.coupon_img_small,
  82. path: shareUrl,
  83. success: res=> {
  84. console.log(res, "转发成功")
  85. },
  86. }
  87. },
  88. addFn: function () {
  89. if (this.data.ticketNum < this.data.ticketUser.num) {
  90. this.data.ticketNum++;
  91. this.setData({
  92. buyNumber: this.data.ticketNum
  93. })
  94. }
  95. },
  96. subtractFn: function () {
  97. if (this.data.ticketNum > 1) {
  98. this.data.ticketNum--;
  99. this.setData({
  100. buyNumber: this.data.ticketNum
  101. })
  102. }
  103. },
  104. getInputVal: function (e) {
  105. if (e.detail.value <= this.data.surplusNum){
  106. console.log(this.data.buyNumber)
  107. if (e.detail.value < 1) {
  108. wx.showToast({
  109. title: "赠送量最小为1",
  110. duration: 1000
  111. })
  112. this.setData({
  113. buyNumber: 1,
  114. ticketNum: 1
  115. })
  116. }else{
  117. this.setData({
  118. buyNumber: e.detail.value,
  119. ticketNum: e.detail.value
  120. })
  121. }
  122. } else{
  123. wx.showToast({
  124. title: "您赠送数量太大",
  125. duration:1000
  126. })
  127. setTimeout(() => {
  128. this.setData({
  129. buyNumber: 1,
  130. ticketNum: 1
  131. })
  132. },1000)
  133. }
  134. },
  135. })