<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>在线</text>
				</view>
				<view class="right" @click="toFertilizer(item)">
					<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() {
			const that= this
			uni.getStorage({
				key: 'token',
				success: function(res) {
					that.getEquipmentInfo(uni.getStorageSync('userid'))
				},
				fail:function(err){
					uni.reLaunch({
						url:'/pages/login/login'
					})
				}
			})
		},
		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) {
						this.deviceList=res.data
					}
				})
			},
		}
	}
</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;
				}
				>text:nth-child(2){
					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;
				}
			}
			
			.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>
