wszhyWx/pages/preciseWaterAndFertilizer/preciseWaterAndFertilizer.vue

206 lines
4.4 KiB
Vue

<template>
<view class="preciseWaterAndFertilizer">
<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>
<view class="content">
<view class="item" v-for="item,index in deviceList" :key="index">
<image src="../../static/icon_precise.png" mode=""></image>
<view class="center">
<text>{{item.deviceTypeName}}</text>
<text
:class="item.deviceState == 1 ? 'state' : 'state_act'">{{ item.deviceState == 1 ? "在线" : "离线"}}</text>
</view>
<view class="right" @click="toFertilizer(item)" v-if="item.deviceState == 1">
<text>状态</text>
<image src="../../static/right-arrow.png" mode=""></image>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 头部导航背景
background: {
backgroundColor: '#24B383',
},
deviceList: []
};
},
onLoad() {
uni.showLoading({
title: '加载中...'
})
uni.getStorage({
key: 'token',
success: function(res) {
that.getEquipmentInfo(uni.getStorageSync('userid'))
},
fail: function(err) {
uni.reLaunch({
url: '/pages/login/login'
})
}
})
const that = this
setInterval(function() {
uni.getStorage({
key: 'token',
success: function(res) {
// uni.showLoading({
// title: '加载中...'
// })
that.getEquipmentInfo(uni.getStorageSync('userid'))
}
})
}, 120000);
},
onPullDownRefresh() {
uni.showLoading({
title: '加载中...'
})
const that = this
uni.getStorage({
key: 'token',
success: function(res) {
that.getEquipmentInfo(uni.getStorageSync('userid'))
}
})
},
methods: {
// 离线或者在线
toFertilizer(item) {
uni.navigateTo({
url: '/pages/fertilizer_machine/fertilizer_machine?id=' + item.deviceId
})
},
// 根据用户id查询对应的设备数据
getEquipmentInfo(userid) {
let that = this
this.$http({
url: this.api.sel_eqbyid + userid,
method: 'GET'
}).then(res => {
// console.log(res, '根据用户id查询对应的设备数据');
if (res.code == 200) {
uni.hideLoading()
uni.stopPullDownRefresh();
this.deviceList = res.data
}else {
this.$refs.uToast.show({
title: res.msg,
type: 'error',
})
}
})
},
}
}
</script>
<style lang="scss">
.preciseWaterAndFertilizer {
width: 100%;
min-height: 100vh;
background-color: #F5F6FA;
.content {
box-sizing: border-box;
padding: 30rpx;
.item {
width: 690rpx;
height: 100rpx;
background: #FFFFFF;
box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(153, 153, 153, 0.1);
border-radius: 15rpx;
display: flex;
align-items: center;
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;
}
}
.right {
width: 120rpx;
height: 54rpx;
background: #F5F6FA;
border: 2px solid #E1E2E6;
border-radius: 10rpx;
display: flex;
justify-content: center;
align-items: center;
>text {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: bold;
color: #666666;
}
>image {
width: 12rpx;
height: 20rpx;
margin-left: 20rpx;
}
}
}
}
}
</style>