|
|
|
// pages/billboards/firm/index.js
|
|
|
|
import { BillboardModel } from '../../../models/billboard.js'
|
|
|
|
let billboard = new BillboardModel()
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
list: [],
|
|
|
|
navs: [],
|
|
|
|
curCode: '',
|
|
|
|
currPage: 1,
|
|
|
|
tags: [],
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.fetchTags() // 获取Tags
|
|
|
|
},
|
|
|
|
tapSegemnt (e) {
|
|
|
|
console.log(e.detail)
|
|
|
|
const {index} = e.detail
|
|
|
|
this.setData({
|
|
|
|
curCode: this.data.tags[index].code,
|
|
|
|
currPage: 1,
|
|
|
|
})
|
|
|
|
this.fetchList()
|
|
|
|
},
|
|
|
|
clickCardItem(e) {
|
|
|
|
console.log(e.detail)
|
|
|
|
const { id } = e.detail
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/pages/article/index?id=${id}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchList() {
|
|
|
|
const { curCode } = this.data
|
|
|
|
const page = this.data.currPage
|
|
|
|
billboard.fetchBailList(curCode, page, res => {
|
|
|
|
console.log(res)
|
|
|
|
const datas = res.list
|
|
|
|
let tempDatas = []
|
|
|
|
datas.forEach(item => {
|
|
|
|
tempDatas.push({
|
|
|
|
id: item.id,
|
|
|
|
title: item.title,
|
|
|
|
image: item.titlePic
|
|
|
|
})
|
|
|
|
})
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取分类Tags
|
|
|
|
fetchTags () {
|
|
|
|
billboard.fetchTagsByCode('sc-zdqy', res => {
|
|
|
|
console.log(res)
|
|
|
|
const tags = res.result.records
|
|
|
|
const navs = tags.map(item => item.name)
|
|
|
|
this.setData({
|
|
|
|
navs: navs,
|
|
|
|
tags: tags,
|
|
|
|
curCode: tags.length > 0 ? tags[0].code : ''
|
|
|
|
})
|
|
|
|
this.fetchList()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
this.setData({
|
|
|
|
currPage: 1
|
|
|
|
})
|
|
|
|
this.fetchList()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
const page = this.data.currPage + 1
|
|
|
|
this.setData({
|
|
|
|
currPage: page
|
|
|
|
})
|
|
|
|
this.fetchList()
|
|
|
|
}
|
|
|
|
})
|