// pages/newsList/newsList.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { news: { newsUrl: app.newsUrl, newsDictionaries: [], newsList: [], }, dirId: '', //tab Id currentNewsDictionariesId: '', currentPage: 1, rows: 10, areaId: app.areaCode, defaultAreaId: app.areaCode }, //获取下级子目录 doGetNewsDictionariesList: function () { var self = this; app.dialog.loading('正在加载'); app.restAjax.get(app.restAjax.path('{newsUrl}/app/newsdirectories/listsub/areaauth/release/{newsDirectoriesId}/{areaCode}', [self.data.news.newsUrl, self.data.dirId, app.areaCode]), null, null, function (code, data) { self.setData({ 'news.newsDictionaries': data, currentNewsDictionariesId: self.data.dirId }) self.doGetNewsList(1); }, function (code, data) { app.dialog.msg(data.msg); }, function () { }); }, doClickDictionaries: function (event) { var self = this; console.log(event.currentTarget.dataset.newsDirectoriesId) self.setData({ currentNewsDictionariesId: event.currentTarget.dataset.newsDirectoriesId }); self.doGetNewsList(1); }, //获取新闻 doGetNewsList: function (page, lv) { var self = this; app.dialog.loading('正在加载'); var info = { page: page, rows: self.data.rows } if (self.data.currentNewsDictionariesId == self.data.dirId) { info.newsDirectoriesParentId = self.data.dirId; } else { info.newsDirectoriesId = self.data.currentNewsDictionariesId; } var tempAreaCode = app.areaCode; if (lv) { tempAreaCode = self.data.areaId; } app.restAjax.get(app.restAjax.path('{newsUrl}/app/newscontent/listpagenewscontentrelease/{areaCode}', [self.data.news.newsUrl, tempAreaCode]), info, null, function (code, data) { 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 }) if (data.rows.length == 0) { app.dialog.msg('暂无数据'); return; } }, function (code, data) { app.dialog.msg(data.msg); }, function () { wx.stopPullDownRefresh(); wx.hideLoading(); }); }, goNewsDetail: function (event) { wx.navigateTo({ url: '../newsDetail/newsDetail?id=' + event.currentTarget.dataset.item.newsContentId }) }, getAreaList: function () { var self = this; app.restAjax.get(app.restAjax.path(app.usercenterUrl + '/app/area/listbyparentidrelease/' + app.areaId, []), self.data.pages, null, function (code, data) { if (code == '200') { self.setData({ areaList: data }) } } ) }, changeArea: function (e) { app.dialog.loading('正在加载'); var lv = parseInt(e.currentTarget.dataset.level) + 1 this.setData({ areaId: e.currentTarget.dataset.area }) this.doGetNewsList(1, lv) }, //加载全部类型 doClearCurrentNewsDictionariesId: function () { var self = this; self.setData({ currentNewsDictionariesId: self.data.dirId }); self.doGetNewsList(1); }, //加载全部地区 loadAll: function () { this.setData({ areaId: app.areaCode }) this.doGetNewsList(1) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var self = this; self.setData({ dirId: options.id }) self.doGetNewsDictionariesList(); self.getAreaList(); }, onReachBottom() { this.setData({ currentPage: this.data.currentPage + 1 }) this.doGetNewsList(this.data.currentPage) } })