Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

213 Zeilen
4.7KB

  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. console.log(this.data.buyNumber)
  60. if (!this.data.buyNumber){
  61. wx.showToast({
  62. title: '请先输入赠送好友优惠券的数量',
  63. icon:"none",
  64. duration:2000
  65. })
  66. return;
  67. } else if (this.data.buyNumber==0){
  68. wx.showToast({
  69. title: '赠送好友优惠券的数量最小为1',
  70. icon: "none",
  71. duration: 2000
  72. })
  73. return;
  74. }
  75. if (!this.data.yesShare) {
  76. this.data.yesShare = true;
  77. this.getShareId();
  78. }
  79. },
  80. hideMask:function(){
  81. this.data.yesShare = false;
  82. this.setData({
  83. showMask: false,
  84. })
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function (options) {
  120. this.setData({
  121. showMask: false,
  122. yesShare:false,
  123. })
  124. var shareUrl = "";//分享指定路径
  125. var titleWord = "";//title
  126. var shareImg = "";//分享图
  127. if (options.from === "button"){
  128. shareUrl = '/pages/receiveTicket/receiveTicket?shareId=' + this.data.shareId + "&number=" + this.data.buyNumber
  129. titleWord = "赠送给好友"
  130. shareImg = this.data.ticketUser.coupon_img_small;
  131. }else{
  132. shareUrl = "/pages/register/register";
  133. titleWord = "老门框爆肚会员"
  134. shareImg = "";
  135. }
  136. return{
  137. title: titleWord,
  138. imageUrl: shareImg,
  139. path: shareUrl,
  140. success: res=> {
  141. console.log(res, "转发成功")
  142. },
  143. }
  144. },
  145. addFn: function () {
  146. if (this.data.ticketNum < this.data.ticketUser.num) {
  147. this.data.ticketNum++;
  148. this.setData({
  149. buyNumber: this.data.ticketNum
  150. })
  151. }
  152. },
  153. subtractFn: function () {
  154. if (this.data.ticketNum > 1) {
  155. this.data.ticketNum--;
  156. this.setData({
  157. buyNumber: this.data.ticketNum
  158. })
  159. }
  160. },
  161. getInputVal: function (e) {
  162. if (e.detail.value <= this.data.surplusNum){
  163. console.log(this.data.buyNumber)
  164. // if (e.detail.value == 0) {
  165. // wx.showToast({
  166. // title: "赠送数量最小为1",
  167. // icon:"none",
  168. // duration: 2000
  169. // })
  170. // this.setData({
  171. // buyNumber: 1,
  172. // ticketNum: 1
  173. // })
  174. // }else{
  175. // this.setData({
  176. // buyNumber: e.detail.value,
  177. // ticketNum: e.detail.value
  178. // })
  179. // }
  180. this.setData({
  181. buyNumber: e.detail.value,
  182. ticketNum: e.detail.value
  183. })
  184. } else{
  185. wx.showToast({
  186. title: "您赠送数量不能大于您已有数量",
  187. icon: "none",
  188. duration:2000
  189. })
  190. setTimeout(() => {
  191. this.setData({
  192. buyNumber: 1,
  193. ticketNum: 1
  194. })
  195. },1000)
  196. }
  197. },
  198. })