city_card/pages/news/newsList.js

101 lines
2.8 KiB
JavaScript
Raw Normal View History

2023-07-18 16:54:17 +08:00
var t = getApp();
2023-07-15 14:25:28 +08:00
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
},
2023-07-18 16:54:17 +08:00
getNewsType: function () {
2023-07-15 14:25:28 +08:00
var a = this;
2023-07-18 16:54:17 +08:00
t.restAjax.get(t.restAjax.path(t.apis.getNewsType, [t.baseUrls.requestUrl]), {
2023-07-15 14:25:28 +08:00
showArea: "6dcbb862-4b48-4dca-aee1-d78fd76adc05"
}, {
headers: {
token: a.data.token
}
2023-07-18 16:54:17 +08:00
}, function (t, s) {
2023-07-15 14:25:28 +08:00
var n;
2023-07-18 16:54:17 +08:00
a.setData({
newsType: s,
"page.newsTypeId": s[0].newsTypeId,
"curType": s[0].newsTypeId
});
a.getNewsList();
}, function (e, t) {
2023-07-15 14:25:28 +08:00
console.log(t);
});
},
2023-07-18 16:54:17 +08:00
changeType: function (t) {
2023-07-15 14:25:28 +08:00
var a, s = t.currentTarget.dataset.id;
2023-07-18 16:54:17 +08:00
this.setData({
curType: s,
"page.newsTypeId": s,
"page.page": 1,
});
this.getNewsList();
2023-07-15 14:25:28 +08:00
},
2023-07-18 16:54:17 +08:00
getNewsList: function () {
2023-07-15 14:25:28 +08:00
var a = this;
2023-07-18 16:54:17 +08:00
t.restAjax.get(t.restAjax.path(t.apis.getNewsList, [t.baseUrls.requestUrl]), a.data.page, {
2023-07-15 14:25:28 +08:00
headers: {
token: a.data.token
}
2023-07-18 16:54:17 +08:00
}, 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){
2023-07-15 14:25:28 +08:00
for (var o = a.data.newsList, r = 0; r < s.rows.length; r++) o.push(s.rows[r]);
a.setData({
newsList: o
});
2023-07-18 16:54:17 +08:00
}else{
wx.showToast({
title: '暂无更多',
icon:'none'
})
a.setData({
"page.page":a.data.page.page-1
})
}
}, function (e, t) {
2023-07-15 14:25:28 +08:00
console.log(t);
});
},
2023-07-18 16:54:17 +08:00
checkDetail: function (e) {
2023-07-15 14:25:28 +08:00
var t = e.currentTarget.dataset.id;
wx.navigateTo({
url: "./newsDetail?newsId=" + t
});
},
2023-07-18 16:54:17 +08:00
onLoad: function (a) {
this.setData({
token: t.globalData.token,
"page.areaCode": wx.getStorageSync("areaCode") ? wx.getStorageSync("areaCode") : ""
})
2023-07-15 14:25:28 +08:00
this.getNewsType();
},
2023-07-18 16:54:17 +08:00
onReachBottom: function () {
this.setData({
"page.page": this.data.page.page + 1,
});
this.getNewsList();
2023-07-15 14:25:28 +08:00
},
});