<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<meta name="author" content="" />
	<meta name="viewport"
		content="width=device-width,height=device-height, user-scalable=no,initial-scale=1, minimum-scale=1, maximum-scale=1,target-densitydpi=device-dpi ">
	<meta name="robots" content="" />
	<title>访客预约</title>
	<script type="text/javascript" src="${ctx }/scripts/jquery/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="${ctx }/scripts/lib/plugins/qrcode/jquery.qrcode.min.js"></script>
	<link rel="stylesheet" href="${ctx }/styles/visitor/visitor.css?v=2.4" type="text/css">
	<link rel="stylesheet" href="${ctx }/styles/visitor/visitorform.css?v=2.4" type="text/css">
	<script type="text/javascript" src="${ctx }/scripts/visitor/controlOptionMenu.js?v=4.0"></script>
	<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<link rel="stylesheet" href="${ctx }/styles/visitor/layer.css" type="text/css">
</head>
<input type="hidden" id="ctx" value="${ctx }" />
<input type="hidden" id="passType" value="${passType}" />
<input type="hidden" id="type" value="${type}" />
<input type="hidden" id="qrCode" value="${qrCode}" />
<input type="hidden" id="visitorQrCode" value="${result.visitorQrCode}" />
<input type="hidden" id="passList" value="${passList}" />
<input type="hidden" name="orgId" id="orgId" value="${orgId}" />
<body>

	<c:if test="${orgId != 969 && orgId != 615 && orgId != 1247}">
		<div id="qrcodehidden">
			<c:if test="${ result.visitorOrderStatus==1 && (fn:contains(passType,'2'))}">
				<div class="code-wp" style="margin-top: 15px;">
					<div class="title">
						<h6 class="throuth_code">通行码</h6>
						<span class="throuth_code_tip">可在闸机二维码读头设备处扫码通行</span>
					</div>
					<div class="qrcode_img_wrap">
						<div id="visitorCode"></div>
					</div>
					<div class="tip">二维码当日有效，截止当日时间23:59:59</div>
				</div>
			</c:if>

			<c:if test="${ result.visitorOrderStatus==1 && (fn:contains(passType,'3'))}">
				<div class="code-wp" style="margin-top: 15px;">
					<div class="title throuth_code">请在客服处扫码打印访客单</div>
					<div class="qrcode_img_wrap">
						<div id="code"></div>
					</div>
					<div class="tip">二维码当日有效，截止当日时间23:59:59</div>
				</div>
			</c:if>
		</div>
	</c:if>

	<div class="topstyle">
		<c:if test="${type != '3' }">
			<c:if test="${result.visitorOrderStatus==0 }">
				<p name="appointinfo" id="appointinfo" value="">请确认预约信息</p>
			</c:if>
			<c:if test="${result.visitorOrderStatus!=0}">
				<div id="back-btn" style="text-align: center">
					<a style="padding: 5px;color: #007bff;border: 1px solid #007bff;border-radius: 2px;">返回列表页面</a>
				</div>
			</c:if>
		</c:if>
		<c:if test="${type == '3'}">
			<div id="back-btn" style="text-align: center">
				<a style="padding: 5px;color: #007bff;border: 1px solid #007bff;border-radius: 2px;">返回列表页面</a>
			</div>
		</c:if>
	</div>

	<div class="bottomstyle clearfix" id="clearfix">
		<div class="clearfix-top">
			<p name="companycount" id="companycount">${result.compayName } 共有${result.count }位到访</p>
			<div class="appoint-time">
				<label name="appointtimehead" id="appointtimehead">到访时间</label>
				<!-- <p name="appointdate" id="appointdate" value="">${result.dateTime } ${result.week }</p> -->
				<span name="appointtime" id="appointtime" value="">${result.visitorTime}</span>
			</div>
			<c:if test="${not empty result.remak }">
				<p id="remarkP">
					<input type="text" name="remark" id="remark" style="border: none;" placeholder="" value="${result.remak }"
						disabled="true" />
				</p>
			</c:if>
			<div class="line-img ">
				<div class="line-img-left"></div>
				<div class="line-img-right"></div>
			</div>
		</div>
		<div class="clearfix-btm">
			<c:forEach items="${result.resultList }" var="model" varStatus="row">
				<div class='child clearfix'>
					<c:if test="${empty model.imageUrL }">
						<img src="../../images/visitor/user.png" class='touxiang' />
					</c:if>
					<c:if test="${not empty model.imageUrL }">
						<img src="${model.imageUrL }" class='touxiang' />
					</c:if>
					<c:if test="${not empty model.visitorName}" var="visitorName">
						<input type="text" name="guestname" id="guestname" value="${model.visitorName }" disabled="true">
					</c:if>
					<c:if test="${!visitorName}">
						<input type="text" name="guestname" id="guestname" value="访客${row.index + 1}" disabled="true">
					</c:if>
					<input type="text" name="guestphone" id="guestphone" value="${model.visitorPhone }" disabled="true">
					<%--<c:if test="${model.visitorType==0 }">
						<span class="gueststate">VIP</span>
					</c:if>--%>
					<c:if test="${result.visitorOrderStatus==1 && (fn:contains(passType,'3'))}">
						<span class=gueststate>已授权</span>
					</c:if>
				</div>
			</c:forEach>
		</div>
	</div>

	<div class="action">

		<c:if test="${type=='2' }">
			<c:if test="${result.visitorOrderStatus==0 }">
				<input type="button" name="modify" id="modify" value="不通过" onclick="authorUser(2)">
				<input type="button" name="submit" id="submit" value="通过" onclick="authorUser(1)">
			</c:if>
			<c:if test="${result.visitorOrderStatus==2 }">
				<input type="button" name="wmodify" id="wmodify" value="未通过">
			</c:if>
			<%--<c:if test="${result.visitorOrderStatus==1}">
				<input type="button" name="author" id="author" class="author" value="已授权">
			</c:if> --%>
		</c:if>
		<c:if test="${type=='1' || type=='3'}">
			<c:if test="${result.visitorOrderStatus==0}">
				<input type="button" name="wmodify" id="wmodify" value="未授权">
			</c:if>
			<c:if test="${ result.visitorOrderStatus==2 }">
				<input type="button" name="wmodify" id="wmodify" value="未通过">
			</c:if>
			<%--<c:if test="${result.visitorOrderStatus==1}">
				<input type="button" name="author" id="author" class="author" value="已授权">
			</c:if> --%>
		</c:if>
	</div>

	<c:if test="${not empty passList}">
		<div class="pass-wp">
			<h6 class="title">通行记录</h6>
			<div class="line"></div>
			<c:forEach var="pass" items="${passList}">
				<div class="cell-list">
					<div class="cell-left">${pass.deviceName}</div>
					<div class="cell-right">${pass.passTime}</div>
				</div>
			</c:forEach>
		</div>
	</c:if>

	<form:form action="${ctx }/wechat/visitor/updateVisitorOrder" method="post" id="updateuserform">
		<input type="hidden" name="visitorOrderStatus" id="visitorOrderStatus" />
		<input type="hidden" name="visitorId" id="visitorId" value="${result.visitorId }" />
	</form:form>
</body>
<!-- <script type="text/javascript" src="${ctx }/scripts/visitor/layer.js?v=5.0"></script> -->
<script type="text/javascript" src="${ctx }/scripts/visitor/layer_init.js?v=6.0"></script>
<script type="text/javascript">
	$(document).ready(function () {
		$(window).resize(infinite);

		if (!$('#orgId').val()) {
          let orgId = sessionStorage.getItem("orgId");
          if (orgId == 969 || orgId == 615 || orgId == 1247) {
            console.log('是否隐藏页面', orgId);
            $('#qrcodehidden').hide();
          }
        }

		$('#code').qrcode({
			width: 180,
			height: 180,
			text: $('#qrCode').val()
		})
		$('#visitorCode').qrcode({
			width: 180,
			height: 180,
			text: $('#visitorQrCode').val()
		})

		$("#back-btn").click(function () {
			let openId = sessionStorage.getItem("openId");
			let orgId = sessionStorage.getItem("orgId");
			let developId = sessionStorage.getItem("developId");
			let userId = sessionStorage.getItem("userId");
			let state = sessionStorage.getItem("state");
			let userToken = sessionStorage.getItem("userToken");
			sessionStorage.setItem('isList', 1);
			location.href = $("#ctx").val() + "/wechat/visitor/authorVisitor?userId=" + userId + "&openId=" + openId + "&orgId=" + orgId + "&state=" + state + "&userToken=" + userToken + "&developId=" + developId;
		})

		passType = sessionStorage.getItem('passType');
		if (!passType) {
			passType = $("#passType").val();
		}

		function infinite() {
			var htmlWidth = $('html').width();
			if (htmlWidth >= 640) {
				$("html").css({
					"font-size": "24px"
				});
			} else {
				$("html").css({
					"font-size": 24 / 640 * htmlWidth + "px"
				});
			}
		}
		infinite();
		if (passType.indexOf("4") === -1) {
			$('.touxiang').css({
				'display': 'none',
			});
		}
	});

	function authorUser(val) {
		var str = "";
		if (val == '2') {
			str = "您确认拒绝" + $("#guestname").val() + "预约请求吗？";
			layer.open({
				content: str
				, btn: ['确定', '关闭']
				, yes: function (index) {
					$.ajax({
						url: $("#ctx").val() + "/wechat/visitor/updateVisitorOrder",
						type: "POST",
						dataType: "json",
						data: {
							visitorOrderStatus: val,
							visitorId: $("#visitorId").val()
						},
						timeout: 30000,
						beforeSend: function (xhr) {
							layer.open({
								type: 2,
								content: '预约审核中'
							});
						},
						success: function (data) {
							layer.closeAll();
							if (data.flag) {
								showMessage(data.desc);
								$("#modify").hide();
								$("#submit").hide();
								//  WeixinJSBridge.call("closeWindow");
								// let orgId = sessionStorage.getItem("orgId");
								// let developId = sessionStorage.getItem("developId");
								// let openId = sessionStorage.getItem("openId");
								// location.href = $("#ctx").val() + "/wechat/visitor/visitorlist?userId=" + data.userId + "&openId=" + openId + "&orgId=" + orgId + "&developId=" + developId;
								//location.href=$("#ctx").val()+"/wechat/visitor/visitorlist?userId="+data.userId;
							} else {
								showMessage(data.desc);

							}
						},
						error: function (xhr, textStatus) {
							showMessage("请求超时！")
							layer.closeAll();
						}
					});
					layer.closeAll();
				}
			});
		}
		if (val == '1') {
			$.ajax({
				url: $("#ctx").val() + "/wechat/visitor/updateVisitorOrder",
				type: "POST",
				dataType: "json",
				data: {
					visitorOrderStatus: val,
					visitorId: $("#visitorId").val()
				},
				timeout: 30000,
				beforeSend: function (xhr) {
					layer.open({
						type: 2,
						content: '预约审核中'
					});
				},
				success: function (data) {
					layer.closeAll();
					if (data.flag) {
						showMessage(data.desc);
						//  WeixinJSBridge.call("closeWindow");
						// location.href=$("#ctx").val()+"/wechat/visitor/visitorlist?userId="+data.userId;
						$("#modify").hide();
						$("#submit").hide();
					} else {
						showMessage(data.desc);

					}
				},
				error: function (xhr, textStatus) {
					showMessage("请求超时");
					layer.closeAll();
				}
			});
		}
	}

	function showMessage(desc) {
		layer.open({
			content: desc,
			skin: 'msg',
			time: 2 //2秒后自动关闭
		});
	}
</script>

</html>
