index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // pages/integral-details/index.js
  2. import {
  3. postSignUser,
  4. getIntegralList
  5. } from '../../api/user.js';
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. parameter: {
  13. 'navbar': '1',
  14. 'return': '1',
  15. 'title': '积分详情',
  16. 'color': true,
  17. 'class': '0'
  18. },
  19. navList: [{
  20. 'name': '分值明细',
  21. 'icon': 'icon-mingxi'
  22. },
  23. {
  24. 'name': '分值提升',
  25. 'icon': 'icon-tishengfenzhi'
  26. }
  27. ],
  28. current: 0,
  29. page: 1,
  30. limit: 10,
  31. integralList: [],
  32. loadend: false,
  33. loading: false,
  34. loadTitle: '加载更多',
  35. },
  36. /**
  37. * 授权回调
  38. */
  39. onLoadFun: function () {
  40. this.getUserInfo();
  41. this.getIntegralList();
  42. },
  43. getUserInfo: function () {
  44. var that = this;
  45. postSignUser({
  46. sign: 1,
  47. integral: 1,
  48. all: 1
  49. }).then(function (res) {
  50. that.setData({
  51. userInfo: res.data
  52. });
  53. });
  54. },
  55. /**
  56. * 获取积分明细
  57. */
  58. getIntegralList: function () {
  59. var that = this;
  60. if (that.data.loading) return;
  61. if (that.data.loadend) return;
  62. that.setData({
  63. loading: true,
  64. loadTitle: ''
  65. });
  66. getIntegralList({
  67. page: that.data.page,
  68. limit: that.data.limit
  69. }).then(function (res) {
  70. var list = res.data,
  71. loadend = list.length < that.data.limit;
  72. that.data.integralList = app.SplitArray(list, that.data.integralList);
  73. that.setData({
  74. integralList: that.data.integralList,
  75. page: that.data.page + 1,
  76. loading: false,
  77. loadend: loadend,
  78. loadTitle: loadend ? '哼~😕我也是有底线的~' : "加载更多"
  79. });
  80. }, function (res) {
  81. that.setData({
  82. loading: false,
  83. loadTitle: '加载更多'
  84. });
  85. });
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {
  91. },
  92. nav: function (e) {
  93. this.setData({
  94. current: e.currentTarget.dataset.idx
  95. })
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. this.getIntegralList();
  102. }
  103. })