164 lines
3.4 KiB
JavaScript
164 lines
3.4 KiB
JavaScript
// pages/list/list.js
|
|
|
|
const request = require('../../utils/request')
|
|
const ui = require('../../utils/ui')
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
searchName : "",
|
|
title:"搜索",
|
|
total_count: 0,
|
|
total_pages: 0,
|
|
has_next: false,
|
|
has_next: false,
|
|
current_page: 1,
|
|
list: [],
|
|
|
|
scrollHeight:0
|
|
},
|
|
|
|
|
|
jumpPage(e) {
|
|
let jumpType = e.currentTarget.dataset.jumptype;
|
|
let aid = e.currentTarget.dataset.aid;
|
|
console.log(jumpType == 2);
|
|
if (jumpType == 2) {
|
|
wx.navigateTo({
|
|
url: "/pages/details/details?aid=" +aid
|
|
})
|
|
}
|
|
// wx.navigateTo({
|
|
// url: this.data.category[index].url
|
|
// })
|
|
},
|
|
|
|
|
|
|
|
|
|
GetList() {
|
|
let that = this;
|
|
request.request({
|
|
method: "GET",
|
|
url: "/api.php/doc/list?keyword=" + that.data.searchName + "&pageSize=16&page=" + that.data.current_page
|
|
}).then(res => {
|
|
if (res.data.code === 1) {
|
|
that.setData({
|
|
list: that.data.list.concat(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')
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 设置列表高度
|
|
*/
|
|
setListHeight: function () {
|
|
let that = this;
|
|
const windowInfo = wx.getWindowInfo()
|
|
that.setData({
|
|
scrollHeight: windowInfo.windowHeight - 90,
|
|
});
|
|
// wx.getSystemInfo({
|
|
// success: function (res) {
|
|
// that.setData({
|
|
// scrollHeight: res.windowHeight - 90,
|
|
// });
|
|
// }
|
|
// });
|
|
},
|
|
|
|
|
|
/**
|
|
* 下拉到底加载数据
|
|
*/
|
|
bindDownLoad() {
|
|
let that = this;
|
|
// 已经是最后一页
|
|
if (that.data.has_next) {
|
|
that.setData({
|
|
current_page: that.data.current_page + 1
|
|
});
|
|
this.GetList();
|
|
}
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
let that = this;
|
|
if (!options.search) {
|
|
wx.navigateBack()
|
|
this.triggerEvent('onBack')
|
|
}
|
|
console.log(options);
|
|
that.setData({searchName:options.search})
|
|
that.setListHeight()
|
|
that.GetList()
|
|
// that.data.searchName = options.search;
|
|
// if (that.sea)
|
|
// console.log(options);
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |