recent-news.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // pages/recent-news/recent-news.js
  2. var http = require("../../utils/http.js");
  3. var config = require("../../utils/config.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. news: [],
  10. distNews: [] // 分销公告
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. console.log(options)
  17. this.setData({
  18. isDist: options.isDist
  19. })
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady: function() {
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow: function() {
  30. var ths = this;
  31. if (this.data.isDist == 'true') {
  32. // 加载分销的公告
  33. var params = {
  34. url: "/p/distribution/msg/page",
  35. method: "GET",
  36. data: {},
  37. callBack: function(res) {
  38. console.log(res);
  39. ths.setData({
  40. distNews: res.records,
  41. });
  42. }
  43. };
  44. http.request(params);
  45. } else {
  46. //加载普通公告
  47. var params = {
  48. url: "/shop/notice/noticeList/0",
  49. method: "GET",
  50. data: {},
  51. callBack: function(res) {
  52. // console.log(res);
  53. ths.setData({
  54. news: res.records,
  55. });
  56. }
  57. };
  58. http.request(params);
  59. }
  60. },
  61. // 跳转公告详情页
  62. toNewsDetail: function(e) {
  63. console.log(e)
  64. var id = e.currentTarget.dataset.id
  65. var type = e.currentTarget.dataset.type
  66. if (type == 'dist') {
  67. wx.navigateTo({
  68. url: '/pages/news-detail/news-detail?id=' + e.currentTarget.dataset.id + '&type=' + type,
  69. })
  70. } else {
  71. wx.navigateTo({
  72. url: '/pages/news-detail/news-detail?id=' + e.currentTarget.dataset.id,
  73. })
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面隐藏
  78. */
  79. onHide: function() {
  80. },
  81. /**
  82. * 生命周期函数--监听页面卸载
  83. */
  84. onUnload: function() {
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function() {
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom: function() {
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function() {
  100. }
  101. })