Browse Source

寿命预警横轴展示

master
CODE 2 years ago
parent
commit
2fa47cd11b
  1. 63
      weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js

63
weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js

@ -2,14 +2,14 @@
import * as echarts from '../../components/ec-canvas/echarts'; import * as echarts from '../../components/ec-canvas/echarts';
import { import {
getAllPatrol, getAllPatrol,
getDevices,getProjectList getDevices, getProjectList
} from "../../../utils/getApiUrl"; } from "../../../utils/getApiUrl";
import { import {
Request Request
} from "../../../common"; } from "../../../common";
const moment = require("../../../utils/moment"); const moment = require("../../../utils/moment");
function setOption(chart, seriesData, xData) { function setOption (chart, seriesData, xData) {
const option = { const option = {
grid: { grid: {
top: '5%', top: '5%',
@ -20,7 +20,10 @@ function setOption(chart, seriesData, xData) {
}, },
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xData data: xData,
// axisLabel: {
// formatter: '{value}'
// }
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
@ -28,7 +31,7 @@ function setOption(chart, seriesData, xData) {
series: [{ series: [{
data: seriesData, data: seriesData,
type: 'line' type: 'line'
}, ] },]
}; };
chart.setOption(option); chart.setOption(option);
} }
@ -73,9 +76,9 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad (options) {
const projectList=decodeURIComponent(options.arrayData) const projectList = decodeURIComponent(options.arrayData)
const complexArray = JSON.parse(projectList); const complexArray = JSON.parse(projectList);
const { const {
windowHeight windowHeight
} = wx.getSystemInfoSync() } = wx.getSystemInfoSync()
@ -117,9 +120,9 @@ Page({
// 查找匹配项目 // 查找匹配项目
const project = complexArray.find((project) => project.id === point.projectId); const project = complexArray.find((project) => project.id === point.projectId);
if (project) { if (project) {
device.project = project; device.project = project;
} }
}); });
expiringDevices.push(device); expiringDevices.push(device);
} }
// 检查设备的 dateGuarantee 是否在日期范围内 // 检查设备的 dateGuarantee 是否在日期范围内
@ -140,10 +143,28 @@ Page({
// const label = `${year}-${month}`; // const label = `${year}-${month}`;
// xAxisLabels.push(label); // xAxisLabels.push(label);
const nextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + i, 1); const nextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + i, 1);
const month = nextMonth.toLocaleDateString('en-US', { const month = nextMonth
month: 'short' .getMonth()
}); // 获取月份的缩写 // .toLocaleDateString('en-US', {
xAxisLabels.push(month); // month: 'short'
// }); // 获取月份的缩写
const month_ = {
"0": "Jan",
"1": "Feb",
"2": "Mar",
"3": "Apr",
"4": "May",
"5": "Jun",
"6": "Jul",
"7": "Aug",
"8": "Sep",
"9": "Oct",
"10": "Nov",
"11": "Dec"
}[month]
console.log('月', month_);
xAxisLabels.push(month_);
} }
//过期的 //过期的
const guaranteedRate = res.filter(item => moment(item.dateGuarantee).isBefore(moment()))?.length || 0 const guaranteedRate = res.filter(item => moment(item.dateGuarantee).isBefore(moment()))?.length || 0
@ -153,7 +174,7 @@ Page({
count: res.length, count: res.length,
guaranteedRate: guaranteedRate, guaranteedRate: guaranteedRate,
warrantyPeriod: warrantyPeriod, warrantyPeriod: warrantyPeriod,
next30days:expiringDevices next30days: expiringDevices
}) })
setTimeout(() => { setTimeout(() => {
this.initChart(monthlyCounts, xAxisLabels) this.initChart(monthlyCounts, xAxisLabels)
@ -168,49 +189,49 @@ Page({
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady() { onReady () {
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow () {
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide() { onHide () {
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload() { onUnload () {
}, },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh() { onPullDownRefresh () {
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom() { onReachBottom () {
}, },
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage() { onShareAppMessage () {
} }
}) })
Loading…
Cancel
Save