wszhyWx/pages/target_water_fertilizer_PH/target_water_fertilizer_PH.vue

283 lines
6.1 KiB
Vue
Raw Normal View History

2023-09-28 10:07:02 +00:00
<template>
<view class="target_water_fertilizer_PH">
<!-- 目标水肥PH -->
<u-navbar :background="background" :is-back='true' back-icon-color='#FFFFFF' :border-bottom="false"
2023-10-13 00:55:47 +00:00
:title="titleName+echartName" title-color='#FFFFFF' :title-bold='true' title-size='32'></u-navbar>
2023-09-28 10:07:02 +00:00
<view class="navbar">
2023-10-05 04:08:22 +00:00
<image src="../../static/PH_bg.png" mode=""></image>
2023-09-28 10:07:02 +00:00
</view>
<view class="content">
<view class="number">
2023-10-13 06:58:18 +00:00
{{ valuePH + unit }}
2023-09-28 10:07:02 +00:00
</view>
<view class="data_analysis">
2023-10-05 04:08:22 +00:00
<image src="../../static/data_analysis.png" mode=""></image>
2023-09-28 10:07:02 +00:00
<text>数据分析</text>
</view>
<view class="echart">
<view class="title">
2023-10-05 04:08:22 +00:00
<image src="../../static/icon_ph.png" mode=""></image>
2023-10-13 00:55:47 +00:00
<text>{{ titleName+echartName }}</text>
2023-09-28 10:07:02 +00:00
</view>
<view id="echart_p">
2023-10-13 09:07:57 +00:00
<qiun-data-charts type="area" :opts="opts" :chartData="chartData" :ontouch="true"
2023-09-28 10:07:02 +00:00
background="none" />
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 头部导航背景
background: {
backgroundColor: 'transparent',
},
2023-10-13 09:07:57 +00:00
equipmentId: '',
2023-09-28 10:07:02 +00:00
chartData: {},
opts: {
color: ["#24B383"],
2023-10-13 09:07:57 +00:00
padding: [15, 35, 0, 15],
2023-09-28 10:07:02 +00:00
dataLabel: false,
dataPointShape: false,
2023-10-13 09:07:57 +00:00
enableScroll: false,
2023-09-28 10:07:02 +00:00
legend: {},
2023-10-13 09:07:57 +00:00
tooltipShow: true,
2023-09-28 10:07:02 +00:00
xAxis: {
disableGrid: true,
2023-10-13 09:07:57 +00:00
// scrollShow: true,
labelCount: 4,
// scrollAlign: 'left',
// scrollColor: '#24B383',
// scrollBackgroundColor: '#DFE5E4',
// itemCount: '5',
2023-09-28 10:07:02 +00:00
boundaryGap: "justify",
2023-10-13 09:07:57 +00:00
// format: "",
2023-09-28 10:07:02 +00:00
},
yAxis: {
gridType: "dash",
dashLength: 2,
2023-10-13 06:58:18 +00:00
showTitle: true,
2023-09-28 10:07:02 +00:00
data: [{
2023-10-13 06:58:18 +00:00
title: '',
2023-09-28 10:07:02 +00:00
min: 0,
2023-10-13 09:07:57 +00:00
// max: '',
2023-10-13 06:58:18 +00:00
titleOffsetY: -5,
2023-09-28 10:07:02 +00:00
}]
},
extra: {
area: {
type: "curve",
2023-10-13 09:07:57 +00:00
opacity: 0.8,
2023-09-28 10:07:02 +00:00
addLine: true,
width: 2,
gradient: true,
activeType: "hollow"
}
}
},
2023-10-13 09:07:57 +00:00
categoriesList: [],
valuePH: '',
valuePHList: [],
newValuePHList: [],
unit: '',
titleName: '',
echartName: ''
2023-09-28 10:07:02 +00:00
};
},
onReady() {
// this.getEchartsData()
// this.getServerData();
2023-10-13 09:07:57 +00:00
2023-09-28 10:07:02 +00:00
},
onLoad(option) {
2023-10-13 09:07:57 +00:00
// console.log(option);
if (option.id) {
2023-09-28 10:07:02 +00:00
this.equipmentId = option.id
}
2023-10-13 09:07:57 +00:00
if (option.data) {
2023-09-28 10:07:02 +00:00
this.valuePH = option.data
}
2023-10-13 09:07:57 +00:00
if (option.name) {
2023-10-13 00:55:47 +00:00
this.echartName = option.name
}
2023-10-13 09:07:57 +00:00
if (option.unit) {
2023-10-13 06:58:18 +00:00
this.unit = option.unit
this.opts.yAxis.data[0].title = option.unit
}
2023-10-13 09:07:57 +00:00
this.titleName = this.getStatus(option.equipmentNumber, option.targetValue)
2023-09-28 10:07:02 +00:00
},
mounted() {
2023-10-13 09:07:57 +00:00
this.getEchartsData()
2023-09-28 10:07:02 +00:00
},
methods: {
getServerData() {
2023-10-13 09:07:57 +00:00
2023-09-28 10:07:02 +00:00
//模拟从服务器获取数据时的延时
setTimeout(() => {
//模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
let res = {
2023-10-13 09:07:57 +00:00
categories: this.categoriesList,
2023-09-28 10:07:02 +00:00
series: [{
2023-10-13 09:07:57 +00:00
name: this.titleName + this.echartName,
2023-10-13 00:55:47 +00:00
data: this.newValuePHList
2023-09-28 10:07:02 +00:00
}, ]
};
this.chartData = JSON.parse(JSON.stringify(res));
}, 500);
},
2023-10-13 09:07:57 +00:00
2023-09-28 10:07:02 +00:00
// 获取折线图数据
2023-10-13 09:07:57 +00:00
getEchartsData() {
2023-09-28 10:07:02 +00:00
this.$http({
2023-10-13 09:07:57 +00:00
url: this.api.chart_fsdata + '?equipmentId=' + this.equipmentId,
method: 'POST'
}).then(res => {
console.log(res, '获取折线图数据');
res.data.forEach((i, index) => {
2023-09-28 10:07:02 +00:00
this.categoriesList.push(i.time);
2023-10-13 00:55:47 +00:00
this.valuePHList.push(i.value)
2023-09-28 10:07:02 +00:00
})
2023-10-13 09:07:57 +00:00
this.getServerData();
this.categoriesList = this.categoriesList.map(item => {
return item.split(' ')[1]
})
// this.opts.xAxis.itemCount = this.categoriesList.length
2023-10-13 00:55:47 +00:00
// console.log(this.categoriesList,'this.categoriesList');
// console.log(this.valuePHList,'this.valuePHList');
2023-10-13 09:07:57 +00:00
this.newValuePHList = this.valuePHList.map((e, index) => {
return e[this.titleName + this.echartName] == undefined ? '' : e[this.titleName +
this.echartName]
2023-10-13 00:55:47 +00:00
})
2023-10-13 09:07:57 +00:00
console.log(this.newValuePHList, '121212212121211111111');
2023-09-28 10:07:02 +00:00
})
},
2023-10-13 09:07:57 +00:00
2023-10-13 00:55:47 +00:00
// 判断是否是平均或者目标,或者是1#
2023-10-13 09:07:57 +00:00
getStatus(equipmentNumber, targetValue) {
if (targetValue == 1) {
2023-10-13 00:55:47 +00:00
return '目标'
2023-10-13 09:07:57 +00:00
} else if (targetValue == 0 && equipmentNumber == 0) {
2023-10-13 00:55:47 +00:00
return '1#平均'
2023-10-13 09:07:57 +00:00
} else if (targetValue == 0 && equipmentNumber == 15) {
2023-10-13 00:55:47 +00:00
return '2#平均'
2023-10-13 09:07:57 +00:00
} else if (targetValue == 0 && equipmentNumber != 0 && equipmentNumber != 15) {
2023-10-13 00:55:47 +00:00
return equipmentNumber + '#'
}
}
2023-09-28 10:07:02 +00:00
}
}
</script>
<style lang="scss" scoped>
.target_water_fertilizer_PH {
width: 100%;
min-height: 100vh;
box-sizing: border-box;
position: relative;
background-color: #F5F6FA;
.navbar {
width: 100%;
height: 100%;
>image {
width: 750rpx;
height: 440rpx;
position: absolute;
top: 0;
left: 0;
}
}
.content {
position: absolute;
z-index: 2;
box-sizing: border-box;
padding: 0 30rpx 30rpx;
display: flex;
flex-direction: column;
align-items: center;
.number {
font-size: 100rpx;
font-family: Nexa Bold;
font-weight: 400;
color: #FFFFFF;
}
.data_analysis {
width: 100%;
text-align: center;
margin-bottom: 59rpx;
>image {
width: 30rpx;
height: 30rpx;
margin-right: 15rpx;
}
>text {
font-size: 28rpx;
font-family: PingFang-SC-Bold;
font-weight: bold;
color: #FFFFFF;
}
}
.echart {
width: 690rpx;
height: 1060rpx;
background: #FFFFFF;
box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(153, 153, 153, 0.1);
border-radius: 20rpx;
box-sizing: border-box;
padding-top: 30rpx;
.title {
width: 200rpx;
height: 44rpx;
background: #EFFCF7;
border: 2px solid rgba(58, 187, 144, 0.25);
border-radius: 22rpx;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
>image {
width: 36rpx;
height: 10rpx;
margin-right: 10rpx;
}
>text {
font-size: 20rpx;
font-family: PingFang-SC-Bold;
font-weight: bold;
color: #37BA8E;
}
}
#echart_p {
width: 100%;
height: calc(100% - 74rpx);
box-sizing: border-box;
2023-10-13 09:07:57 +00:00
padding: 0 0rpx;
2023-09-28 10:07:02 +00:00
}
}
}
}
</style>