// pages/monitor/monitor.js const api = require('../../api/index') Page({ /** * 页面的初始数据 */ data: { tableData:[], queryParams:{ current:1, size:10 }, total:0, menu:[ { label:'监控记录', method:'monitoringRecord' } ], triggered:false, load:false, hasMore:true, showPopup:false, changeFollow:false, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { this.init() }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 页面功能 */ //关注和监控 closePopup(e){ this.setData( { showPopup:false } ) wx.nextTick(() => { this.setData({ changeFollow: false }) // 在当前同步流程结束后,下一个时间片执行 }) }, openPopup(e){ console.log(e) this.setData( { showPopup:true } ) if(e.detail && e.detail.changeFollow){ this.setData( { changeFollow:true } ) } }, attention(e){ const childComponent = this.selectComponent('#myProduct'); if (childComponent) { childComponent.attention(e); // 调用子组件的方法 } }, cancelFollow(e){ const childComponent = this.selectComponent('#myProduct'); // var {type} = e.detail if (childComponent) { childComponent.cancelFollow(e); // 调用子组件的方法 } }, //初始化加载 init(){ var params = { current:1, size:10 } this.setData( { queryParams:params, total:0, tableData:[], hasMore:true } ) this.getMyMonitor() }, //下拉刷新 onRefresh() { console.log('onRefresh') this.setData({ triggered: true, }) this.init() }, //获取监控产品 getMyMonitor(type){ var params = { ...this.data.queryParams } wx.showLoading({ title: '加载中', }) api.selectMonitoring(params).then(res=>{ if(res.code == 200){ var data = this.data.tableData wx.hideLoading() if(type){ var startIndex = (this.data.queryParams.current-1)*this.data.queryParams.size var endIndex = data.length var len = endIndex - startIndex data.splice(startIndex,len,...res.data.data) }else{ data = data.concat(res.data.data) } this.setData( { tableData:data, total:res.data.total, triggered: false, load:false } ) if(this.data.total<=data.length){ this.setData({ hasMore:false }) } api.notify( { type:'success', message:'查询成功', top:wx.getStorageSync('height') } ) } }).catch(error=>{ wx.hideLoading() this.setData({ triggered: false, load:false }) }) }, //加载更多 loadMore(){ var current = this.data.queryParams.current this.setData( { ['queryParams.current']:current+1, load:true } ) this.getMyMonitor() }, //取消监控 cancelMonitoring(e){ var index = e.detail var data = this.data.tableData data.splice(index,1) this.setData( { tableData:data } ) this.getMyMonitor(1) }, //按钮菜单点击事件 click(e){ var {method,params} = e.detail this[method](params) }, //查看监控结果 monitoringRecord(params){ var index = params.index var product = this.data.tableData[index] wx.navigateTo({ url: '/pages/monitor/monitoringRecord?id='+product.assoId+'&productName='+product.name, }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })