Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

187 lines
4.0KB

  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. showMask:false,//弹框
  17. yesShare:false,//防止重复点击赠送按钮
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. console.log(options.id)
  24. this.data.id = options.id
  25. this.data.sellId = options.id;
  26. if (app.globalData.openId) {
  27. this.getTicketUser()
  28. } else {
  29. app.globalData.openidSuccessFuc = this.getTicketUser;
  30. }
  31. },
  32. getTicketUser: function () {//获取优惠券信息
  33. app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: this.data.sellId, from: 2 }, e => {
  34. console.log(e)
  35. if (e.code == 200) {
  36. this.setData({
  37. ticketUser: e.data,
  38. surplusNum:e.data.num,
  39. })
  40. }
  41. }, this)
  42. },
  43. getShareId:function(){
  44. wx.showLoading({
  45. title: '加载中',
  46. })
  47. app.wxRequest(app.globalData.httpUrl + 'couponsell/presentid', { coupon_sell_id: this.data.sellId}, e => {
  48. console.log(e)
  49. if (e.code == 200) {
  50. wx.hideLoading();
  51. this.setData({
  52. shareId: e.present_id,
  53. showMask:true,
  54. })
  55. }
  56. }, this)
  57. },
  58. shareBtn:function(){
  59. if (!this.data.yesShare) {
  60. this.data.yesShare = true;
  61. this.getShareId();
  62. }
  63. },
  64. hideMask:function(){
  65. this.data.yesShare = false;
  66. this.setData({
  67. showMask: false,
  68. })
  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 (options) {
  104. this.setData({
  105. showMask: false,
  106. yesShare:false,
  107. })
  108. var shareUrl = "";//分享指定路径
  109. if (options.from === "button"){
  110. shareUrl = '/pages/receiveTicket/receiveTicket?shareId=' + this.data.shareId + "&number=" + this.data.buyNumber
  111. }
  112. return{
  113. title:"赠送给好友",
  114. imageUrl: this.data.ticketUser.coupon_img_small,
  115. path: shareUrl,
  116. success: res=> {
  117. console.log(res, "转发成功")
  118. },
  119. }
  120. },
  121. addFn: function () {
  122. if (this.data.ticketNum < this.data.ticketUser.num) {
  123. this.data.ticketNum++;
  124. this.setData({
  125. buyNumber: this.data.ticketNum
  126. })
  127. }
  128. },
  129. subtractFn: function () {
  130. if (this.data.ticketNum > 1) {
  131. this.data.ticketNum--;
  132. this.setData({
  133. buyNumber: this.data.ticketNum
  134. })
  135. }
  136. },
  137. getInputVal: function (e) {
  138. if (e.detail.value <= this.data.surplusNum){
  139. console.log(this.data.buyNumber)
  140. // if (e.detail.value < 1) {
  141. // wx.showToast({
  142. // title: "赠送量最小为1",
  143. // duration: 1000
  144. // })
  145. // this.setData({
  146. // buyNumber: 1,
  147. // ticketNum: 1
  148. // })
  149. // }else{
  150. // this.setData({
  151. // buyNumber: e.detail.value,
  152. // ticketNum: e.detail.value
  153. // })
  154. // }
  155. this.setData({
  156. buyNumber: e.detail.value,
  157. ticketNum: e.detail.value
  158. })
  159. } else{
  160. wx.showToast({
  161. title: "您赠送数量太大",
  162. duration:1000
  163. })
  164. setTimeout(() => {
  165. this.setData({
  166. buyNumber: 1,
  167. ticketNum: 1
  168. })
  169. },1000)
  170. }
  171. },
  172. })