143 lines
2.7 KiB
JavaScript
143 lines
2.7 KiB
JavaScript
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
boundingSize: wx.getMenuButtonBoundingClientRect(),
|
|
siteList: [],
|
|
currentPage: 1,
|
|
isLastPage: false,
|
|
siteName: ''
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.getSiteList()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
// 获取列表
|
|
getSiteList: function (siteName = '', page = 1) {
|
|
const url = `/mobile/get_data`
|
|
app.AppService.appRequest(url, 'POST', {
|
|
page: page,
|
|
page_len: app.globalData.pageLen,
|
|
site_name: siteName || this.data.siteName,
|
|
data_type: 'data-03'
|
|
}, (res) => {
|
|
const lastSiteList = this.data.siteList || []
|
|
let siteList = res.data.result || []
|
|
const len = siteList.length
|
|
// 不是第一页
|
|
if (page > 1) {
|
|
// 有下一页
|
|
if (len > 0) {
|
|
siteList = lastSiteList.concat(siteList)
|
|
this.setData({
|
|
isLastPage: false
|
|
})
|
|
} else {
|
|
siteList = lastSiteList
|
|
this.setData({
|
|
isLastPage: true
|
|
})
|
|
}
|
|
}
|
|
this.setData({
|
|
siteList,
|
|
currentPage: page,
|
|
})
|
|
})
|
|
},
|
|
|
|
// 滚动到底部获取更多
|
|
getMoreList: function () {
|
|
const siteName = this.data.siteName || ''
|
|
if (!this.data.isLastPage) {
|
|
this.getSiteList(siteName, this.data.currentPage + 1)
|
|
}
|
|
},
|
|
|
|
// 选择工地
|
|
selectSite: function (e) {
|
|
const id = e.currentTarget.dataset.id
|
|
const item = e.currentTarget.dataset.item
|
|
let pages = getCurrentPages() // 获取页面栈
|
|
let currPage = pages[pages.length - 1] // 当前页面
|
|
let prevPage = pages[pages.length - 2] // 上一个页面
|
|
console.log(id)
|
|
prevPage.setData({
|
|
siteId: id,
|
|
siteDetail: item
|
|
})
|
|
wx.navigateBack()
|
|
},
|
|
|
|
|
|
// 监听搜索输入
|
|
listenSearch: function (e) {
|
|
this.getSiteList(e.detail.value)
|
|
},
|
|
|
|
// 输入失去焦点才setData
|
|
searchBlur: function (e) {
|
|
this.setData({
|
|
siteName: e.detail.value
|
|
})
|
|
},
|
|
|
|
// 跳转页面
|
|
navigateTo: function (e) {
|
|
const url = e.currentTarget.dataset.url
|
|
wx.navigateTo({
|
|
url: url,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
|
|
}) |