|
|
@ -1,14 +1,28 @@ |
|
|
|
// package/riskManagement/riskCalendar/riskCalendar.js
|
|
|
|
Page({ |
|
|
|
import { getPatrolRecord } from "../../../utils/getApiUrl"; |
|
|
|
import { Request } from "../../../common"; |
|
|
|
import moment from '../../../utils/moment'; |
|
|
|
|
|
|
|
Page({ |
|
|
|
/** |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
show: false, |
|
|
|
level: ['轻微', '中度', '严重'], |
|
|
|
curLevel: '轻微', |
|
|
|
todayAlarm: [1, 2, 3], |
|
|
|
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() { |
|
|
@ -19,13 +33,76 @@ Page({ |
|
|
|
}, |
|
|
|
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) { |
|
|
|
// 计算此记录的异常等级(检查项中异常最高等级),用于列表展示
|
|
|
|
let tempLevel = '轻微'; |
|
|
|
for (const device of d.points.inspectContent) { |
|
|
|
if (device.alarm === true) { |
|
|
|
for (const item of device.checkItems) { |
|
|
|
if (item.level) { 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(); |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|