city_card/pages/news/newsList.js
2023-07-18 16:54:17 +08:00

101 lines
2.8 KiB
JavaScript

var t = getApp();
Page({
data: {
token: t.globalData.token,
sourceUrl: t.baseUrls.sourceUrl,
newsType: [],
curType: "",
page: {
page: 1,
rows: 10,
newsTypeId: "",
areaCode: ""
},
newsList: [],
serviceUrl: t.baseUrls.serviceUrl,
baseImgUrl: t.baseUrls.baseImgUrl
},
getNewsType: function () {
var a = this;
t.restAjax.get(t.restAjax.path(t.apis.getNewsType, [t.baseUrls.requestUrl]), {
showArea: "6dcbb862-4b48-4dca-aee1-d78fd76adc05"
}, {
headers: {
token: a.data.token
}
}, function (t, s) {
var n;
a.setData({
newsType: s,
"page.newsTypeId": s[0].newsTypeId,
"curType": s[0].newsTypeId
});
a.getNewsList();
}, function (e, t) {
console.log(t);
});
},
changeType: function (t) {
var a, s = t.currentTarget.dataset.id;
this.setData({
curType: s,
"page.newsTypeId": s,
"page.page": 1,
});
this.getNewsList();
},
getNewsList: function () {
var a = this;
t.restAjax.get(t.restAjax.path(t.apis.getNewsList, [t.baseUrls.requestUrl]), a.data.page, {
headers: {
token: a.data.token
}
}, function (t, s) {
for (var n = 0; n < s.rows.length; n++) {
s.rows[n].photo && (s.rows[n].photo = s.rows[n].photo.split(","));
}
if(1==a.data.page.page){
a.setData({
newsList:s.rows
})
}else if(s.rows.length>0){
for (var o = a.data.newsList, r = 0; r < s.rows.length; r++) o.push(s.rows[r]);
a.setData({
newsList: o
});
}else{
wx.showToast({
title: '暂无更多',
icon:'none'
})
a.setData({
"page.page":a.data.page.page-1
})
}
}, function (e, t) {
console.log(t);
});
},
checkDetail: function (e) {
var t = e.currentTarget.dataset.id;
wx.navigateTo({
url: "./newsDetail?newsId=" + t
});
},
onLoad: function (a) {
this.setData({
token: t.globalData.token,
"page.areaCode": wx.getStorageSync("areaCode") ? wx.getStorageSync("areaCode") : ""
})
this.getNewsType();
},
onReachBottom: function () {
this.setData({
"page.page": this.data.page.page + 1,
});
this.getNewsList();
},
});