wszhyWx/pages/preciseWaterAndFertilizer/preciseWaterAndFertilizer.vue

206 lines
4.4 KiB
Vue
Raw Normal View History

2023-09-28 10:07:02 +00:00
<template>
<view class="preciseWaterAndFertilizer">
2023-10-09 10:07:25 +00:00
<u-navbar :background="background" :is-back='true' back-icon-color='#FFFFFF' :border-bottom="false" title="精准水肥"
title-color='#FFFFFF' :title-bold='true' title-size='32'></u-navbar>
2023-09-28 10:07:02 +00:00
<view class="content">
<view class="item" v-for="item,index in deviceList" :key="index">
2023-10-05 04:08:22 +00:00
<image src="../../static/icon_precise.png" mode=""></image>
2023-09-28 10:07:02 +00:00
<view class="center">
<text>{{item.deviceTypeName}}</text>
2023-10-09 10:07:25 +00:00
<text
:class="item.deviceState == 1 ? 'state' : 'state_act'">{{ item.deviceState == 1 ? "在线" : "离线"}}</text>
2023-09-28 10:07:02 +00:00
</view>
<view class="right" @click="toFertilizer(item)" v-if="item.deviceState == 1">
2023-09-28 10:07:02 +00:00
<text>状态</text>
2023-10-05 04:08:22 +00:00
<image src="../../static/right-arrow.png" mode=""></image>
2023-09-28 10:07:02 +00:00
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 头部导航背景
background: {
backgroundColor: '#24B383',
},
2023-10-09 10:07:25 +00:00
deviceList: []
2023-09-28 10:07:02 +00:00
};
},
onLoad() {
2023-10-09 10:07:25 +00:00
uni.showLoading({
title: '加载中...'
})
2023-09-28 10:07:02 +00:00
uni.getStorage({
key: 'token',
success: function(res) {
that.getEquipmentInfo(uni.getStorageSync('userid'))
},
2023-10-09 10:07:25 +00:00
fail: function(err) {
2023-09-28 10:07:02 +00:00
uni.reLaunch({
2023-10-09 10:07:25 +00:00
url: '/pages/login/login'
2023-09-28 10:07:02 +00:00
})
}
})
2023-10-09 10:07:25 +00:00
const that = this
setInterval(function() {
uni.getStorage({
key: 'token',
success: function(res) {
2023-10-14 03:16:59 +00:00
// uni.showLoading({
// title: '加载中...'
// })
2023-10-09 10:07:25 +00:00
that.getEquipmentInfo(uni.getStorageSync('userid'))
}
})
}, 120000);
2023-09-28 10:07:02 +00:00
},
2023-10-09 10:07:25 +00:00
onPullDownRefresh() {
uni.showLoading({
title: '加载中...'
})
const that = this
uni.getStorage({
key: 'token',
success: function(res) {
that.getEquipmentInfo(uni.getStorageSync('userid'))
}
})
},
methods: {
2023-09-28 10:07:02 +00:00
// 离线或者在线
2023-10-09 10:07:25 +00:00
toFertilizer(item) {
2023-09-28 10:07:02 +00:00
uni.navigateTo({
2023-10-09 10:07:25 +00:00
url: '/pages/fertilizer_machine/fertilizer_machine?id=' + item.deviceId
2023-09-28 10:07:02 +00:00
})
},
2023-10-09 10:07:25 +00:00
2023-09-28 10:07:02 +00:00
// 根据用户id查询对应的设备数据
getEquipmentInfo(userid) {
let that = this
this.$http({
url: this.api.sel_eqbyid + userid,
method: 'GET'
}).then(res => {
2023-10-09 10:07:25 +00:00
// console.log(res, '根据用户id查询对应的设备数据');
2023-09-28 10:07:02 +00:00
if (res.code == 200) {
2023-10-09 10:07:25 +00:00
uni.hideLoading()
uni.stopPullDownRefresh();
this.deviceList = res.data
}else {
this.$refs.uToast.show({
title: res.msg,
type: 'error',
})
2023-09-28 10:07:02 +00:00
}
})
},
}
}
</script>
<style lang="scss">
2023-10-09 10:07:25 +00:00
.preciseWaterAndFertilizer {
width: 100%;
min-height: 100vh;
background-color: #F5F6FA;
.content {
2023-09-28 10:07:02 +00:00
box-sizing: border-box;
2023-10-09 10:07:25 +00:00
padding: 30rpx;
.item {
width: 690rpx;
height: 100rpx;
background: #FFFFFF;
box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(153, 153, 153, 0.1);
border-radius: 15rpx;
2023-09-28 10:07:02 +00:00
display: flex;
align-items: center;
2023-10-09 10:07:25 +00:00
justify-content: space-between;
box-sizing: border-box;
padding: 0 20rpx 0 26rpx;
margin-bottom: 10rpx;
>image {
width: 60rpx;
height: 56rpx;
margin-right: 14rpx;
}
.center {
display: flex;
align-items: center;
flex: 1;
>text:nth-child(1) {
font-size: 34rpx;
font-family: PingFang-SC-Bold;
font-weight: bold;
color: #333333;
margin-right: 11rpx;
}
>.state {
width: 66rpx;
height: 34rpx;
background: #EFFCF7;
border: 2px solid rgba(58, 187, 144, 0.25);
border-radius: 17rpx;
font-size: 20rpx;
font-family: PingFang-SC-Bold;
font-weight: bold;
color: #24B383;
display: flex;
justify-content: center;
align-items: center;
}
>.state_act {
width: 66rpx;
height: 34rpx;
background: #F5F6FA;
border: 2px solid #E1E2E6;
border-radius: 17rpx;
font-size: 20rpx;
font-family: PingFang-SC-Bold;
font-weight: bold;
color: #999999;
display: flex;
justify-content: center;
align-items: center;
}
2023-09-28 10:07:02 +00:00
}
2023-10-09 10:07:25 +00:00
.right {
width: 120rpx;
height: 54rpx;
background: #F5F6FA;
border: 2px solid #E1E2E6;
border-radius: 10rpx;
2023-09-28 10:07:02 +00:00
display: flex;
justify-content: center;
align-items: center;
2023-10-09 10:07:25 +00:00
>text {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: bold;
color: #666666;
}
>image {
width: 12rpx;
height: 20rpx;
margin-left: 20rpx;
}
2023-09-28 10:07:02 +00:00
}
}
}
}
2023-10-09 10:07:25 +00:00
</style>