195 lines
4.4 KiB
JavaScript
195 lines
4.4 KiB
JavaScript
|
// pages/newsPage/newsPage.js
|
||
|
const app = getApp()
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
newsUrl: app.newsUrl,
|
||
|
pageId: '',
|
||
|
areaList: [],
|
||
|
typeList: [],
|
||
|
newsList: [],
|
||
|
curType: '',
|
||
|
curArea: '',
|
||
|
page: {
|
||
|
page: 1,
|
||
|
rows: 10,
|
||
|
newsDirectoriesId: '',
|
||
|
county: ''
|
||
|
}
|
||
|
},
|
||
|
getAreaList: function () {
|
||
|
var self = this;
|
||
|
app.restAjax.get(app.restAjax.path(app.usercenterUrl + '/app/dataarea/listareabyparentidrelease/110889', []), {}, null, function (code, data) {
|
||
|
if (code == '200') {
|
||
|
self.setData({
|
||
|
areaList: data
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
changeArea: function (e) {
|
||
|
var item = this.data.page
|
||
|
var lv = parseInt(e.currentTarget.dataset.lv) + 1
|
||
|
lv = 'area' + lv
|
||
|
item.page = 1
|
||
|
item.county = e.currentTarget.dataset.area
|
||
|
item[lv] = e.currentTarget.dataset.area
|
||
|
this.setData({
|
||
|
page: item
|
||
|
})
|
||
|
console.log(this.data.page)
|
||
|
this.getNewsList()
|
||
|
},
|
||
|
getTypeList: function () {
|
||
|
var self = this
|
||
|
app.restAjax.get(app.restAjax.path(app.newsUrl + '/app/newsdirectories/listnewsdirectoriesrelease', []),
|
||
|
{
|
||
|
directoriesParentId: self.data.pageId
|
||
|
}, null, function (code, data) {
|
||
|
if (code == '200') {
|
||
|
self.setData({
|
||
|
typeList: data,
|
||
|
curType: data[0].newsDirectoriesId,
|
||
|
['page.newsDirectoriesId']: data[0].newsDirectoriesId,
|
||
|
})
|
||
|
self.getNewsList()
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
changeType: function (e) {
|
||
|
var self = this
|
||
|
self.setData({
|
||
|
curType: e.currentTarget.dataset.id,
|
||
|
['page.newsDirectoriesId']: e.currentTarget.dataset.id,
|
||
|
['page.page']: 1
|
||
|
})
|
||
|
self.getNewsList()
|
||
|
},
|
||
|
getNewsList: function () {
|
||
|
var self = this
|
||
|
app.restAjax.get(app.restAjax.path(app.newsUrl + '/app/newscontent/listpagenewscontentrelease', []),
|
||
|
self.data.page, null, function (code, data) {
|
||
|
if (code == '200') {
|
||
|
if (self.data.page.page == 1) {
|
||
|
for (let i = 0; i < data.rows.length; i++) {
|
||
|
data.rows[i].newsContentCoverList = data.rows[i].newsContentCoverList[0].contentCoverId
|
||
|
}
|
||
|
self.setData({
|
||
|
newsList: data.rows
|
||
|
})
|
||
|
} else {
|
||
|
if (data.rows.length > 0) {
|
||
|
var arr = self.data.newsList
|
||
|
for (let i = 0; i < data.rows.length; i++) {
|
||
|
data.rows[i].newsContentCoverList = data.rows[i].newsContentCoverList[0].contentCoverId
|
||
|
arr.push(data.rows[i])
|
||
|
}
|
||
|
self.setData({
|
||
|
newsList: arr
|
||
|
})
|
||
|
} else {
|
||
|
self.setData({
|
||
|
['page.page']: self.data.page.page - 1
|
||
|
})
|
||
|
wx.showToast({
|
||
|
title: '暂无更多',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
},
|
||
|
loadAll: function () {
|
||
|
var item = {
|
||
|
page: 1,
|
||
|
rows: 10,
|
||
|
newsDirectoriesId: this.data.curType,
|
||
|
county: ''
|
||
|
}
|
||
|
this.setData({
|
||
|
page: item
|
||
|
})
|
||
|
this.getNewsList()
|
||
|
},
|
||
|
goNewsDetail: function (event) {
|
||
|
if (event.currentTarget.dataset.type == '6') {
|
||
|
wx.navigateTo({
|
||
|
url: '../newsDetail/newsDetail?content='+ event.currentTarget.dataset.content,
|
||
|
})
|
||
|
} else {
|
||
|
wx.navigateTo({
|
||
|
url: '../newsDetail/newsDetail?templateRecordUrl='+ event.currentTarget.dataset.templateRecordUrl,
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
this.setData({
|
||
|
pageId: options.id,
|
||
|
})
|
||
|
this.getAreaList()
|
||
|
this.getTypeList()
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
var self = this
|
||
|
this.setData({
|
||
|
['page.page']: self.data.page.page + 1
|
||
|
})
|
||
|
this.getNewsList()
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|