coupon-status.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/coupon/coupon.js
  2. // var fileData = require('../../utils/util.js'); //暴露的接口;
  3. var app = getApp();
  4. Page({
  5. data: {
  6. _active:0,
  7. headerArray: ['可领取'],
  8. couponArray:"",
  9. userstatus:"",
  10. title: '加载中...',
  11. cartId:'',
  12. pinkId:'',
  13. addressId:'',
  14. totalPrice:''
  15. },
  16. headertap:function(e){
  17. this.setData({
  18. _active: e.target.dataset.idx
  19. });
  20. },
  21. onLoad: function (options) {
  22. app.setBarColor();
  23. if (options.cartId){
  24. this.setData({
  25. cartId: options.cartId,
  26. totalPrice: options.totalPrice,
  27. pinkId: options.pinkId,
  28. addressId: options.addressId,
  29. })
  30. this.getCouponOrderList();
  31. }else {
  32. this.getCouponList();
  33. }
  34. },
  35. getCouponUser:function(e){
  36. // e.currentTarget.dataset.id;
  37. var that = this;
  38. var id = e.currentTarget.dataset.id;
  39. if (that.data.cartId) {
  40. var cartId = that.data.cartId;
  41. var totalPrice = that.data.totalPrice;
  42. var addressId = that.data.addressId;
  43. var pinkId = that.data.pinkId;
  44. that.setData({
  45. cartId:'',
  46. totalPrice:'',
  47. addressId:'',
  48. pinkId:'',
  49. })
  50. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  51. url: '/pages/order-confirm/order-confirm?id=' + cartId + '&couponId=' + id + '&addressId=' + addressId + '&pinkId=' + pinkId
  52. })
  53. } else {
  54. var header = {
  55. 'content-type': 'application/x-www-form-urlencoded'
  56. };
  57. wx.request({
  58. url: app.globalData.url + '/routine/auth_api/user_get_coupon?uid=' + app.globalData.uid,
  59. method: 'POST',
  60. header: header,
  61. data: {
  62. couponId: id
  63. },
  64. success: function (res) {
  65. var array = that.data.couponArray;
  66. if (res.data.code == 200) {
  67. for (var i in array) {
  68. if (array[i].id == id) {
  69. array[i].is_use = true;
  70. }
  71. }
  72. that.setData({
  73. couponArray: array
  74. })
  75. wx.showToast({
  76. title: '领取成功',
  77. icon: 'success',
  78. duration: 1500
  79. })
  80. } else {
  81. wx.showToast({
  82. title: res.data.msg,
  83. icon: 'none',
  84. duration: 1500
  85. })
  86. }
  87. }
  88. })
  89. }
  90. },
  91. getCouponOrderList:function(){
  92. var that = this;
  93. var that = this;
  94. wx.request({
  95. url: app.globalData.url + '/routine/auth_api/get_use_coupon_order?uid=' + app.globalData.uid,
  96. method: 'GET',
  97. data: {
  98. totalPrice: that.data.totalPrice
  99. },
  100. success: function (res) {
  101. that.setData({
  102. userstatus: '立即使用',
  103. couponArray: res.data.data,
  104. title: "没有数据了",
  105. loadinghidden: true
  106. })
  107. }
  108. })
  109. },
  110. getCouponList:function(){
  111. var that = this;
  112. var header = {
  113. 'content-type': 'application/x-www-form-urlencoded'
  114. };
  115. var that = this;
  116. wx.request({
  117. url: app.globalData.url + '/routine/auth_api/get_issue_coupon_list?uid=' + app.globalData.uid,
  118. method: 'POST',
  119. header: header,
  120. data: {
  121. limit: 10
  122. },
  123. success: function (res) {
  124. that.setData({
  125. userstatus: '立即领取',
  126. couponArray: res.data.data,
  127. title: "没有数据了",
  128. loadinghidden: true
  129. })
  130. }
  131. })
  132. }
  133. })