// package/AIOTOverview/network/network.js import { getNetworks,getProjectList} from "../../../utils/getApiUrl"; import { Request } from "../../../common"; import moment from "../../../utils/moment"; Page({ networkDataCopy:[], /** * 页面的初始数据 */ data: { limit: 10, //条数 page: 0, //当前页 count: 0, //总条数 networkData:[], structList:[], // networkDataCopy:[], curStruId: 'all', // 选中结构物id }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.queryData() this.obtainStruc() }, obtainStruc(){ let promiseArr=[] let sdatas=[] promiseArr.push(Request.get(getProjectList())) Promise.all(promiseArr).then(res=>{ if(res[0].rows.length){ const filterData=res[0].rows.filter(s => s.type=='管廊') sdatas=filterData?.map(item=>( { value: item.id, text:item.name })) sdatas.unshift({ text: '全部', value: 'all' }) } this.setData({ structList:sdatas }) }) }, queryData(){ const {limit,page}=this.data let promiseArr=[] promiseArr.push(Request.get(getNetworks(),{limit,page})) Promise.all(promiseArr).then(res=>{ let datas=[]//宽带的数据 let sdatas=[]//结构物 if(res[0].rows.length){ datas=res[0].rows.filter(s => s.project.type==='管廊')?.map(q=>({ ...q, indate:moment(q.indate).format('YYYY-MM-DD'), status:moment(q.indate).isBefore(moment())?1:0 })) } this.networkDataCopy=datas this.setData({ networkData:datas, }) }) }, onStruChange(e){ if (e.detail) { let data = [] if (e.detail === 'all') { data = this.networkDataCopy } else { data = this.networkDataCopy.filter(item => item.projectId === e.detail) } this.setData({ curStruId: e.detail, networkData: data }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { let _that=this let page = _that.data.page + 1; //获取当前页数并+1 let { networkData, count } = _that.data; if (networkData.length == count) { wx.showToast({ title: '没有更多数据了...', icon: 'none', }) return; } _that.setData({ page: page, //更新当前页数 }) _that.queryData() }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })