reward.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. list: [],
  8. total_points: 0,
  9. tab_index: 1
  10. },
  11. listPage: 1,
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.goodsList();
  17. this.getScore();
  18. },
  19. /**
  20. * 生命周期函数--监听页面显示
  21. */
  22. onShow: function () {
  23. },
  24. tabchange: function (e) {
  25. var index = e.currentTarget.dataset.index;
  26. this.listPage = 1;
  27. this.setData({
  28. list: [],
  29. tab_index: index
  30. })
  31. console.log(index)
  32. if(index==1) {
  33. this.goodsList();
  34. } else {
  35. this.getScore();
  36. }
  37. },
  38. goodsList() {
  39. let _this = this;
  40. let token = wx.getStorageSync('token');
  41. let data = {
  42. token,
  43. page: _this.listPage
  44. };
  45. wx.showLoading();
  46. app.util.ProReq('invitegift.getInvitegiftCouponList', data)
  47. .then(res => {
  48. _this.listLoading = false;
  49. wx.stopPullDownRefresh();
  50. let h = {};
  51. if (_this.listPage == 1) {
  52. h.list = res.data;
  53. res.data.length==0?(h.noData=true):'';
  54. } else {
  55. h.list = [..._this.data.list, ...res.data];
  56. }
  57. if (res.data.length > 0) {
  58. _this.listPage += 1;
  59. } else {
  60. _this.listPage = 0;
  61. }
  62. if(res.data.length < 10) {
  63. h.noMore = true;
  64. }
  65. this.setData(h);
  66. wx.hideLoading();
  67. })
  68. .catch(err => {
  69. wx.hideLoading();
  70. let h = {};
  71. _this.listPage==1?(h.noData=true):'';
  72. this.setData({
  73. listLoading: false,
  74. noMore: true,
  75. ...h,
  76. })
  77. wx.stopPullDownRefresh();
  78. });
  79. },
  80. getScore() {
  81. let token = wx.getStorageSync('token');
  82. app.util.ProReq('invitegift.getInvitegiftPoints', {token})
  83. .then(res=>{
  84. this.setData({
  85. total_points: res.data.total_points
  86. })
  87. })
  88. },
  89. goLink: function(event) {
  90. let link = event.currentTarget.dataset.link;
  91. var pages_all = getCurrentPages();
  92. if (pages_all.length > 3) {
  93. wx.redirectTo({
  94. url: link
  95. })
  96. } else {
  97. wx.navigateTo({
  98. url: link
  99. })
  100. }
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh: function () {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. }
  112. })