coupon.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. var util = require('../../utils/util.js');
  2. var app = getApp();
  3. Page({
  4. mixins: [require('../../mixin/globalMixin.js')],
  5. data: {
  6. is_login: true,
  7. tab_index: 1,
  8. isHideLoadMore: true,
  9. no_order: 0,
  10. quan: [],
  11. loadText: '加载中'
  12. },
  13. page: 1,
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. util.check_login() ? this.setData({is_login: true}) : this.setData({is_login: false});
  19. this.getData();
  20. },
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow: function () {
  25. },
  26. /**
  27. * 授权成功回调
  28. */
  29. authSuccess: function () {
  30. wx.reLaunch({
  31. url: '/lionfish_comshop/pages/user/me',
  32. })
  33. },
  34. tabchange: function (e) {
  35. var index = e.currentTarget.dataset.index;
  36. this.page = 1;
  37. this.setData({
  38. quan: [],
  39. tab_index: index
  40. })
  41. this.getData();
  42. },
  43. getData: function () {
  44. this.setData({
  45. isHideLoadMore: true
  46. })
  47. wx.showLoading();
  48. this.data.no_order = 1
  49. var page = this.page;
  50. var tab_index = this.data.tab_index;
  51. var token = wx.getStorageSync('token');
  52. var self = this;
  53. app.util.request({
  54. 'url': 'entry/wxapp/user',
  55. 'data': {
  56. controller: 'user.myvoucherlist',
  57. token: token,
  58. type: tab_index,
  59. page: page,
  60. pre_page: 5,
  61. },
  62. dataType: 'json',
  63. method: 'POST',
  64. success: function (data) {
  65. wx.hideLoading();
  66. if (data.data.code == 0) {
  67. var agoData = self.data.quan;
  68. var goods = data.data.list;
  69. goods.map(function (good) {
  70. agoData.push(good);
  71. });
  72. self.setData({
  73. quan: agoData,
  74. no_order: 0
  75. });
  76. } else {
  77. self.setData({
  78. isHideLoadMore: true
  79. })
  80. return false;
  81. }
  82. }
  83. })
  84. },
  85. goUse: function (e) {
  86. let idx = e.currentTarget.dataset.idx;
  87. let quan = this.data.quan || [];
  88. if (quan.length>=idx) {
  89. if(quan[idx].is_limit_goods_buy==0) {
  90. wx.switchTab({
  91. url: '/lionfish_comshop/pages/index/index',
  92. })
  93. } else if (quan[idx].is_limit_goods_buy == 1) {
  94. let id = quan[idx].limit_goods_list;
  95. let ids = id.split(',');
  96. let url = '';
  97. if(ids.length>1) {
  98. url = '/lionfish_comshop/pages/type/result?type=2&good_ids=' + id;
  99. } else {
  100. url = '/lionfish_comshop/pages/goods/goodsDetail?id=' + id;
  101. }
  102. wx.navigateTo({ url: url })
  103. } else if (quan[idx].is_limit_goods_buy == 2) {
  104. let gid = quan[idx].goodscates || 0;
  105. wx.navigateTo({
  106. url: '/lionfish_comshop/pages/type/result?type=1&gid=' + gid,
  107. })
  108. }
  109. }
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. if (this.data.no_order == 1) return false;
  116. this.page += 1;
  117. this.getData();
  118. this.setData({
  119. isHideLoadMore: false
  120. })
  121. }
  122. })