city_card/pages/news/newsList.js
2023-07-15 14:25:28 +08:00

86 lines
2.8 KiB
JavaScript

var e = require("../../@babel/runtime/helpers/defineProperty"), 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((e(n = {
newsType: s
}, "page.newsTypeId", s[0].newsTypeId), e(n, "curType", s[0].newsTypeId), n)), a.getNewsList();
}, function(e, t) {
console.log(t);
});
},
changeType: function(t) {
var a, s = t.currentTarget.dataset.id;
this.setData((e(a = {
curType: s
}, "page.newsTypeId", s), e(a, "page.page", 1), a)), 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(e({}, "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(e({
token: t.globalData.token
}, "page.areaCode", wx.getStorageSync("areaCode") ? wx.getStorageSync("areaCode") : "")),
this.getNewsType();
},
onReady: function() {},
onShow: function() {},
onHide: function() {},
onUnload: function() {},
onPullDownRefresh: function() {},
onReachBottom: function() {
this.setData(e({}, "page.page", this.data.page.page + 1)), this.getNewsList();
},
onShareAppMessage: function() {}
});