couponDetail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. discStatus: '',
  7. couponId: '',
  8. storeId: '',
  9. storeTopicId: '',
  10. tickDiscount: {},
  11. isShare: '',
  12. referrer: 0,
  13. discId: ''
  14. },
  15. onLoad: function(options) {
  16. // 页面初始化 options为页面跳转所带来的参数
  17. // options.scene = "4&8&0";
  18. if (options.scene) {
  19. var scene = decodeURIComponent(options.scene);
  20. console.log("scene is ", scene);
  21. var scanArray = scene.split('&');
  22. var discId = scanArray[0];
  23. var storeId = scanArray[1];
  24. var isShare = scanArray[2];
  25. // console.log("discId is ", discId);
  26. // console.log("storeId is ", storeId);
  27. // console.log("isShare is ", isShare);
  28. this.setData({
  29. discId: discId,
  30. storeId: storeId,
  31. isShare: isShare
  32. });
  33. if (storeId) {
  34. wx.setStorageSync('storeId', storeId);
  35. }
  36. } else {
  37. if (options.couponId) {
  38. this.setData({
  39. couponId: options.couponId,
  40. storeId: options.storeId,
  41. isShare: options.isShare
  42. });
  43. }
  44. if (options.discId) {
  45. this.setData({
  46. discId: options.discId,
  47. storeId: options.storeId,
  48. isShare: options.isShare
  49. });
  50. }
  51. }
  52. console.log("discId is ", options.discId);
  53. console.log("storeId is ", options.storeId);
  54. console.log("isShare is ", options.isShare);
  55. this.getTickDiscountDetail();
  56. },
  57. onReady: function() {},
  58. onShow: function() {},
  59. onHide: function() {
  60. // 页面隐藏
  61. },
  62. onUnload: function() {
  63. // 页面关闭
  64. },
  65. getTickDiscountDetail() {
  66. var that = this;
  67. util.request(api.DiscountDetail, {
  68. couponId: that.data.couponId,
  69. storeId: that.data.storeId,
  70. discId: that.data.discId
  71. })
  72. .then(function(res) {
  73. if (res.errno === 0) {
  74. console.log(res.data);
  75. if (res.data) {
  76. that.setData({
  77. tickDiscount: res.data
  78. });
  79. }
  80. }
  81. });
  82. },
  83. linkCouponInfo(event) {
  84. // let url = event.currentTarget.dataset.couponUrl;
  85. let discId = event.currentTarget.dataset.discId;
  86. let storeId = wx.getStorageSync('storeId');
  87. let couponId = event.currentTarget.dataset.couponId;
  88. console.log('couponId' + couponId)
  89. console.log('discId' + discId)
  90. if (couponId) {
  91. console.log('couponId' + couponId)
  92. wx.navigateTo({
  93. url: '../couponTickInfo/couponTickInfo?couponId=' + couponId + '&&storeId=' + storeId
  94. })
  95. }
  96. if (discId) {
  97. console.log('discId' + discId)
  98. wx.navigateTo({
  99. url: '../couponTickInfo/couponTickInfo?discId=' + discId + '&&storeId=' + storeId
  100. })
  101. }
  102. },
  103. linkMyCoupon() {
  104. wx.navigateTo({
  105. url: '../coupon/coupon'
  106. })
  107. },
  108. /**
  109. * 领取优惠券
  110. */
  111. getUserCoupon(event) {
  112. var that = this;
  113. let tickDiscId = event.currentTarget.dataset.tickId;
  114. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  115. let storeId = wx.getStorageSync('storeId');
  116. util.request(api.getUserCoupon, {
  117. tickDiscId: tickDiscId,
  118. storeTopicId: storeTopicId,
  119. storeId: storeId
  120. }, 'POST').then(function(res) {
  121. if (res.errno === 0) {
  122. wx.showToast({
  123. title: '领取成功'
  124. });
  125. that.setData({
  126. discStatus: 0
  127. });
  128. that.getTickDiscountDetail();
  129. } else {
  130. wx.showToast({
  131. title: res.errmsg,
  132. icon: 'none'
  133. })
  134. }
  135. });
  136. },
  137. /**
  138. * 优惠券可使用商品
  139. */
  140. linkCoupon(event) {
  141. // let url = event.currentTarget.dataset.couponUrl;
  142. let tickDiscId = event.currentTarget.dataset.tickId;
  143. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  144. let storeId = wx.getStorageSync('storeId');
  145. wx.navigateTo({
  146. url: '../ticketDiscountGoods/ticketDiscountGoods?tickDiscId=' + tickDiscId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId
  147. })
  148. },
  149. })