// pages/newsList/newsList.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { news: { newsUrl: app.newsUrl, newsDictionaries: [], newsList: [], }, directoriesParentId: 'f497904b-7727-4832-891c-604c36ae4167', currentNewsDictionariesId: '', currentPage: 1, rows: 10 }, doGetNewsDictionariesList: function() { var self = this; app.dialog.loading('正在加载'); app.restAjax.get(app.restAjax.path('{newsUrl}/app/newsdirectories/listnewsdirectoriesrelease', [self.data.news.newsUrl]), { directoriesParentId: self.data.directoriesParentId, }, null, function(code, data) { self.setData({ 'news.newsDictionaries': data }) self.doGetNewsList(1); }, function(code, data) { app.dialog.msg(data.msg); }, function() {}); }, doClickDictionaries: function(event) { var self = this; self.setData({ currentNewsDictionariesId: event.currentTarget.dataset.newsDirectoriesId }); self.doGetNewsList(1); }, doClearCurrentNewsDictionariesId: function() { var self = this; self.setData({ currentNewsDictionariesId: '' }); self.doGetNewsList(1); }, doGetNewsList: function(page) { var self = this; app.dialog.loading('正在加载'); app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease', [self.data.news.newsUrl]), { newsDirectoriesParentId: self.data.directoriesParentId, newsDirectoriesId: self.data.currentNewsDictionariesId ? self.data.currentNewsDictionariesId : '', page: page, rows: self.data.rows }, null, function(code, data) { if(data.rows.length == 0) { app.dialog.msg('暂无数据'); return; } var newsArray; if(page <= 1) { newsArray = data.rows; } else { newsArray = self.data.news.newsList; newsArray = newsArray.concat(data.rows); } self.setData({ currentPage: page, 'news.newsList': newsArray }) }, function(code, data) { app.dialog.msg(data.msg); }, function() { wx.stopPullDownRefresh(); wx.hideLoading(); }); }, goNewsDetail: function (event) { wx.navigateTo({ url: '../newsDetail/newsDetail?templateRecordUrl='+ event.currentTarget.dataset.templateRecordUrl, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var self = this; console.log(options); if(options.type == 1) { self.setData({ directoriesParentId: 'f497904b-7727-4832-891c-604c36ae4167' }); } else { self.setData({ directoriesParentId: 'f1d5d313-f728-4dda-9843-1116d97e17b0' }); } self.doGetNewsDictionariesList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.doGetNewsList(1); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.doGetNewsList(this.data.currentPage + 1); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })