new-list.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // pages/new-list/new-list.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. swiperCurrent: 0,
  9. indicatorDots: false,
  10. interval: 5000,
  11. duration: 1000,
  12. first:0,
  13. limit:8,
  14. newList:[],
  15. bannerList: [],
  16. hotList: [],
  17. title: '加载中···',
  18. hidden: true,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. app.setBarColor();
  25. app.setUserInfo();
  26. this.getNewList();
  27. this.getArticleBanner();
  28. this.getArticleHot();
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow: function () {
  39. },
  40. getArticleBanner: function () {
  41. var that = this;
  42. wx.request({
  43. url: app.globalData.url + '/routine/auth_api/get_article_banner?uid=' + app.globalData.uid,
  44. method: 'GET',
  45. success: function (res) {
  46. that.setData({
  47. bannerList: res.data.data
  48. })
  49. }
  50. })
  51. },
  52. getArticleHot:function(){
  53. var that = this;
  54. wx.request({
  55. url: app.globalData.url + '/routine/auth_api/get_article_hot?uid=' + app.globalData.uid,
  56. method: 'GET',
  57. success: function (res) {
  58. that.setData({
  59. hotList: res.data.data
  60. })
  61. }
  62. })
  63. },
  64. getNewList:function(){
  65. var that = this;
  66. wx.request({
  67. url: app.globalData.url + '/routine/auth_api/get_cid_article?uid=' + app.globalData.uid,
  68. method: 'GET',
  69. data: {
  70. cid : 0,
  71. first: that.data.first,
  72. limit: that.data.limit
  73. },
  74. success: function (res) {
  75. that.setData({
  76. newList:res.data.data
  77. })
  78. }
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function (p) {
  100. var that = this;
  101. that.setData({
  102. hidden: false,
  103. })
  104. var limit = that.data.limit;
  105. var offset = that.data.first;
  106. if (!offset) offset = 1;
  107. var startpage = limit * offset;
  108. wx.request({
  109. url: app.globalData.url + '/routine/auth_api/get_cid_article?uid=' + app.globalData.uid,
  110. data: { cid:0,limit: limit, first: startpage },
  111. method: 'GET',
  112. success: function (res) {
  113. var len = res.data.data.length;
  114. for (var i = 0; i < len; i++) {
  115. that.data.newList.push(res.data.data[i])
  116. }
  117. that.setData({
  118. first: offset + 1,
  119. newList: that.data.newList
  120. })
  121. if (len < limit) {
  122. that.setData({
  123. title: "数据已经加载完成",
  124. });
  125. }
  126. },
  127. fail: function (res) {
  128. console.log('submit fail');
  129. },
  130. complete: function (res) {
  131. console.log('submit complete');
  132. }
  133. })
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })