|
|
@ -100,11 +100,13 @@ Page({ |
|
|
|
wx.showLoading({ title: '加载中...' }); |
|
|
|
const that = this |
|
|
|
//上次菜单传入设备列表
|
|
|
|
const complexArray = JSON.parse(decodeURIComponent(options.arrayData)); |
|
|
|
const complexArray = JSON.parse(decodeURIComponent(options.arrayData)) |
|
|
|
//上级菜单传入巡检记录
|
|
|
|
const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord)) |
|
|
|
const today = moment(); |
|
|
|
|
|
|
|
// const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord))
|
|
|
|
const today = moment().format('YYYY-MM-DD HH:mm:ss') |
|
|
|
const sevenDaysAgos = moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm:ss') |
|
|
|
Request.get(getPatrolRecord('all',today, sevenDaysAgos, 'null', 'null',{home:false})).then(res=>{ |
|
|
|
if(res){ |
|
|
|
// console.log('xx111',res)
|
|
|
|
// 创建一个对象来存储每个pointId的最大inspectionTime
|
|
|
|
const maxInspectionTimeByPointId = {}; |
|
|
@ -112,13 +114,13 @@ Page({ |
|
|
|
//把设备数据全部弄成未知状态
|
|
|
|
const len=complexArray.map(item=>{return {id:item.id,name:item.name,status:'unknown'}})?.length |
|
|
|
// 过滤出近七天内的最新记录(同点位+同一天的最新记录)
|
|
|
|
const latestRecords = patrolRecord?.filter((record) => { |
|
|
|
const latestRecords = res?.filter((record) => { |
|
|
|
const inspectionDate = moment(record.inspectionTime).format('YYYY-MM-DD'); |
|
|
|
const isWithin7Days = moment(today).diff(inspectionDate, 'days') <= 7; |
|
|
|
if (!isWithin7Days) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return patrolRecord?.every((r) => { |
|
|
|
return res?.every((r) => { |
|
|
|
if (r.pointId === record.pointId && moment(r.inspectionTime).isSame(moment(record.inspectionTime), 'day')) { |
|
|
|
return moment(r.inspectionTime).isSameOrBefore(moment(record.inspectionTime)); |
|
|
|
} |
|
|
@ -128,7 +130,7 @@ Page({ |
|
|
|
//调用每天的函数处理每天的正常-异常-未知的个数
|
|
|
|
const sevenDays= that.calculateDailyDeviceStatusCounts(latestRecords,len) |
|
|
|
// 遍历数据并更新maxInspectionTimeByPointId
|
|
|
|
patrolRecord?.forEach((item) => { |
|
|
|
res?.forEach((item) => { |
|
|
|
const {pointId,inspectionTime} = item; |
|
|
|
if (pointId in maxInspectionTimeByPointId) { |
|
|
|
if (inspectionTime > maxInspectionTimeByPointId[pointId]) { |
|
|
@ -139,7 +141,7 @@ Page({ |
|
|
|
} |
|
|
|
}); |
|
|
|
// 过滤数据以获取相同pointId中inspectionTime最大的记录
|
|
|
|
const filteredData = patrolRecord?.filter((item) => { |
|
|
|
const filteredData = res?.filter((item) => { |
|
|
|
const { pointId,inspectionTime} = item; |
|
|
|
const inspectionDate = moment(inspectionTime); |
|
|
|
if (inspectionDate.isBetween(sevenDaysAgo, today, null, '[]')) { |
|
|
@ -169,6 +171,8 @@ Page({ |
|
|
|
}, 1000) |
|
|
|
|
|
|
|
|
|
|
|
}}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|