<template>
	<view class="content">
		<view class="top">
			<image class="top_logo" src="../../static/logo.png" mode=""></image>
			<image class="tite" src="../../static/tite.png" mode=""></image>
			<view class="time">
				<view class="time_top">
				{{ formattedTime}}
				</view>
				<view class="time_bottom">
					<view>
						
					</view>
					<view class="time_bottom1">
						连接状态：
						<view class="time_state" v-if="status=='ok'">
							在线
						</view>
						<view class="time_state1" v-else>
							离线
						</view>
					</view>
					
				</view>
			</view>
		</view>
		<view class="tap">
			<view class="tap_1">
				AC
			</view>
			<view class="tap_2">
				DC
			</view>
			<view class="tap_3">
				System
			</view>
		</view>
     <view class="power">
     	<view class="power_1">
			<image v-if="selectorid!=3&&selectorindex==1" src="../../static/choice1.png" mode=""></image>
			<image v-else src="../../static/electricity.png" mode="" @click="onclick(3)"></image>
     	</view>
		<view class="power_1">
			<image v-if="selectorid!=2&&selectorindex==1" src="../../static/choice2.png" mode=""></image>
			<image v-else src="../../static/power1.png" mode="" @click="onclick(2)"></image>
		</view>
		<view class="power_1">
			<image v-if="selectorid!=4&&selectorindex==1" src="../../static/choice3.png" mode=""></image>
			<image v-else src="../../static/direct1.png" mode="" @click="onclick(4)"></image>
		</view>
		<view class="power_1">
			<image v-if="selectorid!=1&&selectorindex==1" src="../../static/choice4.png" mode=""></image>
			<image v-else src="../../static/DCpower1.png" mode="" @click="onclick(1)"></image>
		</view>
		<view class="power_5" @click="system">
			<image src="../../static/system.png" mode=""></image>
		</view>
     </view>
	 <view class="power_6" v-if="selectorindex==1">
	 	<image src="../../static/!.png" mode=""></image>若想重新选择模式，请返回之前模式停止以后再重新选择！
	 </view>
	 <uni-popup ref="message" type="message">
	 				<uni-popup-message type="error" :message="messageText" :duration="2500"></uni-popup-message>
	 			</uni-popup>
	</view>
</template>
<script>
	import {getuidatas,control} from "../../api/api.js"
	import {getTime} from "../../utils/index.js"
	import { mapState } from 'vuex';
	export default {
		data() {
		
			return {
				title: '',
				uidatas:'',
				formatTimeid:'',
				messageText:''
			}
		},
		created() {
	 
		  },
		mounted(){
		
		},
		
		computed: {
		  // 使用 mapState 映射多个状态到组件的计算属性
		    ...mapState(['formattedTime','status','selectorid','selectorindex']),
		    ...mapState({
		      uidatasdata: state => state.uidatasdata
		    })
		},
		onLoad() {
		   // this.onfaultsList();
		   
		},
		beforeUnmount() {
			clearInterval(this.uidatas);
			// clearInterval(this.formatTimeid);
		},
		methods: {

         onclick(e){
			this.pattern(e)
		 },
		 pattern(unm){
			 let data = {
			 		id: "c32e6a80-9159-4f6e-9acc-8525cf177808",
			 		issaveinitvalue:true,
			 		value:unm+''  // 直流供电=1，直流补电=4，交流供电=2，交流补电=3
			 	}
			 	control(data).then(data => {
			 		console.log(data);
			 		if (data.status == 'ok') {
			 		if (unm==3) {
			 			uni.redirectTo({
			 			  url: '/pages/home/index'
			 			});
			 		} else if(unm==2){
			 			uni.redirectTo({
			 			  url: '/pages/electricity/index'
			 			});
			 		}else if(unm==4){
			 			uni.redirectTo({
			 			  url: '/pages/supply/supply'
			 			});
			 		}else if(unm==1){
			 			uni.redirectTo({
			 			  url: '/pages/supplyss/supplyss'
			 			});
			 		}
			 		} else {
						 // uni.hideLoading()
						 // uni.showToast({
						 //   title:'选择模式失败请重新选择',
						 //   icon: 'warning',
						 //   duration: 2500, // 显示时长，单位为毫秒
						 // });
						 this.messageText = '选择模式失败请重新选择'
						 this.$refs.message.open()
						 return
			 		}
			 	});
		 },
		 system(){
			uni.redirectTo({
			  url: '/pages/faultlist/index'
			}); 
		 }
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		height: 100vh;
		opacity: 1;
		background: linear-gradient(180deg, rgba(215, 230, 245, 0) 0%, rgba(196, 229, 255, 1) 100%);
box-sizing: border-box;
	}
	.top {
		 width: 100%;
		 height: 100px;
		 display: flex;
       align-items: center;
	  justify-content: space-between;
background-size: 100% 100%;
background-repeat: no-repeat;
box-sizing: border-box;
background-color: #fff;
		padding: 0px 46px;
	}
	.top_logo{
		width:426px;
		height: 68px;
	}
	.tite{
		 width:277px;
		 height: 48px;
	}
	.time{
	text-align: right;
	}
	.time_top{
		font-size: 17px;
	}
.time_bottom{
	display: flex;
	font-size: 17px;
	justify-content: space-between;
}
.time_bottom1{
	display: flex;
}
.time_state{
	font-size: 17px;
	font-weight: 600;
	color: rgba(22, 68, 144, 1);
}
.time_state1 {
		font-size: 17px;
		font-weight: 600;
		color: rgba(217, 22, 22, 1);
	}
	 .tap{
		width: 100%;
		height: 46.01px;
		 display: flex;
		 justify-content: space-between;
		 margin-top: 118px;
		 margin-bottom: 50px;
		 padding: 0px 40px;
		 box-sizing: border-box;
	 }
	 .tap_1{
	   width: 485.57px;
      height: 46.5px;
	  border-radius: 50px;
	  background: linear-gradient(180deg, rgba(43, 158, 218, 1) 0%, rgba(39, 114, 186, 1) 100%);
	  display: flex;
	  align-items: center;
      justify-content: center;
  font-size: 35.24px;
  font-weight: 700;
  color: #fff;
	 }
	 .tap_2{
		width: 485px;
		    height: 46.5px;
			  border-radius: 50px;
			  background: linear-gradient(180deg, rgba(43, 158, 218, 1) 0%, rgba(39, 114, 186, 1) 100%);
			  display: flex;
			  align-items: center;
		    justify-content: center;
		font-size: 35.24px;
		font-weight: 700;
		color: #fff; 
	 }
	 .tap_3{
		 width: 155.17px;
		 height: 46.01px;
		 opacity: 1;
		 border-radius: 24.47px;
		 background: linear-gradient(180deg, rgba(43, 158, 218, 1) 0%, rgba(39, 114, 186, 1) 100%);
         display: flex;
		 align-items: center;
		    justify-content: center;
			font-size: 30px;
			font-weight: 700;
			color: #fff; 
	 }
	 .power{
		 width: 100%;
		display: flex; 
		justify-content: space-between;
		padding: 0px 50px;
		box-sizing: border-box;
	 }
	 .power_1{
		width: 237.55px;
		height: 298.98px;
		opacity: 1;
		box-sizing: border-box;
 image {
 	 width: 100%;
 	 height: 100%;
 }
	 }
	 
	 .power_11{
		width: 237.55px;
				height: 298.98px;
				opacity: 1;
				box-sizing: border-box;
				font-size: 23px;
				font-family: 400;
	              display: flex;
				  flex-direction: column;
          align-items: center;
     .power_image{
		 width: 100%;
		 height: 248px;
		 margin-bottom: 20px;
		 background-image: url("../../static/electricity1.png");
		 background-size: 100% 100%;
		 display: flex;
          align-items: center;
		  justify-content: center;
		  padding: 0px 16px;
		  box-sizing: border-box;
		image{
			width: 100%;
			height: 160.06px;
		} 
	 }
	 }
	 .power_5{
		 width: 154.19px;
		 height: 297.61px;
		 opacity: 1;
		 margin-left: 20px;
 image{
 	 width: 100%;
 	 height: 100%;
 }
	 }
	 .power_6{
		 width: 100%;
		 height: 50px;
		 font-size: 17.62px;
		 margin-top: 80px;
		 display: flex;
		 align-items: center;
		 padding: 0px 20px;
		 box-sizing: border-box;
		 position: fixed;
		 left: 0px;
		 bottom: 64px;
		 image{
		 margin-right: 10px;
			 width: 27.41px;
			 height: 27.41px;
		 };
	 }
</style>
