|
|
@ -1,5 +1,8 @@ |
|
|
|
// package/subSystem/dayPatrolInfo/dayPatrolInfo.js
|
|
|
|
import * as echarts from '../../components/ec-canvas/echarts'; |
|
|
|
import { getSubSystemPatrol, getSubSystemPatrolAbout } from "../../../utils/getApiUrl"; |
|
|
|
import { Request } from "../../../common"; |
|
|
|
import moment from '../../../utils/moment'; |
|
|
|
|
|
|
|
const setPieOptions = ((chart, data) => { |
|
|
|
const option = { |
|
|
@ -42,6 +45,9 @@ Page({ |
|
|
|
data: { |
|
|
|
needEc: { lazyLoad: true }, |
|
|
|
alreadyEc: { lazyLoad: true }, |
|
|
|
dayIssues: [], // 今日问题分布
|
|
|
|
needInspectCount: 0, // 今日待检总次数
|
|
|
|
inspectedCount: 0, // 今日已检总次数
|
|
|
|
}, |
|
|
|
|
|
|
|
// 今日待检分布图表
|
|
|
@ -50,45 +56,115 @@ Page({ |
|
|
|
const chart = echarts.init(canvas, null, { |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
devicePixelRatio: dpr // new
|
|
|
|
devicePixelRatio: dpr |
|
|
|
}); |
|
|
|
setPieOptions(chart, data) |
|
|
|
return chart; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 今日已检分布图表
|
|
|
|
initAlreadyChart: function (data) { |
|
|
|
// 今日已检分布图表
|
|
|
|
initAlreadyChart: function (data) { |
|
|
|
this.alreadyEcComponent.init((canvas, width, height, dpr) => { |
|
|
|
const chart = echarts.init(canvas, null, { |
|
|
|
width: width, |
|
|
|
height: height, |
|
|
|
devicePixelRatio: dpr // new
|
|
|
|
devicePixelRatio: dpr |
|
|
|
}); |
|
|
|
setPieOptions(chart, data) |
|
|
|
return chart; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
getData() { |
|
|
|
const promiseArr = [ |
|
|
|
Request.get(getSubSystemPatrol(this.day, this.subType)), |
|
|
|
Request.get(getSubSystemPatrolAbout({ |
|
|
|
STime: moment().startOf('month').format('YYYY-MM-DD HH:mm:ss'), |
|
|
|
ETime: moment().endOf('month').format('YYYY-MM-DD HH:mm:ss'), |
|
|
|
keywords: this.subType, |
|
|
|
})), |
|
|
|
] |
|
|
|
Promise.all(promiseArr).then(([subSystemPatrol, patrolRecord]) => { |
|
|
|
let dayRecord = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day')); // 今日巡检记录
|
|
|
|
let dayAlarmRecord = dayRecord.filter(r => r.alarm); // 今日异常记录
|
|
|
|
|
|
|
|
// 今日问题分布
|
|
|
|
let nextDayIssues = []; |
|
|
|
const colors = ['#1684FF', '#DF6F6F', '#DF9B6F', '#DFBC6F']; |
|
|
|
dayAlarmRecord.forEach((record, index) => { |
|
|
|
const dayIndex = nextDayIssues.findIndex(d => d.pointName === record.points.itemData.name); |
|
|
|
if (dayIndex === -1) { |
|
|
|
nextDayIssues.push({ |
|
|
|
pointName: record.points.itemData.name, |
|
|
|
count: 1, |
|
|
|
color: colors[index % colors.length], |
|
|
|
}); |
|
|
|
} else { |
|
|
|
nextDayIssues[dayIndex].count += 1; |
|
|
|
} |
|
|
|
}); |
|
|
|
const total = nextDayIssues.reduce((accumulator, currentValue) => accumulator + currentValue.count, 0); |
|
|
|
nextDayIssues = nextDayIssues.map(d => ({ ...d, percent: Math.round((d.count / total) * 100) })); |
|
|
|
|
|
|
|
// 今日已巡分布
|
|
|
|
let inspectedPoints = []; |
|
|
|
dayRecord.forEach((record) => { |
|
|
|
const dayIndex = inspectedPoints.findIndex(d => d.name === record.points.itemData.name); |
|
|
|
if (dayIndex === -1) { |
|
|
|
inspectedPoints.push({ |
|
|
|
name: record.points.itemData.name, |
|
|
|
value: 1, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
inspectedPoints[dayIndex].value += 1; |
|
|
|
} |
|
|
|
}) |
|
|
|
this.inspectedPoints = inspectedPoints; |
|
|
|
|
|
|
|
// 今日待检分布
|
|
|
|
// let needInspectPoints = [];
|
|
|
|
// subSystemPatrol.dayPatrolPlan.forEach((plan) => {
|
|
|
|
// const unit = plan.frequency.split('/')[1];
|
|
|
|
// const frequency = plan.frequency.split('/')[0];
|
|
|
|
// let record = [...patrolRecord];
|
|
|
|
// switch (unit) {
|
|
|
|
// case '周':
|
|
|
|
// record = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day'));
|
|
|
|
// break;
|
|
|
|
// case '天':
|
|
|
|
// record = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day'));
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
this.initAlreadyChart(inspectedPoints) |
|
|
|
this.setData({ |
|
|
|
dayIssues: nextDayIssues, |
|
|
|
inspectedCount: inspectedPoints.reduce((accumulator, currentValue) => accumulator + currentValue.value, 0), |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|
onLoad(options) { |
|
|
|
wx.setNavigationBarTitle({ title: options.day }) |
|
|
|
this.day = options.day; |
|
|
|
this.subType = options.subType; |
|
|
|
this.getData(); |
|
|
|
setTimeout(() => { |
|
|
|
this.initNeedChart([ |
|
|
|
{ value: 1048, name: 'Search Engine' }, |
|
|
|
{ value: 735, name: 'Direct' }, |
|
|
|
{ value: 580, name: 'Email' }, |
|
|
|
{ value: 580, name: 'Email2' }, |
|
|
|
{ value: 580, name: 'Email3' }, |
|
|
|
]) |
|
|
|
this.initAlreadyChart([ |
|
|
|
{ value: 1048, name: 'Search Engine' }, |
|
|
|
{ value: 735, name: 'Direct' }, |
|
|
|
{ value: 580, name: 'Email' }, |
|
|
|
{ value: 580, name: 'Email2' }, |
|
|
|
{ value: 580, name: 'Email3' }, |
|
|
|
{ value: 1048, name: '点位1' }, |
|
|
|
{ value: 735, name: '点位2' }, |
|
|
|
{ value: 580, name: '点位3' }, |
|
|
|
{ value: 580, name: '点位4' }, |
|
|
|
{ value: 580, name: '点位5' }, |
|
|
|
]) |
|
|
|
}, 1000) |
|
|
|
}, |
|
|
|