You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.5 KiB
116 lines
2.5 KiB
// pages/billboards/policy/index.js
|
|
import {PolicyModel} from '../../../models/policy.js'
|
|
import dayjs from '../../../utils/dayjs/index.js'
|
|
let policy = new PolicyModel()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
list: [],
|
|
currPage: 1,
|
|
searchKey: '',
|
|
tags: [],
|
|
},
|
|
clickListItem(e) {
|
|
const {id} = e.detail
|
|
wx.navigateTo({
|
|
url: `/pages/article/index?id=${id}`,
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.fetchPolicyTags()
|
|
this.fetchPolicyList()
|
|
},
|
|
onSearchClear (e) {
|
|
this.setData({
|
|
currPage: 1,
|
|
searchKey: ''
|
|
})
|
|
//console.log(e)
|
|
this.fetchPolicyList()
|
|
},
|
|
onSearchInput (e) {
|
|
const key = e.detail.value
|
|
this.setData({
|
|
searchKey: key,
|
|
currPage: 1,
|
|
})
|
|
//console.log(e)
|
|
this.fetchPolicyList()
|
|
},
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
this.setData({
|
|
currPage: 1
|
|
})
|
|
this.fetchPolicyList()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
const page = this.data.currPage + 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
this.fetchPolicyList()
|
|
},
|
|
// 获取 Tags
|
|
fetchPolicyTags () {
|
|
policy.fetchPolicyTags(res => {
|
|
const datas = res.result.records
|
|
this.setData({
|
|
tags: datas
|
|
})
|
|
wx.setStorageSync('PolicyTags', datas)
|
|
})
|
|
},
|
|
// 获取列表,搜索列表
|
|
fetchPolicyList () {
|
|
const {searchKey} = this.data
|
|
const page = this.data.currPage
|
|
policy.fetchPolicyList(page, searchKey, res => {
|
|
//console.log(res)
|
|
const datas = res.list
|
|
let tempDatas = []
|
|
datas.forEach(item => {
|
|
tempDatas.push({
|
|
id: item.id,
|
|
title: item.title,
|
|
showTop: item.isTop == 1 ? true : false,
|
|
time: dayjs(item.createTime).toNow(),
|
|
})
|
|
})
|
|
if (page == 1) {
|
|
this.setData({
|
|
list: tempDatas
|
|
})
|
|
} else {
|
|
if (tempDatas.length > 0) {
|
|
const list = [...this.data.list, ...tempDatas]
|
|
this.setData({
|
|
list: list
|
|
})
|
|
} else {
|
|
const page = this.data.currPage - 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
wx.showToast({
|
|
title: '已加载全部',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
}
|
|
})
|