//获取应用实例 const app = getApp() Page({ /** * 页面的初始数据 */ data: { list: [], page: 1, pageSize: 10, isLastPage: false, tips: '上拉加载更多', windowHeight: app.globalData.windowHeight }, //获取搜索ID的值 searchID: function (e) { this.setData({ searchID: e.detail.value }) }, //点击搜索 searchBtn: function () { wx.showLoading({ title: '加载中', }) var that = this; var searchID = that.data.searchID //获取到用户搜索的ID值 wx.request({ url: 'https://wx.yfzhwlw.com/wechat_equip_search', header: { "Content-Type": "application/x-www-form-urlencoded" }, method: "post", data: { equip_id: searchID, type: '3' }, success: function (res) { //判断当前请求到的数据是否为空 if (res.data.dat.length == '0') { wx.showToast({ title: '暂无该设备,请确定您输入的ID是否有误', icon: 'none', duration: 2000 }) } else { var list = []; for (var i = 0; i < res.data.dat.length; i++) { list.push(res.data.dat[i]); } that.setData({ list: list }); if (res.statusCode != 200) { app.showError() } else { wx.hideLoading() var num = that.data.pageSize //限制数据条数 var nums = res.data.nums var bb = nums / num var aa = Math.ceil(bb) //最后得到的页数 if (aa == that.data.page) { //后端数据条数大于限制数据条数时显示提示 if (res.data.nums >= num) { that.setData({ newData: '0' }) } } } } }, fail: function (res) { app.showError() } }); }, //点击进入测报灯详情 warning: function (e) { var id = e.currentTarget.dataset.id var name = e.currentTarget.dataset.name wx.navigateTo({ url: '../warning_details/warning_details?id=' + id + '&name=' + name, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.requestVideos(1) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.requestVideos(1) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { // 最后一页了,取消下拉功能 if (this.data.isLastPage) { return } this.setData({ page: this.data.page + 1 }) this.requestVideos(this.data.activeIndex) }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, //请求数据 requestVideos: function () { wx.showLoading({ title: '加载中', }) var that = this; wx.getStorage({ key: 'login', success(res) { wx.request({ url: 'https://wx.yfzhwlw.com/wechat_equip_list', header: { "Content-Type": "application/x-www-form-urlencoded" }, method: "post", data: { username: res.data, type: '3', page: that.data.page }, success: function (res) { var list = that.data.list; for (var i = 0; i < res.data.dat.length; i++) { list.push(res.data.dat[i]); } that.setData({ list: list }); if (res.statusCode != 200) { app.showError() } else { wx.hideLoading() var num = that.data.pageSize //限制数据条数 var nums = res.data.nums var bb = nums / num var aa = Math.ceil(bb) //最后得到的页数 if (aa == that.data.page) { //后端数据条数大于限制数据条数时显示提示 if (res.data.nums >= num) { that.setData({ newData: '0' }) } } } }, fail: function (res) { app.showError() } }); } }) }, // 选择menu selector: function (e) { var index = e.currentTarget.dataset.index // 改变当前类,并重置分页数据 this.setData({ activeIndex: index, page: 1, isLastPage: false, tips: '上拉加载更多', list: [] }) this.requestVideos(index) }, // 获取滚动条当前位置 onPageScroll: function (e) { if (e.scrollTop > 100) { this.setData({ floorstatus: true }); } else { this.setData({ floorstatus: false }); } }, //回到顶部 goTop: function (e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } }, })