index.js 2.7 KB

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