|
|
|
// 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('day').subtract(6, 'days').valueOf(),
|
|
|
|
maxDate: moment().endOf('day').valueOf(),
|
|
|
|
curDate: moment().format('YYYY-MM-DD'),
|
|
|
|
showList: [],
|
|
|
|
formatter(day) { return day; },
|
|
|
|
},
|
|
|
|
|
|
|
|
dayData: [], // 每天的异常数据
|
|
|
|
|
|
|
|
onDateSelect(e) {
|
|
|
|
this.setData({ curDate: moment(e.detail).format('YYYY-MM-DD') })
|
|
|
|
this.calcShowList(this.data.curLevel, moment(e.detail).format('YYYY-MM-DD'))
|
|
|
|
},
|
|
|
|
|
|
|
|
showPopup() {
|
|
|
|
this.setData({ show: 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;
|
|
|
|
Request.get(getPatrolRecord('all', moment(minDate).format('YYYY-MM-DD HH:mm:ss'), moment(maxDate).format('YYYY-MM-DD HH:mm:ss'), true, 'null')).then(res => {
|
|
|
|
let dayData = new Array(7)
|
|
|
|
for (let i = 6; 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[6 - i] = { 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 });
|
|
|
|
this.dayData = dayData;
|
|
|
|
this.calcShowList();
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|