2020-06-26 12:33:13 +08:00
|
|
|
// pages/newsList/newsList.js
|
|
|
|
var app = getApp();
|
|
|
|
Page({
|
2023-02-24 18:15:58 +08:00
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
news: {
|
|
|
|
newsUrl: app.newsUrl,
|
|
|
|
newsDictionaries: [],
|
|
|
|
newsList: [],
|
|
|
|
},
|
|
|
|
dirId: '', //tab Id
|
|
|
|
currentNewsDictionariesId: '',
|
|
|
|
currentPage: 1,
|
|
|
|
rows: 10,
|
|
|
|
areaId: app.areaCode,
|
|
|
|
defaultAreaId: app.areaCode
|
2020-06-26 12:33:13 +08:00
|
|
|
},
|
2023-03-01 16:33:12 +08:00
|
|
|
//获取下级子目录
|
2023-02-24 18:15:58 +08:00
|
|
|
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);
|
|
|
|
},
|
2023-07-11 14:33:19 +08:00
|
|
|
function () { });
|
2023-02-24 18:15:58 +08:00
|
|
|
},
|
|
|
|
doClickDictionaries: function (event) {
|
|
|
|
var self = this;
|
|
|
|
console.log(event.currentTarget.dataset.newsDirectoriesId)
|
|
|
|
self.setData({
|
|
|
|
currentNewsDictionariesId: event.currentTarget.dataset.newsDirectoriesId
|
|
|
|
});
|
|
|
|
self.doGetNewsList(1);
|
|
|
|
},
|
2023-03-01 16:33:12 +08:00
|
|
|
//获取新闻
|
2023-02-24 18:15:58 +08:00
|
|
|
doGetNewsList: function (page, lv) {
|
|
|
|
var self = this;
|
|
|
|
app.dialog.loading('正在加载');
|
|
|
|
var info = {
|
|
|
|
page: page,
|
|
|
|
rows: self.data.rows
|
2020-08-06 16:49:55 +08:00
|
|
|
}
|
2023-03-01 16:33:12 +08:00
|
|
|
if (self.data.currentNewsDictionariesId == self.data.dirId) {
|
|
|
|
info.newsDirectoriesParentId = self.data.dirId;
|
|
|
|
} else {
|
|
|
|
info.newsDirectoriesId = self.data.currentNewsDictionariesId;
|
|
|
|
}
|
2023-02-24 18:15:58 +08:00
|
|
|
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({
|
2023-03-15 17:58:44 +08:00
|
|
|
url: '../newsDetail/newsDetail?id=' + event.currentTarget.dataset.item.newsContentId
|
2023-02-24 18:15:58 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
getAreaList: function () {
|
|
|
|
var self = this;
|
2023-03-01 16:33:12 +08:00
|
|
|
app.restAjax.get(app.restAjax.path(app.usercenterUrl + '/app/area/listbyparentidrelease/' + app.areaId, []),
|
2023-02-24 18:15:58 +08:00
|
|
|
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)
|
|
|
|
},
|
2023-03-01 16:33:12 +08:00
|
|
|
//加载全部类型
|
|
|
|
doClearCurrentNewsDictionariesId: function () {
|
|
|
|
var self = this;
|
|
|
|
self.setData({
|
|
|
|
currentNewsDictionariesId: self.data.dirId
|
|
|
|
});
|
|
|
|
self.doGetNewsList(1);
|
|
|
|
},
|
|
|
|
//加载全部地区
|
2023-02-24 18:15:58 +08:00
|
|
|
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();
|
|
|
|
},
|
2023-07-11 14:33:19 +08:00
|
|
|
onReachBottom() {
|
|
|
|
this.setData({
|
|
|
|
currentPage: this.data.currentPage + 1
|
|
|
|
})
|
|
|
|
this.doGetNewsList(this.data.currentPage)
|
|
|
|
}
|
2020-06-26 12:33:13 +08:00
|
|
|
|
|
|
|
})
|