<template>
	<view style="background:#f1f1f1;" class="padding-sm">
		<!-- 下拉选择 -->
		<view class="searchSelect shadow" v-if="flag">
			<view class="cu-bar search bg-white">
				<view class="search-form round" style="margin-top:0">
					<input @focus="InputFocus" @blur="InputBlur" @input="handleInput()" v-model="searchInput"
						:adjust-position="false" type="text" placeholder="" confirm-type="search"
						style="border:none!important"></input>
					<text class="cuIcon-search "></text>
				</view>
			</view>
			<view class="select-items">
				<view class="select-item" v-for="(item,index) in searchList" @click="clickSelectItem(item,index)"
					:key="index">{{item}}</view>
			</view>
		</view>
		<!-- 下拉选择 end -->
		<!-- <search-Select :flag="flag"></search-Select> -->

		<!-- 图表 -->
		<view class="section1 section bg-white padding-xs">
			<view class=" static-tabs grid margin-bottom text-center col-3 margin-top-sm margin-bottom-sm">
				<view :class="['padding-sm ',Inv==0?'active':'']" @click="Inv=0">报警信息统计</view>
				<view :class="['padding-sm ',Inv==1?'active':'']" @click="Inv=1">数据等级统计</view>
				<view :class="['padding-sm ',Inv==2?'active':'']" @click="Inv=2">设备运行状态</view>
			</view>
			<view class="time text-center">统计时段：{{staticData.statisticalPeriod}}
			</view>
			<view style="height:570rpx">
				<view v-if="Inv == 0">
					<chart :bindData="staticData" v-if="hackReset"></chart>
				</view>
				<view v-if="Inv == 1">

					<chart2 :bindData="staticData"></chart2>
				</view>
				<view v-if="Inv == 2" class="chart3-box" >
					<ul class="chart3-icon">
						<li @tap="goOfflineList()">
							<image src="../../static/chart3-1.png" style="width:64rpx;height:64rpx"></image>
						</li>
						<li  @tap="goFaultList()">
							<image src="../../static/chart3-2.png" style="width:64rpx;height:64rpx"></image>
						</li>
						<li>
							<image src="../../static/chart3-3.png" style="width:64rpx;height:64rpx"></image>
						</li>
						<li>
							<image src="../../static/chart3-4.png" style="width:64rpx;height:64rpx"></image>
						</li>
						<li>
							<image src="../../static/chart3-5.png" style="width:64rpx;height:64rpx"></image>
						</li>
					</ul>
					<chart3 :bindData="staticData" :searchList="searchList"  :searchList2="searchList2">
					</chart3>
				</view>
			</view>
		</view>
		<!-- 图表 end-->

		<!-- 宫格列表 -->
		<view class="section2 section  bg-white margin-top-sm margin-bottom-sm">
			<view class="cu-list grid col-3 no-border">
				<view class="cu-item justify-center align-center" @tap=navItemClick(index)
					v-for="(item,index) in cuIconList" :key="index">
					<image :src="item.imgUrl" style="width:100rpx;height:100rpx"></image>
					<view class="cu-tag badge" v-if="item.badge!=0">
						<block v-if="item.badge!=1">{{item.badge>99?'99+':item.badge}}</block>
					</view>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<!-- 宫格列表 end -->
	</view>
</template>

<script>
	import chart from './components/chart/chart.vue';
	import chart2 from './components/chart2/chart2.vue';
	import chart3 from './components/chart3/chart3.vue';
	
	import searchSelect from './components/searchSelect/searchSelect.vue';
	
	
	import json from '../../data/json.js';

	export default {
		components: {
			chart,
			chart2,
			chart3,
			searchSelect
		},

		data() {
			return {
				staticData: json.staticData.data[0],
				alarmCount: json.staticData.data[0].alarmCount,
				cuIconList: json.cuIconList,
				Inv: 0,

				
				flag: false,
				searchList: [],
				searchList2: [],
				
				
				searchInput: '',
			};
		},

		// 自定义导航事件
		onNavigationBarButtonTap(e) {
			if (e.float == 'right') {
				console.log("你点击了扫一扫")
			} else {
				this.showTag()
			}
		},

		onLoad(option) {

			// 图表切换渲染
			this.hackReset = true;
		

			// 数据渲染
			this.getSearchList();
		},
		methods: {
			// 九宫格页面跳转
			navItemClick(index) {
				let url = "";
				switch (index) {
					case 0:
						url = "/pages/alarmingList/alarmingList"
						break;
					case 1:
						url = "/pages/deviceType/deviceType"
						break;
					case 2:
						url = "/pages/inspectList/inspectList"
						break;
					case 3:
						url = "/pages/xunJian/xunJian"
						break;
					case 4:
						url = "/pages/repair/repair"
						break;
					case 5:
						url = "/pages/weiBao/weiBao"
						break;
					case 6:
						url = "/pages/videoList/videoList"
						break;
					case 7:
						url = "/pages/safeGuard/safeGuard"
						break;
						// case 8:
						// 	url = "/pages/test/test"
						// 	break;
						case 9:
							url = "/pages/deviceManage/deviceManage"
							break;
						case 10:
							url = "/pages/accountManage/accountManage"
							break;
						
					default:
						break;
				}
				if (url) {
					uni.navigateTo({
						url: url
					})
				} else {
					uni.showModal({
						title: 'Tips',
						content: '此模块开发中~',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {} else if (res.cancel) {}
						}
					});
				}
			},
			// 页面跳转
			goOfflineList() {
				uni.navigateTo({
					url: '/pages/deviceOffLine/deviceOffLine?type=离线',
				});
				
			},
			goFaultList() {
				uni.navigateTo({
					url: '/pages/deviceOffLine/deviceOffLine?type=故障',
				});
				
			},
			

			//请求
			async getSearchList(ming = {}) {
				const res = await this.$myRequest({
					url: 'Index/getSiteDropDownBox',
					data: ming
				})
				res.data.data.forEach(item => {
					this.searchList.push(item.siteName)
					this.searchList2.push(item.siteName)
				});
			},
			
			showTag() {
				this.flag = !this.flag;
			},
			
			
			// 下拉选择
			clickSelectItem(item, index) {
				this.getSearchList({
					"siteName": item
				});
				this.flag = false
			},
			handleInput() {
				var newlist = this.searchList2.filter(item => item.indexOf(this.searchInput) > -1)
				this.searchList = newlist
			},

			

			InputFocus(e) {
				this.InputBottom = e.detail.height
			},
			InputBlur(e) {
				this.InputBottom = 0
			},

			changeTab(Inv) {
				that.navIdx = Inv;

			},


		
		}
	}
</script>

<style lang="scss">
	body {
		background: #f1f1f1 !important;
	}

	.select-items {
		overflow: auto;
		height: 80vh
	}

	.static-tabs {
		border-radius: 50rpx;
		border: 1rpx solid #4074E7;
	}

	.static-tabs>view {
		color: #4074E7;
		font-size: 30rpx;
	}

	.static-tabs>view.active {
		color: #fff;
		background: #4074E7
	}

	.static-tabs>view:first-child {
		border-top-left-radius: 50rpx;
		border-bottom-left-radius: 50rpx;
	}

	.static-tabs>view:nth-child(2) {
		border-left: 1px solid #4074E7;
		border-right: 1px solid #4074E7
	}

	.static-tabs>view:last-child {
		border-top-right-radius: 50rpx;
		border-bottom-right-radius: 50rpx;
	}


	/* 检测时间 */
	.time {
		border-radius: 50rpx;
		background: #FAFCFF;
		border: 1px solid #E8F1FF;
		padding: 20rpx;
		color: #666666;
		font-size: 30rpx;

	}

	.chart3-box {
		position: relative
	}

	.chart3-icon {
		width:90%;
		position: absolute;
		top: 60rpx;
		left: 30rpx;
		z-index:1;
	}

	.chart3-icon li {
		padding-top: 25rpx
	}

	ul,
	li {
		padding: 0;
		margin: 0;
		list-style: none
	}
</style>

<style>
	.shadow {
		box-shadow: 1px 1px 4px rgb(26 26 26 / 10%);
	}
</style>
