// pages/home/home.js import { getPatrolRecord } from "../../utils/getApiUrl"; import { Request } from "../../common"; const moment = require("../../utils/moment"); Page({ jumpToSubSystem (options) { const key = options.currentTarget.dataset.key; wx.navigateTo({ url: `/package/subSystem/subSystem?key=${key}`, }) }, /** * 页面的初始数据 */ data: { sevenDaysCount:0,//过去七天的巡检次数 sevenDaysQuestionCount:0,//过去七天发现问题个数 sevenDaysHandleCount:0,//过去七天问题解决个数 allCount:0,//总的巡检次数 allQuestionCount:0,//总的发现问题个数 allHandleCount:0,//总的问题解决个数 todayRecord: [], // 今日巡检记录 markers: [], pageHeight:0,//屏幕高度 isShowCallout: false, itemList:[{ picPath:'/images/conduct.png', itemName:'指挥中心' }, { picPath:'/images/waterSupply.png', itemName:'给水仓' }, { picPath:'/images/pipeGallery.png', itemName:'管廊本体' }, { picPath:'/images/elevator.png', itemName:'电梯系统' }, { picPath:'/images/power.png', itemName:'供配电系统' }, { picPath:'/images/gas.png', itemName:'燃气仓' }, { picPath:'/images/security.png', itemName:'安防系统' }, { picPath:'/images/highTension.png', itemName:'高压电力仓' }, { picPath:'/images/electricalStorageRoom.png', itemName:'电气仓' }, { picPath:'/images/lightningProtection.png', itemName:'防雷与接地' } ], }, /** * 生命周期函数--监听页面加载 */ onLoad (options) { const userInfo=wx.getStorageSync('userInfo'); const {windowHeight}=wx.getSystemInfoSync() const pageHeight=windowHeight - 48 const promiseArr = []; const that = this; var data = { "datas": [ { "id": 1, "imgurl": "/images/avatar.png" }, { "id": 2, "imgurl": "/images/card_bg.png" } ] }; wx.showLoading({ title: '加载中' }) promiseArr.push(Request.get(getPatrolRecord('all', moment('1970-1-1').format('YYYY-MM-DD') + ' 00:00:00', moment('2099-12-31').format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null'))); Promise.all(promiseArr).then(res => { wx.hideLoading() //与自己相关的所有巡检记录 const list=res[0]?.filter(item=>item?.points?.user.id===userInfo.id)||[] //过去七天的所有巡检记录 const sevenDaysList=list?.filter(item=> { const recordDate = moment(date, 'YYYY-MM-DD'); // 解析日期 const daysDifference = moment().diff(recordDate, 'days'); // 计算日期差 // 返回近七天内的记录 return daysDifference >= 0 && daysDifference < 7; } )||[] that.setData({ allCount:list.length || 0, allQuestionCount:list?.filter(i=>i.patrolRecordIssueHandles>0)?.length || 0, allHandleCount:list?.filter(i => i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))).length || 0, sevenDaysCount:sevenDaysList.length||0, sevenDaysQuestionCount:sevenDaysList?.filter(i=>i.patrolRecordIssueHandles>0)?.length || 0, sevenDaysHandleCount:sevenDaysList?.filter(i => i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))).length || 0, pageHeight:pageHeight+'px', swiperData:data.datas }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady () { }, /** * 生命周期函数--监听页面显示 */ onShow () { const userInfo = wx.getStorageSync('userInfo'); if (!userInfo || !userInfo.id) { wx.reLaunch({ url: '/pages/login/login' }); } else { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0 }) } } }, /** * 生命周期函数--监听页面隐藏 */ onHide () { }, /** * 生命周期函数--监听页面卸载 */ onUnload () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom () { }, /** * 用户点击右上角分享 */ onShareAppMessage () { } })