coupon-status.js 3.5 KB

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