|
|
|
// package/subSystem/subSystem.js
|
|
|
|
import * as echarts from '../components/ec-canvas/echarts';
|
|
|
|
import {
|
|
|
|
getSubSystemPatrolAbout
|
|
|
|
} from "../../utils/getApiUrl";
|
|
|
|
import {
|
|
|
|
Request
|
|
|
|
} from "../../common";
|
|
|
|
const moment = require("../../utils/moment");
|
|
|
|
|
|
|
|
Page({
|
|
|
|
record: [],//巡检记录
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
ec: {
|
|
|
|
// lazyLoad: true, // 延迟加载 ECharts
|
|
|
|
},
|
|
|
|
date: '',
|
|
|
|
show: true,
|
|
|
|
currentPatrolCount: 0, //当月巡检次数
|
|
|
|
currentRepairCount: 0, //当月维修次数
|
|
|
|
currentDate: new Date().getTime(),
|
|
|
|
minDate: 0,
|
|
|
|
curSelect: null,//当前选择
|
|
|
|
// level1Count: 0, //轻微
|
|
|
|
// level2Count: 0, //中度
|
|
|
|
// level3Count: 0, //严重
|
|
|
|
// dataList:[],//饼图数据
|
|
|
|
selectedDate: new Date(), // 设置默认选中的日期为当前日期
|
|
|
|
questions: 0,//故障数量
|
|
|
|
datePickerShow: false,//选择日期
|
|
|
|
formatter(day) {
|
|
|
|
|
|
|
|
return day;
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
datePickerPopup() {
|
|
|
|
this.setData({
|
|
|
|
datePickerShow: true
|
|
|
|
})
|
|
|
|
},
|
|
|
|
closeDatePickerPopup() {
|
|
|
|
this.setData({
|
|
|
|
datePickerShow: false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onDisplay() {
|
|
|
|
this.setData({
|
|
|
|
show: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onClose() {
|
|
|
|
this.setData({
|
|
|
|
show: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onConfirm(event) {
|
|
|
|
this.setData({
|
|
|
|
show: false,
|
|
|
|
date: this.formatDate(event.detail),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onDateChange(e) {
|
|
|
|
const dateObject = new Date(e.detail);
|
|
|
|
const firstDay = new Date(dateObject.getFullYear(), dateObject.getMonth(), 1);
|
|
|
|
firstDay.setHours(0, 0, 0, 0);
|
|
|
|
const firstDayTimestamp = firstDay.getTime();
|
|
|
|
const nextMonthFirstDay = new Date(dateObject.getFullYear(), dateObject.getMonth() + 1, 1);
|
|
|
|
const lastDayTimestamp = nextMonthFirstDay.getTime() - 1; // 减去1毫秒得到本月最后一天
|
|
|
|
const currentYear = dateObject.getFullYear();
|
|
|
|
const currentMonth = dateObject.getMonth() + 1;
|
|
|
|
this.setData({
|
|
|
|
currentYear: currentYear,
|
|
|
|
currentMonth: currentMonth,
|
|
|
|
lastDay: lastDayTimestamp,
|
|
|
|
firstDay: firstDayTimestamp,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onDateSelect(e) {
|
|
|
|
const currentDate = moment(e.detail).format('YYYY-MM-DD')
|
|
|
|
const inspectionData = this.record.find(item => currentDate == moment(item.inspectionTime).format('YYYY-MM-DD'));
|
|
|
|
if (inspectionData) {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/package/subSystem/dayPatrolInfo/dayPatrolInfo?day=${moment(e.detail).format('YYYY-MM-DD')}&subType=${this.subType}`,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
wx.showToast({
|
|
|
|
title: '当天没有巡检记录',
|
|
|
|
icon: 'none',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
wx.showLoading({
|
|
|
|
title: '加载中...',
|
|
|
|
})
|
|
|
|
this.subType = options.key
|
|
|
|
const { windowHeight } = wx.getSystemInfoSync()
|
|
|
|
const pageHeight = windowHeight - 48
|
|
|
|
const that = this
|
|
|
|
wx.showLoading({
|
|
|
|
title: '加载中'
|
|
|
|
})
|
|
|
|
// const that = this;
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
|
title: options.key,
|
|
|
|
});
|
|
|
|
//加载初始化数据
|
|
|
|
that.getSubSystemPatrolAbout(options)
|
|
|
|
//初始化图表的配置项
|
|
|
|
// 其他渲染逻辑
|
|
|
|
// 创建一个 Date 对象来获取当前日期
|
|
|
|
const currentDate = new Date();
|
|
|
|
// 获取当前年份
|
|
|
|
const currentYear = currentDate.getFullYear();
|
|
|
|
// 获取当前月份(注意,月份是从 0 到 11 表示,所以需要加 1)
|
|
|
|
const currentMonth = currentDate.getMonth() + 1;
|
|
|
|
// 获取当前月份的第一天和最后一天
|
|
|
|
const nextMonth = new Date().getMonth() + 1;
|
|
|
|
const firstDay = new Date().setDate(1);
|
|
|
|
const lastDay = new Date().setMonth(nextMonth, 1) - 86400000;
|
|
|
|
// 更新数据,将年份和月份传递给 WXML 页面
|
|
|
|
that.setData({
|
|
|
|
currentYear: currentYear,
|
|
|
|
currentMonth: currentMonth,
|
|
|
|
lastDay: lastDay,
|
|
|
|
firstDay: firstDay,
|
|
|
|
pageHeight: pageHeight + 'px'
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// wx.hideLoading()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getSubSystemPatrolAbout: function (options) {
|
|
|
|
wx.showLoading({
|
|
|
|
title: '加载中...',
|
|
|
|
})
|
|
|
|
// const userInfo=wx.getStorageSync('userInfo');
|
|
|
|
let that = this;
|
|
|
|
const STime = moment('1970-01-01').format('YYYY-MM-DD')
|
|
|
|
const ETime = moment('2099-12-31').format('YYYY-MM-DD')
|
|
|
|
//子系统关键字
|
|
|
|
let keywords = options.key
|
|
|
|
const maxInspectionTimeByPointId = {};
|
|
|
|
// keywords = '管廊'
|
|
|
|
const query = { STime, ETime, keywords }
|
|
|
|
Request.get(getSubSystemPatrolAbout(query)).then(res => {
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
//求出最小时间
|
|
|
|
const minTimeObject = res.reduce((min, current) => {
|
|
|
|
// 比较时间,选择最小的时间
|
|
|
|
return !min || new Date(current.inspectionTime) < new Date(min.inspectionTime) ? current : min;
|
|
|
|
}, null)
|
|
|
|
let inputDate = new Date()
|
|
|
|
let firstDayTimestamp = new Date().getTime()
|
|
|
|
if (minTimeObject) {
|
|
|
|
inputDate = new Date(minTimeObject.inspectionTime)
|
|
|
|
inputDate.setDate(1);
|
|
|
|
inputDate.setHours(0, 0, 0, 0);
|
|
|
|
firstDayTimestamp = inputDate.getTime();
|
|
|
|
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
minDate: firstDayTimestamp
|
|
|
|
})
|
|
|
|
// 遍历数据并更新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 (!checkItem.isNormal) {
|
|
|
|
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 }));
|
|
|
|
const totalValue = data1.reduce((accumulator, item) => accumulator + item.value, 0);
|
|
|
|
this.record=res
|
|
|
|
that.setData({
|
|
|
|
currentRepairCount: res?.filter(i => i.patrolRecordIssueHandles.length > 0 ? i.patrolRecordIssueHandles[0].state === 6 : false).length || 0,
|
|
|
|
currentPatrolCount: res.length,
|
|
|
|
questions: totalValue,
|
|
|
|
formatter: function (e) {
|
|
|
|
const currentDate = moment(e.date).format('YYYY-MM-DD');
|
|
|
|
const rs = res.filter(item => currentDate === moment(item.inspectionTime).format('YYYY-MM-DD'))
|
|
|
|
if (rs && rs.length) {
|
|
|
|
if (rs.some(item => item.patrolRecordIssueHandles.length > 0)) {
|
|
|
|
e.bottomInfo = '.';
|
|
|
|
e.className = 'yellowClass';
|
|
|
|
} else {
|
|
|
|
e.bottomInfo = '.';
|
|
|
|
e.className = 'greenClass';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
})
|
|
|
|
that.ecComponent = that.selectComponent('#mychart-dom-pie');
|
|
|
|
var option = {
|
|
|
|
backgroundColor: "#ffffff",
|
|
|
|
legend: {
|
|
|
|
bottom: 10,
|
|
|
|
left: 'center',
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'item'
|
|
|
|
},
|
|
|
|
series: [{
|
|
|
|
label: {
|
|
|
|
normal: {
|
|
|
|
fontSize: 14
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'pie',
|
|
|
|
center: ['50%', '50%'],
|
|
|
|
radius: ['20%', '40%'],
|
|
|
|
data: data1
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
that.initECharts(option);
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// wx.hideLoading();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
// wx.hideLoading()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh() {
|
|
|
|
getSubSystemPatrolAbout()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|