index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // nova-shop/pages/cates/article-list/index.js
  2. const Parse = getApp().Parse
  3. const company = getApp().globalData.company
  4. const dateF = require('../../../../utils/date.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. title: "热门资讯",
  11. articleList: [],
  12. titles: [],
  13. id: []
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. // category
  19. onLoad: function(options) {
  20. console.log(options)
  21. this.setData({
  22. title: options.title
  23. })
  24. let cid = options.cid
  25. this.getArticle(cid)
  26. },
  27. textClick(e) {
  28. let that = this;
  29. console.log(e)
  30. let item = e.currentTarget.dataset.item
  31. wx.navigateTo({
  32. url: `/common-page/pages/cates/article-detail/index?title=${item.title}&aid=${item.objectId}`
  33. });
  34. },
  35. async getArticle(cid) {
  36. let Article = new Parse.Query('Article')
  37. Article.equalTo('category', cid);
  38. Article.equalTo('company', company);
  39. Article.equalTo('isEnabled', true);
  40. Article.select('image', 'title', 'createdAt', 'objectId', 'publishDate')
  41. let res = await Article.find();
  42. let articleList = [];
  43. res.forEach(log => {
  44. let logs = log.toJSON();
  45. logs.date = logs.publishDate ? dateF.formatTime("YYYY-mm-dd", logs.publishDate.iso) : dateF.formatTime("YYYY-mm-dd", logs.createdAt)
  46. articleList.push(logs);
  47. });
  48. console.log(articleList, )
  49. this.setData({
  50. articleList: articleList
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function() {
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function() {
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function() {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function() {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function() {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function() {
  82. },
  83. /**
  84. * 用户点击右上角分享
  85. */
  86. onShareAppMessage: function() {
  87. }
  88. })