<template>
	<view class="container">
	<!-- 	<view class="banner-box">
			<image v-if="currentTabIndex == 0" src="/static/imgs/check.jpg" mode=""></image>
			<image v-if="currentTabIndex == 1" src="/static/imgs/check.jpg" mode=""></image>
		</view> -->
		 
		<view class="content" v-if="currentTabIndex == 0">
			<view class="" style="padding: 1vh 3vh 1vh 3vh;margin-top: 3vh;" >
				<view class="form-box">
					<view class="form-item">
						<text class="label">访客预约:</text>
						<!-- <view class="ipt-box"><input class="top-t" v-model="formBxwz" placeholder="请填写位置" type="text" maxlength="50" /></view> -->
						<view class="ipt-box select">
							<!-- <picker class="picker"  style="text-align: right;margin-right: 3vh;" v-if="visitSwich.length > 0" :range="visitSwich" @change="changePlace" range-key="name">
								<view>{{ visitSwich[visitSwichIndex].name }}</view>
							</picker> -->
							<view  style="text-align: right;position: relative;float: right;">
								<view>
									<switch :checked="vschecked" @change="visitChangePlace"  
									style="transform:scale(0.8);">
									</switch>
									<view v-if="vschecked == true" style="position: absolute;font-size: 20upx;
										float: right;
										left: 18%;
										bottom:25%;
										color: #fff;">开</view>
									<view  v-if="vschecked == false" style="position: absolute;font-size: 20upx;
											float: right;
											right: 24%;
											bottom:25%;
											color: #c2c2c2;">关</view>
								</view>
							</view>
							
						</view>
					</view>
				</view>
			</view>
			<view class="" style="padding: 1vh 3vh 1vh 3vh;">
				<view class="form-box">
					<view class="form-item">
						<text class="label">摄像头报警:</text>
						<!-- <view class="ipt-box"><input class="top-t" v-model="formBxwz" placeholder="请填写位置" type="text" maxlength="50" /></view> -->
						<view class="ipt-box select">
							<view  style="text-align: right;position: relative;float: right;">
								<switch :checked="cmchecked" style="transform:scale(0.8)" @change="cameraChangePlace"></switch>
								<view v-if="cmchecked == true" style="position: absolute;font-size: 20upx;
									float: right;
									left: 18%;
									bottom:25%;
									color: #fff;">开</view>
								<view v-if="cmchecked == false" style="position: absolute;font-size: 20upx;
											float: right;
											right: 24%;
											bottom:25%;
											color: #c2c2c2;">关</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="" style="padding: 1vh 3vh 1vh 3vh;">
				<view class="form-box">
					<view class="form-item">
						<text class="label" style="width: auto;">访客后勤部审批:</text>
						<!-- <view class="ipt-box"><input class="top-t" v-model="formBxwz" placeholder="请填写位置" type="text" maxlength="50" /></view> -->
						<view class="ipt-box select">
							<view  style="text-align: right;position: relative;float: right;">
								<switch :checked="approvalchecked" style="transform:scale(0.8)" @change="approvalChangePlace"></switch>
								<view v-if="approvalchecked == true" style="position: absolute;font-size: 20upx;
									float: right;
									left: 18%;
									bottom:25%;
									color: #fff;">开</view>
								<view v-if="approvalchecked == false" style="position: absolute;font-size: 20upx;
											float: right;
											right: 24%;
											bottom:25%;
											color: #c2c2c2;">关</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view style="padding: 5upx 50upx 5upx 30upx;">【提示】</view>
			<view style="padding: 10upx 50upx 10upx 70upx;font-size: 28upx;color: #a2a2a2;">1.访客预约用于控制App端访客预约是否开放。</view>
			<view style="padding: 10upx 50upx 10upx 70upx;font-size: 28upx;color: #a2a2a2;">2.摄像头报警用于控制安检门处声音报警的开关。</view>
			<view style="padding: 10upx 50upx 10upx 70upx;font-size: 28upx;color: #a2a2a2;">3.访客后勤部审核开关打开后，所有访客审批均需要后勤部审核。</view>
			
			<view class="occupied"></view>
			<!-- <view class="footer-btn" @click="submit"><view class="btn">提交</view></view> -->
		</view>
		<!-- 检查列表 -->
		<view v-else>
			<view class="list-content" v-if="repair.length > 0">
				<view class="details" v-for="(item, i) in repair" :key="i" @click="details(item)">
					<view class="detail_header">
						<text class="blueSign"></text>
						<text class="font-tilte">巡检考核</text>
						<text :class="item.statusCode == 11 ? 'statusgr' : 'statusred'">{{ item.status }}</text>
					</view>

					<view class="detail_msg">
						<view class="info-item">
							<text>巡检人：</text>
							<text class="infoSpan">{{ item.userName }}</text>
						</view>
						<view class="info-item">
							<text>巡检选项：</text>
							<text class="infoSpan">{{ fixList[item.opt - 1].title }}</text>
						</view>
						<view class="info-item">
							<text>巡检位置：</text>
							<text class="infoSpan">{{ item.repairAddr }}</text>
						</view>
						<view class="info-item">
							<text>改善建议：</text>
							<text class="infoSpan">{{ item.faultDetail }}</text>
						</view>
						<view class="info-item">
							<text>巡检时间：</text>
							<text class="infoSpan">{{ formatDate(item.apply_time, 'dateTime') }}</text>
						</view>
						<!-- <view class="comment-btn" v-if="item.conmentStatus == 0" @click="goEvaluatePage(item.detailId)">评价</view> -->
						<!-- <view class="comment-btn bg-ccc" v-if="item.conmentStatus == 1">已评价</view> -->
					</view>
				</view>
			</view>
			<content-none v-else :padTop="20"></content-none>
		</view>
	</view>
</template>

<script>
import {  greenSetSetting, greenGetSetting } from '@/common/api.js';
import { callbackRequest, getStorage, alertTip, convertImgToBase64, formatDate } from '@/common/util.js';
import loadMore from '@/components/loadMore.vue';
import contentNone from '@/components/contentNone.vue';
export default {
	components: {
		loadMore,
		contentNone
	},
	data() {
		return {
			vschecked:true,
			vschecked2:true,
			cmchecked:true,
			cmchecked2:true,
			approvalchecked:true,
			approvalchecked2:true,
			formatDate: formatDate,
			//分页
			visitSwich: [{ id: '0', name: '开' }, { id: '1', name: '关' }],
			visitSwichIndex: 0,
			cameraSwichIndex:0,
			approvalSwichIndex:0,
			userInfo: getStorage('userInfo'),
			currentTabIndex: 0,
		};
	},
	watch: {
		
	},
	onReachBottom() {
		if (this.loadingType !== 0 || this.currentTabIndex == 0) {
			return;
		}
		this.loadingType = 1;
		this.page = this.page + 1;
		 
	},
	onLoad() {
		this.getInitData();
	},
	methods: {
		changePlace(e) {
			this.visitSwichIndex = e.detail.value;
		},
		visitChangePlace: function (e) {
			var slef = this;
			slef.vschecked2 = slef.vschecked;
			slef.vschecked = e.target.value;
			var flag = "";
			if(slef.vschecked2 == true){
				flag = "关闭";
			}else{
				flag = "开启";
			}
			var tipMsg = "是否"+flag+"访客预约功能？"
			uni.showModal({
				title: '提示',
				content: tipMsg,
				success: function(res) {
					if (res.confirm) {
						var code = 0;
						if(slef.vschecked == true){
							code = 0;
						}else{
							code = 1;
						}
						let data = {
							method: greenSetSetting,
							data: {"type":"visit","code":code}
						};
						callbackRequest(data).then(res => {
							if (res.data.returnCode == 1) {
								 alertTip('修改成功');
							}else{
								 alertTip('修改失败');
								 slef.vschecked = slef.vschecked2;
							}
						}); 
					}else{
						console.log('2'+slef.vschecked)
						slef.vschecked = slef.vschecked2;
					}
				}
			});
        },
		cameraChangePlace: function (e) {
			 var slef = this;
			 slef.cmchecked2 = slef.cmchecked;
			 slef.cmchecked = e.target.value;
			 var flag = "";
			 if(slef.cmchecked2 == true){
			 	flag = "关闭";
			 }else{
			 	flag = "开启";
			 }
			 var tipMsg = "是否"+flag+"陌生人声音预警功能？"
			 
			 uni.showModal({
				title: '提示',
				content: tipMsg,
				success: function(res) {
					if (res.confirm) {
						var code = 0;
						if(slef.cmchecked == true){
							code = 0;
						}else{
							code = 1;
						}
						let data = {
							method: greenSetSetting,
							data: {"type":"cameraSet","code":code}
						};
						callbackRequest(data).then(res => {
							if (res.data.returnCode == 1) {
								 alertTip('修改成功');
							}else{
								 alertTip('修改失败');
								 slef.cmchecked = slef.cmchecked2;
							}
						}); 
					}else{
						console.log('2'+slef.cmchecked)
						slef.cmchecked = slef.cmchecked2;
					}
				}
			 });
		},
		approvalChangePlace: function (e) {
			 var slef = this;
			 slef.approvalchecked2 = slef.approvalchecked;
			 slef.approvalchecked = e.target.value;
			 var flag = "";
			 if(slef.approvalchecked2 == true){
			 	flag = "关闭";
			 }else{
			 	flag = "开启";
			 }
			 var tipMsg = "是否"+flag+"访客后勤部审批功能？"
			 
			 uni.showModal({
				title: '提示',
				content: tipMsg,
				success: function(res) {
					if (res.confirm) {
						var code = 0;
						if(slef.approvalchecked == true){
							code = 0;
						}else{
							code = 1;
						}
						let data = {
							method: greenSetSetting,
							data: {"type":"approvalCenter","code":code}
						};
						callbackRequest(data).then(res => {
							if (res.data.returnCode == 1) {
								 alertTip('修改成功');
							}else{
								 alertTip('修改失败');
								 slef.approvalchecked= slef.approvalchecked2;
							}
						}); 
					}else{
						console.log('2'+slef.approvalchecked)
						slef.approvalchecked = slef.approvalchecked2;
					}
				}
			 });
		},
		
		getInitData: function() {
			self = this;
			let params = {
				method: greenGetSetting,
				data: {
					userId: this.userInfo.id
				}
			};
			callbackRequest(params).then(res => {
				res = res.data;
				if (res.returnCode == 1) {
					 console.log(res.returnData);
					for (let i = 0; i < res.returnData.length; i++) {
						if(res.returnData[i].name == "访客预约"){
							if(res.returnData[i].is_open == 0){
								self.vschecked = true;
							}else{
								self.vschecked = false;
							}
						}else if(res.returnData[i].name == "摄像头报警"){
							if(res.returnData[i].is_open == 0){
								self.cmchecked = true;
							}else{
								self.cmchecked = false;
							}
						}else if(res.returnData[i].name == "approvalCenter"){
							if(res.returnData[i].is_open == 1){
								self.approvalchecked = true;
							}else if(res.returnData[i].is_open == 2) {
								self.approvalchecked = false;
							}
						}
					}
				} else {
					 
				}
			});
		},
		submit() {
			console.log(this.visitSwich[this.visitSwichIndex].id+"--------"+"==-===="+this.visitSwich[this.cameraSwichIndex].id);
			let data = {
				method: greenSetSetting,
				data: {"visit":this.visitSwich[this.visitSwichIndex].id,"camera":this.visitSwich[this.cameraSwichIndex].id}
			};
			callbackRequest(data).then(res => {
				if (res.data.returnCode == 1) {
					 alertTip('提交成功');
				}
			}); 
		},
		person: function(e) {
			this.index = e.detail.value;
			console.log(e);
		}
	}
};
</script>

<style lang="scss">
@import url('../../static/css/repair/malfunction-repair.css');
@import '@/static/css/common.scss';

.nolist {
	font-size: 30upx;
	color: #797979;
	text-align: center;
	margin-top: 20upx;
}

.container {
	position: relative;
	overflow: hidden;

	.banner-box {
		width: 100%;
		height: 240upx;
		position: absolute;
		top: 0;
		left: 0;

		image {
			width: 100%;
			height: 100%;
		}

		border-radius: 30upx;
	}

	.main {
		margin: 172upx 40upx 0;
		position: relative;
		z-index: 10;

		.tab-box {
			overflow: hidden;
			border-radius: 10upx 10upx 0 0;
			background: rgba(132, 149, 167, 0.8);
			height: 70upx;

			.tab-item {
				float: left;
				height: 70upx;
				width: 50%;
				font-size: 30upx;
				color: #e5f6ff;
				text-align: center;
				line-height: 70upx;
			}

			.active {
				background: #fff;
				color: #333;
				border-radius: 10upx 10upx 0 0;
				font-weight: bold;
			}
		}
	}
}

.list-content {
	font-size: 28upx;
	margin: 0 40rpx;
	.details {
		background: white;
		padding: 0 15upx 15upx;
		// border-radius: 15upx;
		margin-bottom: 10rpx;
		.detail_header {
			border-bottom: #f8f8f8 5upx solid;
			height: 90upx;
			line-height: 90upx;
			// margin: 0;
			// border-radius: 10upx;

			.blueSign {
				height: 28upx;
				width: 5upx;
				background: #00c277;
				display: inline-block;
				margin-left: 20upx;
				vertical-align: middle;
			}

			.font-tilte {
				font-weight: bold;
				margin-left: 20upx;
				vertical-align: middle;
			}
		}

		.detail_msg {
			margin-left: 20upx;
			border-radius: 10upx;
			overflow: hidden;
			view {
				height: 60upx;
				line-height: 60upx;
			}

			.status {
				position: absolute;
				color: red;
				margin-left: 580upx;
				margin-top: -15upx;
			}
		}
	}
}

.statusgr {
	float: right;
	margin-right: 30upx;
	color: #00c277;
}

.statusred {
	float: right;
	margin-right: 30upx;
	color: red;
}

.img-box {
	overflow: hidden;
	padding-top: 20rpx;
	padding-bottom: 10rpx;

	.img-item {
		float: left;
		width: 200upx;
		height: 200upx;
		border: 1px solid #ddd;
		margin: 0 22rpx 20upx 0upx;
		position: relative;
		box-sizing: border-box;

		.img {
			display: block;
			width: 100%;
			height: 100%;
		}

		.remove-btn {
			position: absolute;
			top: -18upx;
			right: -18upx;
			width: 44upx;
			height: 44upx;
			z-index: 2;
		}
	}

	.upload-btn {
		.img {
			width: 60upx;
			height: 60upx;
			margin: 70upx auto 0;
		}
	}
}
.detail_msg .info-item {
	font-size: 28upx;
	margin-right: 30upx;
	text {
		display: inline-block;
		width: 140upx;
	}

	.infoSpan {
		width: auto;
		font-size: 28upx;
		color: #666;
		float: right;
	}
}
.form-box {
	background: #fff;
	.form-item {
		overflow: hidden;
		border-bottom: 1px solid #eee;
		padding: 30upx 20upx;
		.label {
			float: left;
			width: 150upx;
			font-size: 28upx;
			color: #333;
			font-weight: bold;
			line-height: 50upx;
		}
		.ipt-box {
			margin-left: 160upx;
			input {
				width: 100%;
				height: 50upx;
				line-height: 50upx;
				font-size: 26upx;
				color: #666;
			}
		}
		.select {
			.arrow {
				float: right;
				width: 16upx;
				height: 29upx;
				margin-top: 10upx;
			}
			.picker {
				height: 50upx;
				line-height: 50upx;
				font-size: 26upx;
				color: #666;
				margin-left: 10upx;
			}
		}
	}
}

.comment-btn {
	float: right;
	font-size: 24upx;
	border-radius: 10upx;
	color: #fff;
	// line-height: 30upx;
	text-align: center;
	min-width: 120upx;
	margin-right: 30upx;
	background-color: #00c277;
}
</style>
