diff --git a/weapp/package/riskManagement/riskCalendar/riskCalendar.js b/weapp/package/riskManagement/riskCalendar/riskCalendar.js index ee3afca..4836baf 100644 --- a/weapp/package/riskManagement/riskCalendar/riskCalendar.js +++ b/weapp/package/riskManagement/riskCalendar/riskCalendar.js @@ -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(); + }) }, /** diff --git a/weapp/package/riskManagement/riskCalendar/riskCalendar.wxml b/weapp/package/riskManagement/riskCalendar/riskCalendar.wxml index 63b9159..f6fe162 100644 --- a/weapp/package/riskManagement/riskCalendar/riskCalendar.wxml +++ b/weapp/package/riskManagement/riskCalendar/riskCalendar.wxml @@ -6,7 +6,7 @@ 巡检日历 - {{'2023-10-20'}} + {{curDate}} @@ -16,6 +16,10 @@ show-subtitle="{{ false }}" poppable="{{ false }}" show-confirm="{{ false }}" + min-date="{{ minDate }}" + max-date="{{ maxDate }}" + formatter="{{ formatter }}" + bind:select="onDateSelect" row-height="48" color="#1684FF" class="calendar" @@ -30,7 +34,7 @@ - + - + - 结构物A + {{item.points.project.name}} - 查看详情 + 查看详情 本次巡检日期 - 2020/12/21 17:00:00 + {{item.inspectionTime}} 点位 - 点位A + {{item.points.itemData.name}} 巡检人 - 离成功 + {{item.points.user.name}} 巡检结果 @@ -67,7 +71,7 @@ 异常等级 - 轻微 + {{item.level}} diff --git a/weapp/package/riskManagement/riskCalendar/riskCalendar.wxss b/weapp/package/riskManagement/riskCalendar/riskCalendar.wxss index b0af8e2..a33142f 100644 --- a/weapp/package/riskManagement/riskCalendar/riskCalendar.wxss +++ b/weapp/package/riskManagement/riskCalendar/riskCalendar.wxss @@ -47,6 +47,7 @@ border-radius: 16px; color: #fff; font-size: 13px; + z-index: 99; } .card-icon { diff --git a/weapp/package/riskManagement/riskManagement.js b/weapp/package/riskManagement/riskManagement.js index dd94f6f..5b361c9 100644 --- a/weapp/package/riskManagement/riskManagement.js +++ b/weapp/package/riskManagement/riskManagement.js @@ -28,7 +28,12 @@ function setOption(chart, data) { }, }, yAxis: { - type: 'value' + type: 'value', + splitLine: { // 网格线 + lineStyle: { + type: 'dashed' + }, + } }, series: [ { diff --git a/weapp/package/riskManagement/riskManagement.wxml b/weapp/package/riskManagement/riskManagement.wxml index 9a6456c..62627cd 100644 --- a/weapp/package/riskManagement/riskManagement.wxml +++ b/weapp/package/riskManagement/riskManagement.wxml @@ -2,7 +2,7 @@ - 故障统计 + 故障统计