coupon.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var http = require('../../utils/http.js');
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. item: Object,
  8. type: Number,
  9. order: Boolean,
  10. canUse: Boolean,
  11. index: Number,
  12. showTimeType: Number
  13. },
  14. /**
  15. * 组件的初始数据
  16. */
  17. data: {
  18. stsType: 4
  19. },
  20. // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
  21. attached: function() {
  22. //console.log(this.data.item);
  23. },
  24. /**
  25. * 组件的方法列表
  26. */
  27. methods: {
  28. receiveCoupon() {
  29. var couponId = this.data.item.couponId;
  30. http.request({
  31. url: "/p/myCoupon/receive",
  32. method: "POST",
  33. data: couponId,
  34. callBack: () => {
  35. var coupon = this.data.item;
  36. coupon.canReceive = false;
  37. this.setData({
  38. item: coupon
  39. })
  40. }
  41. })
  42. },
  43. checkCoupon(e) {
  44. // this.triggerEvent('checkCoupon', this.data.index);
  45. this.triggerEvent('checkCoupon', {
  46. couponId: e.currentTarget.dataset.couponid
  47. });
  48. },
  49. /**
  50. * 立即使用
  51. */
  52. useCoupon() {
  53. var url = '/pages/prod-classify/prod-classify?sts=' + this.data.stsType;
  54. var id = this.data.item.couponId;
  55. var title = "优惠券活动商品";
  56. if (id) {
  57. url += "&tagid=" + id + "&title=" + title;
  58. }
  59. wx.navigateTo({
  60. url: url
  61. })
  62. }
  63. }
  64. })