index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // pages/message/index.js
  2. import { getProductHot } from '../../api/store.js';
  3. import { getMessages } from "../../api/message"
  4. import { SplitArray } from "../../utils/util"
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. parameter: {
  12. title: "我的消息",
  13. 'navbar': '1',
  14. 'return': '1',
  15. 'color': false,
  16. },
  17. host_product:[],
  18. iShidden: false,
  19. page: 0,
  20. messages: []
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. wx.setTabBarBadge({
  27. index: 2,
  28. text: '9'
  29. });
  30. console.log("load");
  31. if (app.globalData.token) this.setData({ iShidden:true});
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. onLoadFun: function() {
  39. this.get_host_product();
  40. this.refreshNotifications();
  41. },
  42. /**
  43. * 生命周期函数--监听页面显示
  44. */
  45. onShow: function () {
  46. if (app.globalData.isLog) {
  47. this.data.page = 1;
  48. this.get_host_product();
  49. this.pullMessageList();
  50. this.setData({
  51. iShidden: true
  52. });
  53. }
  54. },
  55. refreshNotifications: function() {
  56. var that = this;
  57. getNotifications().then(res=>{
  58. console.log(res);
  59. }, err=> {
  60. console.log(err);
  61. // that.setData({
  62. // messages: [ 1 ]
  63. // });
  64. });
  65. },
  66. /**
  67. * 获取我的推荐
  68. */
  69. get_host_product:function(){
  70. var that=this;
  71. getProductHot().then(res=>{
  72. that.setData({ host_product: res.data });
  73. })
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. console.log("unload");
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function () {
  90. setTimeout(function() {
  91. wx.stopPullDownRefresh({
  92. success: (res) => {
  93. console.log("success stop")
  94. },
  95. });
  96. }, 300);
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. console.log("load more");
  103. this.data.page ++;
  104. this.pullMessageList();
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. },
  111. pullMessageList() {
  112. var that = this;
  113. getMessages(that.data.page).then(res=>{
  114. that.setData({
  115. messages: SplitArray(that.data.messages, res.messages)
  116. });
  117. }, err=> {
  118. });
  119. }
  120. })