租房掌柜微信小程序Api以及小程序前端模板
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.
 
 
 
 
 
 

124 lines
2.6 KiB

var app = getApp();
var netUtil = require("../../../utils/requestUtil.js"); //require引入
Page({
/**
* 页面的初始数据
*/
data: {
dataList: [],
page: 1,
pages: 0,
detailUrl: '/pages/house/view/index',
search:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
this.getDataList(1, true);
},
formSubmit: function(e) {
const params = e.detail.value
this.setData({
search: params.search
})
//执行搜索查询
this.getDataList(1, true)
},
//获取数据列表
getDataList: function(pageNum, override) {
this.loading = true;
var self = this;
var url = app.globalData.requestUrl + 'index/house/index?pagesize=7&page=' + pageNum;
var search = this.data.search;
if (search != undefined) {
url += '&search=' + search
}
return netUtil.sendGet(url)
.then((res) => {
if (res.statusCode == 200 && res.data.code == 200) {
var data = res.data.data
this.setData({
pages: data.pages,
page: pageNum,
//override 为true 则直接覆盖 否则上拉追加数据
dataList: override ? data.list : self.data.dataList.concat(data.list)
})
} else {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 3000
})
}
}).then(() => {
this.loading = false;
})
},
//上拉加载数据
onReachBottom: function() {
// 下拉触底,先判断是否有请求正在进行中
// 以及检查当前请求页数是不是小于数据总页数,如符合条件,则发送请求
if (!this.loading && this.data.page < this.data.pages) {
this.getDataList(this.data.page + 1,false);
}
},
//下拉刷新
onPullDownRefresh: function() {
if (!this.loading) {
this.getDataList(1, true).then(() => {
wx.stopPullDownRefresh()
})
}
},
//点击详情
toDetail: function(e) {
var id = e.currentTarget.dataset.id;
wx.navigateTo({
url: this.data.detailUrl + '?id=' + id,
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})