You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
5.0 KiB

// package/riskManagement/riskCalendar/riskCalendar.js
import { getPatrolRecord } from "../../../utils/getApiUrl";
import { Request } from "../../../common";
import moment from '../../../utils/moment';
Page({
/**
* 页面的初始数据
*/
data: {
show: false,
level: ['全部', '轻微', '中度', '严重'],
curLevel: '全部',
minDate: moment().startOf('month').valueOf(),
maxDate: moment().endOf('month').valueOf(),
curDate: moment().format('YYYY-MM'),
showList: [],
formatter(day) { return day; },
datePickerShow:false,
datePickerMin:1640966400000,//2022-01-01 00:00:00
end:moment().endOf('month').valueOf()
},
dayData: [], // 每天的异常数据
onDateSelect(e) {
this.setData({ curDate: moment(e.detail).format('YYYY-MM') })
this.calcShowList(this.data.curLevel, moment(e.detail).format('YYYY-MM-DD'))
},
onDateChange(e){
// this.queryData(e.detail,)
const begin=e.detail
const end =moment(e.detail).endOf('month').valueOf()
this.queryData(begin,end)
this.setData({curDate:moment(e.detail).format('YYYY-MM'),
end:end,minDate:begin
})
},
showPopup() {
this.setData({ show: true })
},
closeDatePickerPopup(){
this.setData({datePickerShow:false})
},
datePickerPopup() {
this.setData({
datePickerShow: true
})
},
onCancel() {
this.setData({ show: false })
},
onConfirm(e) {
this.setData({ curLevel: e.detail.value, show: false })
this.calcShowList(e.detail.value, this.data.curDate)
},
calcShowList(level = this.data.curLevel, date = this.data.curDate) {
const { dayData } = this;
let nextShowList = []
for (const day of dayData) {
if (day.formatDate === date) {
nextShowList = day.data;
}
}
if (level !== '全部') {
nextShowList = nextShowList.filter(l => l.level === level)
}
this.setData({ showList: nextShowList })
},
// 查看详情
toDetail(e) {
let data = JSON.stringify(e.currentTarget.dataset.item);
wx.navigateTo({
url: '/package/polling/inspectionRecordDetail/inspectionRecordDetail?data=' + encodeURIComponent(data),
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { minDate, maxDate } = this.data;
this.queryData(minDate,maxDate)
},
queryData(minDate,maxDate){
Request.get(getPatrolRecord('all', moment(minDate).format('YYYY-MM-DD HH:mm:ss'), moment(maxDate).format('YYYY-MM-DD HH:mm:ss'), true, 'null',{home:false})).then(res => {
const daysInMonth = moment(maxDate).daysInMonth();
let dayData = new Array(daysInMonth)
for (let i = daysInMonth-1; i >= 0; i--) {
const month = moment().subtract(i, 'day').month();
const date = moment().subtract(i, 'day').date();
let data = [];
res.forEach(d => {
if (moment(d.inspectionTime).date() === date) {
// 计算此记录的异常等级(检查项中异常最高等级),用于列表展示
const levelValues = {轻微: 0,中度: 1,严重: 2};
let tempLevel = '轻微';
for (const device of d.points.inspectContent) {
if (device?.alarm === true) {
for (const item of device.checkItems) {
if (item.level) {
tempLevel=levelValues[item.level]>levelValues[tempLevel]?item.level:tempLevel
// tempLevel = item.level; 这没有取到最高级别的故障等级,取得是最后一个检查项的故障等级
}
}
}
}
data.push({
...d, level: tempLevel,
inspectionTime: moment(d.inspectionTime).format('YYYY-MM-DD HH:mm:ss'),
lastInspectionTime: d.lastInspectionTime ? moment(d.lastInspectionTime).format('YYYY-MM-DD HH:mm:ss') : '--',
})
}
})
dayData[ daysInMonth- i-1] = { month, date, formatDate: moment().subtract(i, 'day').format('YYYY-MM-DD'), data }
}
const formatter = (day) => {
const month = day.date.getMonth();
const date = day.date.getDate();
dayData.forEach(d => {
if (d.month === month && d.date === date && d.data.length) {
day.bottomInfo = '🔸'
}
})
return day;
}
this.setData({ formatter, datePickerShow:false });
this.dayData = dayData;
this.calcShowList();
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})