|
|
@ -13,21 +13,21 @@ const moment = require("../../utils/moment"); |
|
|
|
Page({ |
|
|
|
initECharts(option) { |
|
|
|
this.ecComponent.init((canvas, width, height, dpr) => { |
|
|
|
const chart = echarts.init(canvas, null, { |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
devicePixelRatio: dpr, |
|
|
|
}); |
|
|
|
// 设置图表的配置
|
|
|
|
chart.setOption(option); |
|
|
|
|
|
|
|
// 将 ECharts 实例保存在数据中
|
|
|
|
this.chart = chart; |
|
|
|
|
|
|
|
// 返回 ECharts 实例
|
|
|
|
return chart; |
|
|
|
const chart = echarts.init(canvas, null, { |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
devicePixelRatio: dpr, |
|
|
|
}); |
|
|
|
// 设置图表的配置
|
|
|
|
chart.setOption(option); |
|
|
|
|
|
|
|
// 将 ECharts 实例保存在数据中
|
|
|
|
this.chart = chart; |
|
|
|
|
|
|
|
// 返回 ECharts 实例
|
|
|
|
return chart; |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
@ -39,9 +39,10 @@ Page({ |
|
|
|
show: true, |
|
|
|
currentPatrolCount: 0, //当月巡检次数
|
|
|
|
currentRepairCount: 0, //当月维修次数
|
|
|
|
level1Count: 0, //轻微
|
|
|
|
level2Count: 0, //中度
|
|
|
|
level3Count: 0, //严重
|
|
|
|
// level1Count: 0, //轻微
|
|
|
|
// level2Count: 0, //中度
|
|
|
|
// level3Count: 0, //严重
|
|
|
|
// dataList:[],//饼图数据
|
|
|
|
selectedDate: new Date(), // 设置默认选中的日期为当前日期
|
|
|
|
formatter(day) { |
|
|
|
|
|
|
@ -79,9 +80,9 @@ Page({ |
|
|
|
*/ |
|
|
|
onLoad: function (options) { |
|
|
|
this.subType = options.key |
|
|
|
const {windowHeight}=wx.getSystemInfoSync() |
|
|
|
const pageHeight=windowHeight - 48 |
|
|
|
const that=this |
|
|
|
const { windowHeight } = wx.getSystemInfoSync() |
|
|
|
const pageHeight = windowHeight - 48 |
|
|
|
const that = this |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中' |
|
|
|
}) |
|
|
@ -109,22 +110,22 @@ Page({ |
|
|
|
currentMonth: currentMonth, |
|
|
|
lastDay: lastDay, |
|
|
|
firstDay: firstDay, |
|
|
|
pageHeight:pageHeight+'px' |
|
|
|
pageHeight: pageHeight + 'px' |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wx.hideLoading() |
|
|
|
|
|
|
|
}, |
|
|
|
//过滤轻微,中度,重度的巡检个数
|
|
|
|
filterLevelCount:function(list,level){ |
|
|
|
return list?.filter(i => { |
|
|
|
filterLevelCount: function (list, level) { |
|
|
|
return list?.filter(i => { |
|
|
|
const content = i?.points?.inspectContent |
|
|
|
if (content&&content.length) { |
|
|
|
if (content && content.length) { |
|
|
|
for (let key in content) { |
|
|
|
if (content.hasOwnProperty(key)) { |
|
|
|
const subObject = content[key]; |
|
|
|
return subObject.level===level |
|
|
|
return subObject.level === level |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -139,30 +140,75 @@ Page({ |
|
|
|
const ETime = moment().endOf('month').format('YYYY-MM-DD') |
|
|
|
//子系统关键字
|
|
|
|
let keywords = options.key |
|
|
|
const maxInspectionTimeByPointId = {}; |
|
|
|
// keywords = '管廊'
|
|
|
|
const query = { |
|
|
|
STime, |
|
|
|
ETime, |
|
|
|
keywords |
|
|
|
} |
|
|
|
const query = { STime, ETime, keywords } |
|
|
|
Request.get(getSubSystemPatrolAbout(query)).then(res => { |
|
|
|
|
|
|
|
if (res) { |
|
|
|
// 遍历数据并更新maxInspectionTimeByPointId
|
|
|
|
res.forEach((item) => { |
|
|
|
const { pointId, inspectionTime } = item; |
|
|
|
if (pointId in maxInspectionTimeByPointId) { |
|
|
|
if (inspectionTime > maxInspectionTimeByPointId[pointId]) { |
|
|
|
maxInspectionTimeByPointId[pointId] = inspectionTime; |
|
|
|
} |
|
|
|
} else { |
|
|
|
maxInspectionTimeByPointId[pointId] = inspectionTime; |
|
|
|
} |
|
|
|
}); |
|
|
|
// 过滤数据以获取相同pointId中inspectionTime最大的记录
|
|
|
|
const filteredData = res.filter((item) => { |
|
|
|
const { pointId, inspectionTime } = item; |
|
|
|
return inspectionTime === maxInspectionTimeByPointId[pointId]; |
|
|
|
}); |
|
|
|
//巡查内容
|
|
|
|
// const list=res?.filter(item=>item?.points?.user.id===userInfo.id)||[]
|
|
|
|
// 创建一个对象来存储按设备分类的最低level统计
|
|
|
|
const deviceLevelStatistics = {}; |
|
|
|
// 初始化一个包含所有level的对象
|
|
|
|
const levelValues = {轻微: 0,中度: 1,严重: 2}; |
|
|
|
// 遍历巡检记录
|
|
|
|
filteredData.forEach((record) => { |
|
|
|
const points = record.points; |
|
|
|
if (points && points.inspectContent && Array.isArray(points.inspectContent)) { |
|
|
|
points.inspectContent.forEach((content) => { |
|
|
|
const device = content.deviceId; |
|
|
|
content.checkItems.forEach(checkItem => { |
|
|
|
const level = checkItem.level; |
|
|
|
if (!deviceLevelStatistics[device]) { |
|
|
|
// 如果设备不存在于统计对象中,初始化
|
|
|
|
deviceLevelStatistics[device] = { |
|
|
|
deviceName: content.deviceName, // 可能需要设备名称
|
|
|
|
level: level |
|
|
|
}; |
|
|
|
} else { |
|
|
|
// 如果设备已存在于统计对象中,比较level并更新为最低的level
|
|
|
|
deviceLevelStatistics[device].level = levelValues[level] < levelValues[deviceLevelStatistics[device].level] ? level : deviceLevelStatistics[device].level; |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
const levelCounts = {轻微: 0,中度: 0, 严重: 0}; |
|
|
|
for (const deviceId in deviceLevelStatistics) { |
|
|
|
if (deviceLevelStatistics.hasOwnProperty(deviceId)) { |
|
|
|
const deviceInfo = deviceLevelStatistics[deviceId]; |
|
|
|
const level = deviceInfo.level; |
|
|
|
// 增加相应等级的设备数量
|
|
|
|
levelCounts[level]++; |
|
|
|
} |
|
|
|
} |
|
|
|
const data1=Object.entries(levelCounts).map(([name, value]) => ({ name, value })); |
|
|
|
that.setData({ |
|
|
|
currentRepairCount: res?.filter(i =>i.patrolRecordIssueHandles.length>0 ).length || 0, |
|
|
|
currentRepairCount: res?.filter(i => i.patrolRecordIssueHandles.length > 0).length || 0, |
|
|
|
currentPatrolCount: res.length, |
|
|
|
level1Count: that.filterLevelCount(res,'轻微')||0, |
|
|
|
level2Count: that.filterLevelCount(res,'中度')||0, |
|
|
|
level3Count: that.filterLevelCount(res,'严重')||0, |
|
|
|
formatter:function(e){ |
|
|
|
res?.map(i=>{ |
|
|
|
if(moment(i.inspectionTime).format('YYYY-MM-DD')==moment(e.date).format('YYYY-MM-DD')){ |
|
|
|
if( i.patrolRecordIssueHandles.length==0){ |
|
|
|
e.bottomInfo = '.';e.className = 'greenClass' |
|
|
|
}else if( i.patrolRecordIssueHandles.length&& i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))){ |
|
|
|
e.bottomInfo = '.';e.className = 'yellowClass' |
|
|
|
formatter: function (e) { |
|
|
|
filteredData?.map(i => { |
|
|
|
if (moment(i.inspectionTime).format('YYYY-MM-DD') == moment(e.date).format('YYYY-MM-DD')) { |
|
|
|
if (i.patrolRecordIssueHandles.length == 0) { |
|
|
|
e.bottomInfo = '.'; e.className = 'greenClass' |
|
|
|
} else if (i.patrolRecordIssueHandles.length && i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))) { |
|
|
|
e.bottomInfo = '.'; e.className = 'yellowClass' |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
@ -176,6 +222,9 @@ Page({ |
|
|
|
bottom: 10, |
|
|
|
left: 'center', |
|
|
|
}, |
|
|
|
tooltip: { |
|
|
|
trigger: 'item' |
|
|
|
}, |
|
|
|
series: [{ |
|
|
|
label: { |
|
|
|
normal: { |
|
|
@ -185,13 +234,11 @@ Page({ |
|
|
|
type: 'pie', |
|
|
|
center: ['50%', '50%'], |
|
|
|
radius: ['20%', '40%'], |
|
|
|
data:[ {name:'轻微',value:that.data.level1Count}, |
|
|
|
{name:'中度',value:that.data.level2Count}, |
|
|
|
{name:'重度',value:that.data.level3Count}] |
|
|
|
data:data1 |
|
|
|
}] |
|
|
|
}; |
|
|
|
that.initECharts(option); |
|
|
|
|
|
|
|
|
|
|
|
wx.hideLoading() |
|
|
|
} else { |
|
|
|
wx.hideLoading(); |
|
|
@ -203,7 +250,7 @@ Page({ |
|
|
|
*/ |
|
|
|
|
|
|
|
onReady() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|