index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. "id": 1,
  23. "icon": "/images/one.png",
  24. "from": "系统消息",
  25. "subject": "优惠活动",
  26. "body": "<p>here is html code</p><p style='color:red;'>some code</p>",
  27. "ts": "2021/3/12 12:43:12",
  28. "expiresAt": 1234354545,
  29. "type": 0,
  30. "read": 0
  31. },{
  32. "id": 1,
  33. "icon": "/images/two.png",
  34. "from": "美天旺客服",
  35. "subject": "退货通知",
  36. "body": "<p>here is html code</p><p style='color:red;'>some code</p>",
  37. "ts": "2021/3/12 12:43:12",
  38. "expiresAt": 1234354545,
  39. "type": 0,
  40. "read": 0
  41. }]
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. wx.setTabBarBadge({
  48. index: 2,
  49. text: '9'
  50. });
  51. console.log("load");
  52. if (app.globalData.token) this.setData({ iShidden:true});
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. onLoadFun: function() {
  60. this.pullMessageList();
  61. this.get_host_product();
  62. this.refreshNotifications();
  63. },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {
  68. if (app.globalData.isLog) {
  69. this.data.page = 1;
  70. this.get_host_product();
  71. this.pullMessageList();
  72. this.setData({
  73. iShidden: true
  74. });
  75. }
  76. },
  77. refreshNotifications: function() {
  78. var that = this;
  79. getNotifications().then(res=>{
  80. console.log(res);
  81. }, err=> {
  82. console.log(err);
  83. // that.setData({
  84. // messages: [ 1 ]
  85. // });
  86. });
  87. },
  88. /**
  89. * 获取我的推荐
  90. */
  91. get_host_product:function(){
  92. var that=this;
  93. getProductHot().then(res=>{
  94. that.setData({ host_product: res.data });
  95. })
  96. },
  97. /**
  98. * 生命周期函数--监听页面隐藏
  99. */
  100. onHide: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面卸载
  104. */
  105. onUnload: function () {
  106. console.log("unload");
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function () {
  112. var that = this;
  113. wx.stopPullDownRefresh({
  114. success: (res) => {
  115. setTimeout(function() {
  116. console.log("success stop")
  117. that.data.page = 1;
  118. that.pullMessageList();
  119. }, 300);
  120. },
  121. });
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. console.log("load more");
  128. this.data.page ++;
  129. this.pullMessageList();
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. },
  136. pullMessageList() {
  137. var that = this;
  138. getMessages(that.data.page).then(res=>{
  139. that.setData({
  140. messages: SplitArray(that.data.messages, res.messages)
  141. });
  142. }, err=> {
  143. });
  144. },
  145. tabClick(e) {
  146. wx.navigateTo({
  147. url: '/pages/message_details/index?data=' + base64.encode(JSON.stringify(e.currentTarget.dataset.items)),
  148. });
  149. }
  150. })