xz_bailang/pages/newsList/newsList.js

141 lines
4.3 KiB
JavaScript
Raw Normal View History

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-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);
},
function () {});
},
doClickDictionaries: function (event) {
var self = this;
console.log(event.currentTarget.dataset.newsDirectoriesId)
self.setData({
currentNewsDictionariesId: event.currentTarget.dataset.newsDirectoriesId
});
self.doGetNewsList(1);
},
//获取新闻
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
}
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
})
console.log(self.data.news.newsList)
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
2023-02-24 18:15:58 +08:00
})
},
getAreaList: function () {
var self = this;
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)
},
//加载全部类型
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();
},
2020-06-26 12:33:13 +08:00
})