119 lines
2.5 KiB
JavaScript
119 lines
2.5 KiB
JavaScript
// pages/lianxi/index.js
|
|
const api = require("../../utils/request.js");
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
results: [
|
|
// {id:1,title:"开发需求",is_top:true,ifrom:"第一条咨询",update_time:"2022-10-01"}
|
|
],
|
|
type_: {1:"技能大赛",2:"铺装工匠",3:"培训信息",4:"大赛信息"},
|
|
typeData:[{name:'培训信息',value:3},{name:'大赛信息',value:4}],//{1:"技能大赛",2:"铺装工匠",3:"培训信息",4:"大赛信息"},
|
|
count:0,
|
|
query: {
|
|
page: 1,
|
|
limit: 10,
|
|
type:3
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function () {
|
|
var that = this
|
|
wx.stopPullDownRefresh();
|
|
that.getList(that.data.query)
|
|
},
|
|
//tap切换
|
|
typeChange(e){
|
|
this.setData({
|
|
['query.type']:e.target.dataset.type,
|
|
['query.page']:1
|
|
})
|
|
this.data.query.type = e.target.dataset.type
|
|
this.getList();
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
},
|
|
getList: function () {
|
|
var that = this
|
|
|
|
api.request('/cms/article/', 'GET', that.data.query).then(res => {
|
|
if (that.data.query.page == 1) {
|
|
that.data.results = res.data.results
|
|
} else {
|
|
that.data.results = that.data.results.concat(res.data.results)
|
|
}
|
|
for(var i = 0;i<that.data.results.length;i++){
|
|
that.data.results[i].update_time = that.data.results[i].update_time.substring(0,10)
|
|
}
|
|
that.setData({
|
|
results: that.data.results,
|
|
count: res.data.count
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
var that = this
|
|
that.data.query.page = 1;
|
|
that.getList();
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
var that = this
|
|
if (that.data.count <= that.data.query.page * that.data.query.limit) {
|
|
wx.showToast({
|
|
title: '没有更多了',
|
|
icon: 'none'
|
|
})
|
|
} else {
|
|
that.data.query.page = that.data.query.page + 1
|
|
that.getList()
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
},
|
|
|
|
}) |