<template>
	<view>
		<uni-row style="background-color:cadetblue;height: 40px;">
			<view style="margin-top: 10px;height: 100%;width: 100%;">
				<uni-col :span="9" style="margin-right: 5px;margin-left: 50px;">
					<u-icon label="电量:" labelPos="right" label-color="white" size="30"
						name="../../static/images/dianliangsq.png"></u-icon>
				</uni-col>
				<uni-col :span="9" style="margin-left: 5px;">
					<view class="valuecol">
						{{itemProperty.et}}%
					</view>
				</uni-col>
				<!-- <uni-col :span="10" style="margin-left: 5px;">
					<u-button text="历史" type="success"
						style="height: 30px;width: 80px;margin-bottom: 2px;margin-top: 2px;"></u-button>
				</uni-col> -->
			</view>
		</uni-row>
		<uni-row style="background-color:cadetblue;height: 60px;">
			<view class="rowview">
				<uni-col :span="4" style="margin-right: 5px;margin-left: 40px;">
					<view class="valuecol">
						开关
					</view>
				</uni-col>
				<uni-col :span="4" style="margin-left: 5px;">
					<u-button :text="`${itemProperty.sc == 1? '关闭':'开启'}`"
						:type="`${itemProperty.sc == 1? 'success':'info'}`" @click="pump(itemProperty.sc)"
						style="height: 27px;width: 80px;margin-top: 3px;"></u-button>
				</uni-col>
			</view>
		</uni-row>
	</view>
</template>
<script setup>
	import {
		ref
	} from "vue"
	import {
		onShow,
		onLoad,
		onReady,
		onUnload
	} from '@dcloudio/uni-app'
	import plugin from '@/plugins'
	import store from '@/store'
	const item = ref({})
	const itemProperty = ref({})
	const timestr = ref("")
	const datestr = ref("")
	const time3 = ref({});
	const time4 = ref({});
	const Intervalflag = ref(true);
	const disabled1 = ref(false);
	const disabled2 = ref(false);
	const flValue = ref(0);
	//页面跳转值
	onLoad(info => {
		if (info.item != null) {
			item.value = JSON.parse(decodeURIComponent(info.item));
			queryList();
			time3.value = setInterval(() => {
				if (Intervalflag.value) {
					queryList();
				} else {
					clearInterval(time3.value);
				}
			}, 3000);
		}
	})
	onUnload(info => {
		Intervalflag.value = false;
		clearInterval(time3);		
	})

	function queryList() {
		let par = {
			"deviceCode": item.value.deviceCode,
			"iotId": item.value.iotId,
			"deviceTypeId": 10
		};
		store.dispatch('getPesticideLampDevicePropertyStatus', par)
			.then(res => {
				itemProperty.value = res.data
			}).catch(error => {
				plugin.modal.msgError(error);
			}).finally(() => {})
	}

	//开关
	function pump(e) {
		if (item == null) return;
		let par = {
			controlKey: "sc",
			deviceTypeId: 10,
			operationType: 11,
			deviceCode: item.value.deviceCode,
			controlValve: e == 1 ? 0 : 1
		};
		store.dispatch('controlHeadSwitch', par)
			.then(res => {
				queryList();
			}).catch(error => {
				plugin.modal.msgError(error);
			}).finally(() => {})
	}



	//关闭页面
	function onClosePage() {
		//plugin.tab.switchTab("/pages/index")
		uni.navigateBack({
			delta: 1
		})
	}

</script>

<style lang="scss">
	.uni-page-head {
		display: none
	}

	.demo-uni-col {
		height: 32px;
		border-radius: 2px;
	}

	.dark {
		background-color: cadetblue;
	}

	.light {
		background-color: cadetblue;
	}

	.rowview {
		margin-top: 5px;
		height: 100%;
		width: 100%;

	}

	.valuecol {
		height: 80%;
		margin-top: 2px;
		margin-bottom: 2px;
		text-align: center;
		line-height: 25px;
		font-size: 14px;
		// border: 1px solid black;
		width: 95%;
		// background-color: white;
		color: white;
	}
</style>