<template>
	<view class="deviceRegistWrapper" ref="contentWrapper">

		<!-- 筛选框start -->
		<view>
			<view style="height:206rpx"></view>
			<view class="ding">
				<view class="cu-bar search bg-gray filter-section" style="with:50%;">
					<view class="search-form round bg-white">
						<select name="" id="" placeholder="">
							<option value="">请选择设备类型</option>
							<option value="">类型1</option>
							<option value="">类型2</option>
						</select>
					</view>
					<view class="search-form round bg-white">
						<input type="text" placeholder="选输入设备点位" confirm-type="search"></input>
					</view>
				</view>
			
				<view class="cu-bar search bg-gray filter-section">
					<view class="search-form round bg-white" style="margin-bottom:26rpx">
						<input class="" @focus="InputFocus" v-model="siteName" @blur="InputBlur" :adjust-position="false"
							type="text" placeholder="选择传输方式" confirm-type="search"></input>
					</view>
					<view class="action">
						<button class="cu-btn bg-blue round" @click="searchData()">查询</button>
					</view>
				</view>
			</view>
		</view>
		<!-- 筛选框end -->


		<!-- 设备注册列表start -->
		<block class="">
			<view class="processList deviceRegistList" style="height: calc(100vh - 241px);">
				<view class="cu-list menu-avatar ">
					<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
						v-for="(item,index) in newDeviceManage" :key="index" :data-target="'move-box-' + index">
						<checkbox-group class="block" @change="CheckboxChange">
							<view class="cu-form-group margin-top">
								<checkbox class='blue' @click="selectedProduct(item)" :class="{'check':item.checked}" value="A"></checkbox>
							</view>
						</checkbox-group>
						<view class="cu-avatar round lg" style="background-image:url(../../static/device-icon.png)">
						</view>
						<view class="content" @longpress="showDetail(item)">
							<view class="pro-title">
								<view class="cut">{{item.title}}</view>
							</view>
							<view class="pro-des  ">
								<view class="text-cut">
									{{item.des}}
								</view>
							</view>
							<view class="pro-date ">{{item.time}}</view>
							
							<view class="showDetail"  v-if="item.isShow">
								<view @tap="goDeviceEdit()">修改设备</view>
								<view @tap="deleteItem" data-target="DialogModal2">删除设备</view>
							</view>
						</view>
						<view class="nav-right num">
							<view class="text-grey">
								<span class="online" v-if="item.status==0">在线</span>
								<span class="offline" v-if="item.status==1">离线</span>
								<span class="error" v-if="item.status==2">故障</span>
								<text class="icon iconfont margin-right-xs margin-left-lg">&#xe629;</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</block>
		<!-- 设备注册列表end -->


		<view class="share grid col-3 ">
			<view class="share-item  text-center">
				<view><text class="icon iconfont margin-xs" style="color:#19A402">&#xe66d;</text></view>
				<view @tap="goDeviceAdd()">新增</view>
			</view>
			<view class="share-item  text-center">
				<view><text class="icon iconfont margin-xs" style="color:#FF0303">&#xe66c;</text></view>
				<view @tap="deleteItem" data-target="DialogModal2">删除</view>
			</view>
			<view class="share-item  text-center" >
				<view><text class="icon iconfont margin-xs" style="color:#FF642E">&#xe66e;</text></view>
				<view @tap="showModal" data-target="DialogModal">导出</view>

			</view>
			<view class="checkAll">
				<checkbox-group class="block" @change="CheckboxChange" style="display:inline-block">
					<view class="cu-form-group margin-top">
						<checkbox class='blue' :class="checkbox[0].checked?'checked':''"
							:checked="checkbox[0].checked?true:false" value="A"></checkbox>
					</view>
				</checkbox-group> 
				<text class="margin-left-xs">全选</text>
			</view>
		</view>
		
		
		<!-- 导出弹框 -->
		<view class="cu-modal export-modal" :class="modalName=='DialogModal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close"></text>
					</view>
				</view>
				<view class="padding-sm bg-white">
					<image src="../../static/ok.png" style="width:100rpx;height:100rpx"></image>
					<view style="margin:20rpx 0">已导出文件，是否打开？</view>
				</view>
				<view class="cu-bar operate bg-white" style="min-height: 100rpx;">
					<view class="action margin-0   " @tap="hideModal">
						另存为</view>
					<view class="action margin-0  solid-left text-blue" @tap="hideModal">打开</view>
				</view>
			</view>
		</view>
		<!-- 导出弹框 end -->
		
		
		<!-- 删除弹框 -->
		<view class="cu-modal export-modal" :class="modalName=='DialogModal2'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close"></text>
					</view>
				</view>
				<view class="padding-sm bg-white">
					<image src="../../static/chart3-2.png" style="width:100rpx;height:100rpx"></image>
					<view style="margin:20rpx 0">确定删除该设备吗？</view>
				</view>
				<view class="cu-bar operate bg-white" style="min-height: 100rpx;">
					<view class="action margin-0   " @tap="hideModal">
						取消</view>
					<view class="action margin-0  solid-left text-blue"   @tap="openConfirmModal" data-target="DialogModal3">确定</view>
				</view>
			</view>
		</view>
		<!-- 删除弹框 end -->
		
		
		<!-- 再次确认删除弹框 -->
		<view class="cu-modal export-modal" :class="modalName=='DialogModal3'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close"></text>
					</view>
				</view>
				<view class="padding-sm bg-white">
					
					<view style="margin:20rpx 0">请输入图片中的验证码</view>
					<valid-code :value.sync="validCode"></valid-code>

				</view>
				<view class="cu-bar operate bg-white" style="min-height: 100rpx;">
					<view class="action margin-0   " @tap="hideModal">
						取消</view>
					<view class="action margin-0  solid-left text-blue" @tap="hideModal">确定</view>
				</view>
			</view>
		</view>
		<!-- 再次确认删除弹框 end -->
		
		
	</view>

</template>

<script>
	import json from '../../data/json.js';
	import validCode from './component/validCode/validCode';

	export default {
		components: {
			validCode
		},
		data() {
			return {
				validCode:'',

				checkbox: [{
					value: 'A',
					checked: false
				}],

				deviceManage: json.deviceManage,
				siteListRes: 0,
				siteName: '',
				type: '0',
				siteListData: [],
				modalName: null,
				// modalName2: null,
				listTouchStart: 0,
				listTouchDirection: null,
				CustomBar: this.CustomBar,
			};
		},


		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		computed: {
			newDeviceManage() {
				return this.deviceManage.map(item => {
					this.$set(item, "isShow", false)
					return item
				})
			}

		},


		mounted() {
			document.addEventListener('click', (e) => {
				if (e.target.className != 'showDetail') {
					this.deviceManage.forEach(item => {
						item.isShow = false
					})
				}
			})
		},

		methods: {
			selectedProduct:function(item){
				console.log(item)
						if(typeof item.checked=='undefined'){
							this.$set(item,'checked',true);
						}else{
							item.checked = !item.checked;
						}
					},

			// 页面跳转
			goDeviceAdd() {
				uni.navigateTo({
					url: '/pages/deviceManage/deviceAdd/deviceAdd',
				});
			},
			goDeviceEdit() {
				uni.navigateTo({
					url: '/pages/deviceManage/deviceEdit/deviceEdit',
				});
			},
			
			
			//导出弹框
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			
			//关闭弹框
			hideModal(e) {
				this.modalName = null
			},
			
			//删除弹出框操作
			deleteItem(e){
				this.modalName = e.currentTarget.dataset.target;
				
			},
			//再次确认弹框
			openConfirmModal(e){
				this.modalName = e.currentTarget.dataset.target;
				
			},

			CheckboxChange(e) {
				var items = this.checkbox,
					values = e.detail.value;
				for (var i = 0, lenI = items.length; i < lenI; ++i) {
					items[i].checked = false;
					for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
						if (items[i].value == values[j]) {
							items[i].checked = true;
							break
						}
					}
				}
			},

			// 隐藏显示
			showDetail(e) {
				// alert(1)
				// 存储点击那一项的状态
				const nowStatu = e.isShow;
				// 将每一项列表的isShow设置为false,让所有的列表都隐藏
				this.deviceManage.forEach(item => {
					item.isShow = false
				})
				// 用于再次点击该项的取反
				e.isShow = !nowStatu
			},
			InputFocus(e) {
				this.InputBottom = e.detail.height
			},
			InputBlur(e) {
				this.InputBottom = 0
			},
			
			



		}

	}
</script>

<style >
	.showDetail {
		position: absolute;
		background: #fff;
		box-shadow: 0 1px 6px 0 rgb(32 33 36 / 28%);
		border-radius: 10rpx;
		top: 50rpx;
		right: 47%;
		z-index: 3000000;
		font-size: 28rpx;
	}
	.showDetail view{
		padding: 0rpx 20rpx;
	}
	.showDetail view:first-child{
		border-bottom:1px solid #EDEDED;
	}
		

</style>
