Files
doc-mini-app/pages/list/list.js
2024-08-24 17:38:03 +08:00

181 lines
3.2 KiB
JavaScript

// pages/list/list.js
const request = require('../../utils/request')
const ui = require('../../utils/ui')
Page({
/**
* 页面的初始数据
*/
data: {
categoryName: "",
categoryId: 0,
total_count: 0,
total_pages: 0,
has_next: false,
has_next: false,
current_page: 1,
list: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let that = this;
if (!options.cid) {
wx.navigateBack()
this.triggerEvent('onBack')
}
that.setData({
categoryId: options.cid
})
that.GetCategoryInfo()
that.GetList()
},
GetCategoryInfo() {
let that = this;
request.request({
method: "GET",
url: "/api.php/doc/category_info?cid=" + that.data.categoryId
}).then(res => {
if (res.data.code === 1) {
that.setData({
categoryName: res.data.data.data.name,
categoryId: res.data.data.data.scode,
})
}
}).catch(err => {
console.log('ERROR')
});
},
GetList() {
let that = this;
request.request({
method: "GET",
url: "/api.php/doc/list?cid=" + that.data.categoryId + "&pageSize=16"
}).then(res => {
if (res.data.code === 1) {
that.setData({
list: res.data.data.data,
current_page: res.data.data.current_page,
has_next: res.data.data.has_next,
has_prev: res.data.data.has_prev,
total_count: res.data.data.total_count,
total_pages: res.data.data.total_pages,
})
}
// ui.showToast(res.data.errorMsg)
}).catch(err => {
console.log('ERROR')
});
},
jumpPage(e) {
let jumpType = e.currentTarget.dataset.jumptype;
console.log(jumpType == 2);
if (jumpType == 2) {
wx.navigateTo({
url: "/pages/details/details?id=1"
})
}
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
console.log(111);
// if (this.data.has_next) {
// that.setData({
// current_page: this.current_page + 1
// })
// //加载下一页
// this.GetList();
// } else {
// ui.showToast({
// icon: "none",
// title: '没有更多数据了'
// })
// }
},
loadData: function () {
wx.request({
url: 'http://test.com', //假的后台接口
method: 'POST',
data: {
pageSize: this.pageSize,
pageNum: this.pageNum,
},
success: function (res) {
this.pageNum = res.data.content.pageNum;
this.totalPage = res.data.content.totalPageNum;
this.resultData = res.data.content.rows;
},
fail: function (res) {
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})