$(function () {
	var contextPath = $("#contextPath").val();
	var layer;
	var flag = false;
	layui.use(['layer'], function () {
		layer = layui.layer;
	});
	function padLeftZero(str) {
		return ('00' + str).substr(str.length);
	};
	var orgList = []; //项目
	var fieldList;
	var setData; // 基础设置数据
	//<span class="read-card">读取</span>
	//<span class="search-btn"></span>
	var tpl = {
		"printTpl": '<div class="dialog-wp">\
			<div class="mask"></div>\
			<div class="dialog dialog-print-con">\
				<div class="title-wp">\
					<span>打印</span>\
					<span class="close-btn"></button>\
				</div>\
				<div class=" dialog-print-wp "  >\
					<div class="print-item">\
						<div class="p-i-tip">访客姓名：</div>\
						<div class="p-i-con visitor-name"><%=visitorName%></div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">手机号码：</div>\
						<div class="p-i-con visitor-phone"><%=visitorTelephone%></div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">到访公司：</div>\
						<div class="p-i-con visitor-company"><%=visitorCompany%></div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">预计离开时间：</div>\
						<div class="p-i-con">\
							<input class="p-i-input visitor-time" id="testTime1" value="<%=leaveTime%>" readonly placeholder="请选择预计离开时间"/>\
						</div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">身份证号：</div>\
						<div class="p-i-con id-number">\
							<input class="p-i-input visitor-number" value="<%=idenNumber%>" type="text"  placeholder="请输入身份证号码"/>\
							\
						</div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">民族：</div>\
						<div class="p-i-con">\
							<input class="p-i-input visitor-nation"  value="<%=race%>" type="text"  placeholder="请输入民族"/>\
						</div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">户籍地址：</div>\
						<div class="p-i-con">\
							<input class="p-i-input visitor-address" value="<%=censusAddr%>" type="text"  placeholder="请输入户籍地址"/>\
						</div>\
					</div>\
					<div class="print-item">\
						<div class="p-i-tip">签发机关：</div>\
						<div class="p-i-con">\
							<input class="p-i-input visitor-office" type="text" value="<%=police%>" placeholder="请输入签发机关"/>\
						</div>\
					</div>\
			   </div>		\
			  <div class="dialog-btns">\
					<button class="btn-white cancel-btn">取消</button>\
					<button class="btn-red  dialog-print-btn">打印</button>\
				</div>\
			</div>\
		</div>	',
		"detailsTable": '<div class="details_table">\
				<div class="part_ clearfloat idenNum_top">\
					<div class="part_title float-left part_title_depart">通行记录</div>\
					<div class="part_content float-left"></div>\
				</div>\
				<table border="1" cellspacing="0" width="100%" class="field-list access_records">\
					<tr class="list-title"><th>通行设备</th><th>通行时间</th></tr>\
					<%for (var i=0;i<dataList.length;i++) {%>\
						<tr class="list-content"><td><%=dataList[i].deviceName%></td><td><%=dataList[i].passTime%></td></tr>\
					<%}%>\
				</table>\
				<div class="layui-table-page">\
					<div id="layui-table-page1">\
						<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-2">\
							<%if (currentPage == 1) {%>\
								<a class="layui-laypage-prev layui-disabled" data-page="0"><i class="layui-icon"></i></a>\
							<%} else {%>\
								<a class="layui-btn layui-laypage-prev cursor-pointer" data-page="0"><i class="layui-icon"></i></a>\
							<%}%>\
							<%for (var i=1;i<(totalPages+1);i++) {%>\
								<%if (i == currentPage) {%>\
									<span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em><%=i%></em></span>\
								<%} else if (totalPages>9) {%>\
									<%if(((currentPage>3&&currentPage<(totalPages-2))&&(i==2||i==totalPages-1))||(currentPage<3&&i==4)||(currentPage==3&&i==5)||(currentPage>(totalPages-2)&&i==(totalPages-3))||(currentPage==(totalPages-2)&&i==(totalPages-4))) {%>\
										<span class="layui-laypage-spr">…</span>\
									<%}else if (((currentPage>3&&currentPage<(totalPages-2))&&(i==1||i==totalPages||i==(currentPage-1)||i==(currentPage+1)))||(currentPage<3&&(i<4||i==totalPages))||(currentPage==3&&(i<5||i==totalPages))||(currentPage>(totalPages-2)&&(i>(totalPages-3)||i==1))||(currentPage==(totalPages-2)&&(i>(totalPages-4)||i==1))) {%>\
										<a class="page-btn cursor-pointer" data-page="<%=i%>"><%=i%></a>\
									<%}%>\
								<%} else {%>\
									<a class="page-btn cursor-pointer" data-page="<%=i%>"><%=i%></a>\
								<%}%>\
							<%}%>\
							<%if (currentPage == totalPages) {%>\
								<a class="layui-laypage-next layui-disabled" data-page="1"><i class="layui-icon"></i></a>\
							<%} else {%>\
								<a class="layui-btn layui-laypage-next cursor-pointer" data-page="1"><i class="layui-icon"></i></a>\
							<%}%>\
							<span class="layui-laypage-skip">到第<input type="text" min="1" value="<%=currentPage%>" class="input-page layui-input">页\
								<button type="button" class="determine-btn layui-laypage-btn cursor-pointer">确定</button>\
							</span>\
							<span class="layui-laypage-count">共 <%=total%> 条</span>\
						</div>\
					</div>\
				</div>\
			</div> ',
		"scanPrintTpl": '<div class="dialog-wp">\
			<div class="mask"></div>\
			<div class="dialog dialog-print-con" >\
				<div class="title-wp">\
					<span>扫码打印</span>\
					<span class="close-btn"></button>\
				</div>\
				<%if(type==1){%>\
					<div class=" dialog-print-wp ">\
						<img class="scan-img" src="../../images/scan_img.png">\
						<div class="scan-tip">请扫描访客码...</div>\
					</div>\
				<%}else if(type==2){%>\
					<div class=" dialog-print-wp ">\
						<img class="scan-img" src="../../images/scan_fail.png">\
						<div class="scan-tip">无效二维码或已过期</div>\
					</div>\
				<%}else{%>\
					<div class=" dialog-print-wp " >\
						<div class="print-item">\
							<div class="p-i-tip">访客姓名：</div>\
							<div class="p-i-con visitor-name"><%=visitorName%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">手机号码：</div>\
							<div class="p-i-con visitor-phone"><%=visitorTelephone%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">到访公司：</div>\
							<div class="p-i-con visitor-company"><%=visitorCompany%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">预计离开时间：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-time" id="testTime" readonly placeholder="请选择预计离开时间"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">身份证号：</div>\
							<div class="p-i-con id-number">\
								<input class="p-i-input visitor-number" type="text"  placeholder="请输入身份证号码"/>\
								<span class="read-card">读取</span>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">民族：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-nation" type="text"  placeholder="请输入民族"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">户籍地址：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-address" type="text"  placeholder="请输入户籍地址"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">签发机关：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-office" type="text"  placeholder="请输入签发机关"/>\
							</div>\
						</div>\
				   </div>\
				<%}%>\
				<%if(type==3){%>\
				  <div class="dialog-btns">\
						<button class="btn-white cancel-btn">取消</button>\
						<button class="btn-red dialog-print-btn">打印</button>\
					</div>\
				<%}%>\
			</div>\
		</div>	',
		"printModelTpl": '<div class=" dialog-print-wp " id="printCon" style="display: none">\
							<div class="print-item">\
								<div class="p-i-tip">来访时间：</div>\
								<div class="p-i-con"><%=visitTime%></div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip">预计离开时间：</div>\
								<div class="p-i-con"><%=time%></div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip">访客姓名：</div>\
								<div class="p-i-con"><%=name%></div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip">手机号码：</div>\
								<div class="p-i-con"><%==phone%></div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip">身份证号码：</div>\
								<div class="p-i-con"><%=number%></div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip">到访公司：</div>\
								<div class="p-i-con"><%=company%></div>\
							</div>\
						</div>',
		"throughTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-print-con">\
					<div class="title-wp">\
						<span>通行方式设置</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="xq_plan" >\
						<% if(orgList!=null&&orgList.length>1){ %>\
							<div class="print-item">\
							<div class="p-i-tip">项目：</div>\
								<div class="plan-con" style="width: 350px;">\
									<input class="meal-select organ-id mut_org" name="orgId" id="orgId"  autocomplete="off" value="<%=orgList[0].name %>" org__id="<%=orgList[0].id %>"/>\
									<span class="select_wrap _hide"></span>\
								</div>\
							</div>\
						<%}else if(orgList!=null&&orgList.length==1){%>\
							<input type="hidden" class="meal-select organ-id sin_org" id="orgId" value="<%=orgList[0].name%>" org__id="<%=orgList[0].id %>"/>\
						<%}%>\
						<div class="view-flex">\
							<div class="plan-title">请选择通行方案：</div>\
							<div class="xq_plan_item clearfloat required  group-item">\
								<div class="checkbox-wp">\
									<span class="checkbox-input">\
									<input type="checkbox" id="wx-1" class="check-item staple-plan" data-id="3"/>\
									<span class="checkbox-inner"></span>\
									</span>		\
									<label class="checkbox-con" for="wx-1">访客登记（无闸机）</label>\
								</div>\
								<div class="checkbox-wp">\
									<span class="checkbox-input">\
									<input type="checkbox" id="wx-2" class="check-item staple-plan" data-id="2"/>\
									<span class="checkbox-inner"></span>\
									</span>		\
									<label class="checkbox-con" for="wx-2">令令开门</label>\
								</div>\
								<div class="checkbox-wp">\
									<span class="checkbox-input">\
									<input type="checkbox" id="wx-4" class="check-item staple-plan" data-id="4"/>\
									<span class="checkbox-inner"></span>\
									</span>		\
									<label class="checkbox-con" for="wx-4">考拉</label>\
								</div>\
							</div>\
						</div>\
						<div class="view-flex">\
							<div class="plan-title">访客无需审核：</div>\
							<div class="xq_audit_item clearfloat required  group-item">\
								<div class="checkbox-wp">\
									<span class="checkbox-input">\
									<input type="checkbox" id="audit" class="check-item staple-audit" data-id="5"/>\
									<span class="checkbox-inner"></span>\
									</span>		\
									<label class="checkbox-con" for="wx-1">开启</label>\
								</div>\
							</div>\
						</div>\
						<div class="view-flex">\
							<div class="plan-title">预约信息确认：</div>\
							<div class="xq_audit_item clearfloat required  group-item">\
								<div class="checkbox-wp">\
									<span class="checkbox-input">\
									<input type="checkbox" id="make" class="check-item staple-make" data-id="6"/>\
									<span class="checkbox-inner"></span>\
									</span>		\
									<label class="checkbox-con" for="wx-6">开启</label>\
								</div>\
							</div>\
						</div>\
						<div class="view-flex">\
							<div class="plan-title">预约输入字段：</div>\
							<div class="field-content"></div>\
						</div>\
						<div class="kaola_info">\
							<div class="print-item">\
								<div class="p-i-tip"><span style="color: red;padding-right: 3px">*</span>链接地址：</div>\
								<div class="p-i-con koalaAuthUrl">\
									<input class="p-i-input" type="text"  placeholder="请输入链接地址"/>\
								</div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip"><span style="color: red;padding-right: 3px">*</span>用户名：</div>\
								<div class="p-i-con koalaUserName">\
									<input class="p-i-input" type="text"  placeholder="请输入用户名"/>\
								</div>\
							</div>\
							<div class="print-item">\
								<div class="p-i-tip"><span style="color: red;padding-right: 3px">*</span>用户密码：</div>\
								<div class="p-i-con koalaUserPwd">\
									<input class="p-i-input" type="text"  placeholder="请输入用户密码"/>\
								</div>\
							</div>\
						</div>\
						<div class="dialog-btns btn-top">\
							<button class="btn-white cancel-btn">返回</button>\
							<button class="btn-red save_btn">保存</button>\
						</div>\
					</div>\
				</div>\
			</div>\
			',
		"fieldTpl": '<div class="field-content">\
				<table border="1" cellspacing="0" width="100%" class="field-list">\
					<tr class="list-title">\
						<th>字段</th>\
						<th>输入类型</th>\
					</tr>\
					<%for(var i=0;i<fieldList.length;i++) {%>\
						<tr class="list-content">\
							<td><%=fieldList[i].label%></td>\
							<td>\
								<%if (fieldList[i].disabled) {%>\
									<select class="field-select" disabled id="virPerm" data-task-row="<%=i%>">\
										<%for(var j=0;j<selectList.length;j++) {%>\
											<%if (fieldList[i].value == selectList[j].value) {%>\
												<option value="<%=selectList[j].value%>"  selected="selected"><%=selectList[j].label%></option>\
											<%} else {%>\
												<option value="<%=selectList[j].value%>"><%=selectList[j].label%></option>\
											<%}%>\
										<%}%>\
									</select>\
								<%} else {%>\
									<select class="field-select" id="virPerm" data-task-row="<%=i%>">\
										<%for(var j=0;j<selectList.length;j++) {%>\
											<%if (fieldList[i].value == selectList[j].value) {%>\
												<option value="<%=selectList[j].value%>"  selected="selected"><%=selectList[j].label%></option>\
											<%} else {%>\
												<option value="<%=selectList[j].value%>"><%=selectList[j].label%></option>\
											<%}%>\
										<%}%>\
									</select>\
								<%}%>\
							</td>\
						</tr>\
					<%}%>\
				</table>\
			</div>\
			',
		"visitorTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-print-con">\
					<div class="title-wp">\
						<span>访客登记</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class=" dialog-print-wp "  >\
						<div class="base-title">基础信息</div>\
						<div class="print-item">\
							<div class="p-i-tip"><span style="color: red;padding-right: 3px">*</span>访客姓名：</div>\
							<div class="p-i-con visitor-name">\
								<input class="p-i-input" type="text"  placeholder="请输入访客姓名"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip"><span style="color: red;padding-right: 3px">*</span>手机号码：</div>\
							<div class="p-i-con visitor-phone">\
								<input class="p-i-input" type="text"  placeholder="请输入手机号码"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">到访公司：</div>\
							<div class="p-i-con visitor-company">\
								\
								<input class="default-select companyInput-id " name="companyInputId" id="companyInputId" autocomplete="off" placeholder="请选择公司" />\
								<span class="select_wrap _hide"></span>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">预计离开时间：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-time" id="testTime" readonly placeholder="请选择预计离开时间"/>\
							</div>\
						</div>\
						<div class="base-title">身份证信息</div>\
						<div class="print-item">\
							<div class="p-i-tip">身份证号：</div>\
							<div class="p-i-con id-number">\
								<input class="p-i-input visitor-number" type="text"  placeholder="请输入身份证号码"/>\
								\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">民族：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-nation" type="text"  placeholder="请输入民族"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">户籍地址：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-address" type="text"  placeholder="请输入户籍地址"/>\
							</div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">签发机关：</div>\
							<div class="p-i-con">\
								<input class="p-i-input visitor-office" type="text"  placeholder="请输入签发机关"/>\
							</div>\
						</div>\
				   </div>		\
				  <div class="dialog-btns">\
						<button class="btn-white cancel-btn">取消</button>\
						<button class="btn-red  dialog-next-btn">下一步</button>\
					</div>\
				</div>\
			</div>	',
		"visitorCodeTpl": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog">\
					<div class="title-wp">\
						<span>访客预约码</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class=" dialog-print-wp "  >\
					   <div class="base-title" style="text-align: center;margin-bottom: 20px;"><%=orgName%></div>\
					   <div class="print-item">\
							<div class="p-i-tip" style="width: 50px;flex: 0 0 60px;">链接：</div>\
							<div class="p-i-con">\
								<span class="p-i-input p-span-url">\
								<%=qrUrl%>\
								</span>\
							</div>\
						</div>\
						<div class="print-item">\
							<button class="btn-white btn-copy">复制链接</button>\
							<button class="btn-white btn-qr-code">生成二维码</button>\
						</div>\
						<div class="print-item">\
							<div class="qr-left" id="qrCode"></div>\
						</div>\
					</div>\
					<div class="dialog-btns">\
						<button class="btn-white cancel-btn">返回</button>\
					</div>\
				</div>\
			</div>',
		"visitorModelTpl": '<div class="dialog-wp">\
						<div class="mask"></div>\
						<div class="dialog dialog-print-con">\
							<div class="title-wp">\
								<span>打印访客单</span>\
								<span class="close-btn"></button>\
							</div>\
						<div class=" dialog-print-wp "  >\
						<div class="print-item">\
							<div class="p-i-tip">来访时间：</div>\
							<div class="p-i-con"><%=visitTime%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">预计离开时间：</div>\
							<div class="p-i-con"><%=time%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">访客姓名：</div>\
							<div class="p-i-con"><%=name%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">手机号码：</div>\
							<div class="p-i-con"><%==phone%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">身份证号：</div>\
							<div class="p-i-con"><%=number%></div>\
						</div>\
						<div class="print-item">\
							<div class="p-i-tip">到访公司：</div>\
							<div class="p-i-con"><%=company%></div>\
						</div>\
					</div>\
				  <div class="dialog-btns">\
						<button class="btn-white cancel-btn">取消</button>\
						<button class="btn-red  dialog-print-btn">打印</button>\
					</div>\
				</div>\
			</div>	'
	}
	var visitorOrder = {
		init: function () {
			this.render();
			this.bindEvent();
		},
		render: function () {
			var _this = this;

			if (!sessionStorage.getItem("passType")) {
				if (localStorage.getItem("passType")) {
					var strPassType = localStorage.getItem("passType")
					sessionStorage.setItem("passType", strPassType)
				} else {
					sessionStorage.setItem("passType", '2')
				}
			}

			layui.use('laydate', function () {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: '#startTime' //指定元素

				});
				laydate.render({
					elem: '#endTime' //指定元素

				});
				//执行一个laydate实例
				laydate.render({
					elem: '#createBeginTime' //指定元素

				});
				laydate.render({
					elem: '#createEndTime' //指定元素

				});
			});
			setData = {
				id: '',
				orgId: '',
				isLinglingAudit: 0,
				visitedCompType: 1,
				visitedMobileType: 1,
				visitCompType: 1,
				visitNameType: 1,
				orderAffirm: 0
			};
			fieldList = [
				{
					disabled: true,
					label: '被访人公司',
					value: 1
				},
				{
					disabled: true,
					label: '被访人手机号',
					value: 1
				},
				{
					disabled: false,
					label: '访客公司',
					value: 1
				},
				{
					disabled: false,
					label: '访客姓名',
					value: 1
				},
			]
			_this.itemAjax();
			_this.renderTable();
		},
		bindEvent: function () {
			var _this = this;
			//				$("#btn-search").click(function () {
			//					$("#conditionform").submit();
			//				});
			if (sessionStorage.getItem("passType").indexOf("3") != -1) {
				$(".visitor-list").show();
			} else {
				$(".visitor-list").hide();
			}
			// 关闭公共弹层
			$('body').on('click', '.pop_close', function (event) {
				event.preventDefault();
				/* Act on the event */
				$('.mask').remove()
			});
			//查询
			$("#conditionform input[type='text']").on("keydown", function (event) {
				if (event.keyCode == 13) {
					$("#conditionform .search-btn").click();
				}
			});
			layui.use('laydate', function () {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: '#c_startTime' //提交开始时间

				});
				laydate.render({
					elem: '#c_endTime' //提交结束时间

				})
			});
			//重置
			$(".set-btn").on("click", function () {
				// $("#conditionform select,#conditionform input").val("");
				$("#conditionform input:not('#orgId'),#conditionform select:not('#orgId')").val("");
				$("#conditionform select").val("");
				$("#conditionform .choose-person-btn").data("id", "");
				_this.againRenderTable({ type: 1 });
			});
			// $(".visitorId").on("change", function () {
			// 	///////////
			// 	_this.againRenderTable();
			// 	//					flag= true
			// 	console.log("刚刚开始的flag", '11111')

			// })
			//scanPrintTpl
			//扫码打印
			//				$(".scan-print").on("click",function(){
			//					var html = template.render(tpl.scanPrintTpl)({type: 2})
			//					$("body").append(html)
			//					$(html).find(".print-btn").on("click",function(){
			//						var myWindow = window.open('', '标题');
			//						//获取id为app内的html
			//				        var bodyHtml = window.document.getElementById('printCon').innerHTML;
			//				        // 获取head标签内的html
			//				        var headHtml = document.head.innerHTML;
			//				        // 头中的screen换成打印样式print
			//				        headHtml = headHtml.replace('screen', 'screen, print');
			//				        //重新写入文档流
			//				        myWindow.document.write('<html>');
			//				        myWindow.document.write(headHtml);
			//				        myWindow.document.write('<body >');
			//				        myWindow.document.write(bodyHtml);
			//				        myWindow.document.write('<script>setTimeout(function() {window.print(); window.close();}, 500)</');
			//				        myWindow.document.write('script>');
			//				        myWindow.document.write('</body></html>');
			//					})
			//					$(".close-btn").on("click",function(){
			//		        		$(".dialog-wp").remove();
			//		        	})
			//				})
			//访客登记
			$(".visitor-register").on("click", function () {
				$("body").append(template.render(tpl.visitorTpl))
				//					console.log(_this.formatDate(new Date(),'yyyy-MM-dd hh:mm:ss'))
				layui.use('laydate', function () {
					var laydate = layui.laydate;
					laydate.render({
						elem: '#testTime'
						, type: 'datetime'
						, min: _this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
					});
				})
				//visitorModelTpl
				$(".dialog-next-btn").on("click", function () {
					var name = $(".visitor-name input").val();
					if (!name) {
						layer.msg('请输入访客姓名');
						return false
					}
					var phone = $(".visitor-phone input").val();
					if (!/^[1][0-9]{10}$/.test(phone)) {
						layer.msg('请输入正确的手机号码');
						return false
					}
					var data = {
						name: name,
						phone: phone,
						visitTime: _this.formatDate(new Date(), 'yyyy-MM-dd'),
						company: $(".visitor-company input").val(),
						time: $(".visitor-time").val(),
						number: $(".visitor-number").val(),
						nation: $(".visitor-nation").val(),
						address: $(".visitor-address").val(),
						office: $(".visitor-office").val(),
						companyId: $(".visitor-company input").attr("com__id")
					}
					// PC访客登记
					_this.visitorRegister(data, function () {
						_this.pirntEvent(data, 1)
					})
				})
				$(".close-btn,.dialog-wp .cancel-btn").on("click", function () {
					$(".dialog-wp").remove();
				})
			})


			  //导出报表
			  $(".export-excel-order").on("click", function () {
					var str = "确定导出报表数据吗?";
					layer.confirm(str, {
						btn: ['确定', '取消']
					}, function (index, layero) {
						layer.close(index); //如果设定了yes回调，需进行手工关闭
						_this.exportAjax();
					}, function (index) {});

			})

			// 访客预约码
			$(".reservation-code").on("click", function () {
				var orgId = $("#conditionform  #orgId").attr('org__id');
				_this.getVisitorQenterUrlHandler(orgId, backData => {
					if (!backData) {
						return;
					}
					console.log('backData', backData);
					$("body").append(template.render(tpl.visitorCodeTpl)({
						orgName: $("#conditionform  #orgId").val(),
						qrUrl: backData
					}));

					$(".btn-copy").on("click", function () {
						_this.copyToClipboard(backData)
					})

					$(".btn-qr-code").on("click", function () {
						$("#qrCode").empty(); // 清空子元素
						$("#qrCode").qrcode({width:200,height:200,text:backData});
					})

					$(".close-btn,.dialog-wp .cancel-btn").on("click", function () {
						$(".dialog-wp").remove();
					})
				});
			})

			// 通行方案设计
			$(".through-plan").on("click", function () {
				$("body").append(template.render(tpl.throughTpl)({
					orgList: orgList
				}));
				_this.upFieldDataUI();
				_this.getCaseDetail($('.meal-select#orgId').attr('org__id'))
				_this.getSetData($('.meal-select#orgId').attr('org__id'))
				$(".staple-plan").on("click",function(){
					let arr = $(".xq_plan_item .staple-plan:checked")
					let showKaola = false
					for (var i = 0; i < arr.length; i++) {
						if($(arr[i]).data("id") == 4){
							showKaola = true
						}
					}
					if(showKaola){
						$(".kaola_info").css("display","block")
					}else{
						$(".kaola_info").css("display","none")
					}
				})
				$(".staple-audit").on("click",function(){
					let arr = $(".xq_audit_item .staple-audit:checked")
					if (arr.length>0) {
						if ($(arr[0]).data("id") == 5) {
							setData.isLinglingAudit = 1;
						}
					} else {
						setData.isLinglingAudit = 0;
					}
					fieldList.forEach(item => {
						if (setData.isLinglingAudit == 1) {
							if (item.label === '被访人公司'||item.label === '被访人手机号') {
								item.disabled = false
							}
						} else {
							if (item.label === '被访人公司'||item.label === '被访人手机号') {
								item.disabled = true
								item.value = 1
							}
						}
					})
					_this.upFieldDataUI()
				})
				$(".staple-make").on("click",function(){
					let arr = $(".xq_audit_item .staple-make:checked")
					if (arr.length>0) {
						if ($(arr[0]).data("id") == 6) {
							setData.orderAffirm = 1;
						}
					} else {
						setData.orderAffirm = 0;
					}
				})
				$(".save_btn").on("click", function () {
					var orgId = $('.meal-select#orgId').attr('org__id')

					var passType = "",koalaAuthUrl= "",koalaUserName= "",koalaUserPwd= "",show = false
					if(!orgId){
						layer.msg("请选择项目");
						return false;
					}
					var planList = $(".xq_plan_item .staple-plan:checked");
					if(planList.length == 0){
						layer.msg("请选择通行方案");
						return false;
					}
					var planArr = [];
					for (var i = 0; i < planList.length; i++) {
						planArr.push($(planList[i]).data("id"));
						if($(planList[i]).data("id") == 4){
							show = true;
							koalaAuthUrl = $(".koalaAuthUrl input").val();
							koalaUserName = $(".koalaUserName input").val();
							koalaUserPwd = $(".koalaUserPwd input").val();
						}
					}

					if(show&&!koalaAuthUrl){
						layer.msg("请输入链接地址");
						return false;
					}
					if(show&&!koalaUserName){
						layer.msg("请输入用户名");
						return false;
					}
					if(show&&!koalaUserPwd){
						layer.msg("请输入用户密码");
						return false;
					}
					passType = planArr.join(",")
					let contextPath = window.location.hostname === 'localhost'? 'http://wx.palmnest.com/super_cloud' : $("#contextPath").val().split("super_service")[0]+"super_cloud"
					$.ajax({
						type: "post",
						// url: "http://wx.palmnest.com/super_cloud" + "/api/organisation/organization/updatePassType",
						url: contextPath + "/api/organisation/organization/updatePassType",
						data: {
							"orgId": orgId,
							"passType": passType,
							"koalaAuthUrl": koalaAuthUrl,
							"koalaUserName": koalaUserName,
							"koalaUserPwd": koalaUserPwd
						},
						success: function (data) {
							if (data && data.code == 200) {
								_this.saveSetData(orgId)
							}else{
								layer.msg(data.msg)
							}
						},
						error: function (error) {
							layer.msg('error')
						}
					});
				})
				$(".close-btn,.dialog-wp .cancel-btn").on("click", function () {
					$(".dialog-wp").remove();
				})
			})
			// 模糊搜索
			this.search_fuzzy();
			//模糊查找弹框的企业信息
			this.search_fuzzyInutDialog();
		},
		// 渲染预约输入字段控制table
		upFieldDataUI: function() {
			$(".field-content").replaceWith(template.render(tpl.fieldTpl)({fieldList, selectList:[{label: '必填', value: 1}, {label: '选填', value: 2}, {label: '不展示', value: 3}]}));
			$(".field-select").change(function(){
				var indexRow = Number($(this).attr("data-task-row"));
				var selectedRow= Number($(this).children('option:selected').val());
				fieldList[indexRow].value = selectedRow;
				console.log('fieldList', fieldList)
			})
		},
		saveSetData(orgId) {
			setData.orgId=orgId
			fieldList.forEach(item => {
				if (item.label === '被访人公司') {
					setData.visitedCompType = item.value
				}
				if (item.label === '被访人手机号') {
					setData.visitedMobileType = item.value
				}
				if (item.label === '访客公司') {
					setData.visitCompType = item.value
				}
				if (item.label === '访客姓名') {
					setData.visitNameType = item.value
				}
			})

			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/visitor/order/saveCurrentset",
				data: JSON.stringify(setData),
				contentType : "application/json",
				dataType : "json",
				success: function (data) {
					if (data && data.code == 200) {
						layer.msg('操作成功')
						$(".dialog-wp").remove();
					}else{
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},

		copyToClipboard: function(str) {
			const el = document.createElement('textarea'); //创建input对象
			el.value = str;
			el.setAttribute('readonly', '');  //当前获得焦点的元素
			el.style.position = 'absolute';
			el.style.left = '-9999px';
			document.body.appendChild(el); //添加元素
			const selectedStr = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
			el.select();
			document.execCommand('copy'); //执行复制
			document.body.removeChild(el);//删除元素
			if (selectedStr) {
				document.getSelection().removeAllRanges();
				document.getSelection().addRange(selectedStr);
			}
			layer.msg('复制完成')
		},
		//导出
		exportAjax: function () {
			var _this = this;
			let pageNo = $(".layui-laypage-em").next().html();
			let pageSize = $(".layui-laypage-limits").find("option:selected").val();
			$.ajax({
				type: "post",
				url: contextPath + "/visitor/order/exportVisitorOrder",
				data: {
					// pageNo: pageNo,
					// pageSize: pageSize,
					orgId: $("#conditionform  #orgId").attr('org__id'),
					visitorInfo: $(".visitorInfo").val(),
					respondentsInfo: $(".respondentsInfo").val(),
					objective: $(".objective").val(),
					visitorId: $(".visitorId").val(),
					visitorOrderStatus: $("#visitorOrderStatus").val(),
					beginTime: $("#startTime").val(),
					endTime: $("#endTime").val(),
					createBeginTime: $("#createBeginTime").val(),
					createEndTime: $("#createEndTime").val(),
				},
				success: function (data) {

					if (data.code == 200) {
						// location.href = data.data;
						location.href = $("#contextPath").val() + "/upload/ExportVisitorOrder.xls";
					} else {
						layer.msg(data.msg)
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		search_fuzzyInutDialog: function () {
			var _this=this
			var default_option = {
				org_attrName: 'org__id',
				com_attrName: 'com__id',
				dep_attrName: 'dep__id',
				org_spanName: 'org__span',
				com_spanName: 'com__span',
				dep_spanName: 'dep__span',
				org_path: '/admin/templ/getOrgListByName',
				com_path: '/admin/templ/getVirList',
				dep_path: '/admin/templ/getDept',
				contextPath: $("#contextPath").val()
			}
			var option_1 = $.extend(true, {}, default_option, {
				org_target: '.default-select#orgId',
				com_target: '.default-select#companyInputId',
				dep_target: '.default-select#departmentId',
			});
			var option_2 = $.extend(true, {}, default_option, {
				org_target: '.item-select.organ-id',
			});
			var option_3 = $.extend(true, {}, default_option, {
				org_target: '.meal-select#orgId'
			});

			function eve(option_, otherOption) {
				var obj = $.extend(true, {}, option_, otherOption);
				var type = obj.type
				var _path, _target, _attrName, _spanName
				if (type == 1) {
					_path = obj.org_path
					_target = obj.org_target
					_attrName = obj.org_attrName
					_spanName = obj.org_spanName
				} else if (type == 2) {
					_path = obj.com_path
					_target = obj.com_target
					_attrName = obj.com_attrName
					_spanName = obj.com_spanName
				} else if (type == 3) {
					_path = obj.dep_path
					_target = obj.dep_target
					_attrName = obj.dep_attrName
					_spanName = obj.dep_spanName
				}
				$('body').on("input", _target, function (event) {
					var _this = $(this)
					var obj_input = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_input(_this, _attrName, _spanName, contextPath, _path, obj_input)
				});
				$('body').on("focus", _target, function (event) {
					var _this = $(this)
					var obj_focus = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_focus(_this, _attrName, _spanName, contextPath, _path, obj_focus)
				});
				$('body').on('blur', _target, function (event) {
					var _this = $(this)
					var obj_blur = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_blur(_this, _attrName, obj_blur)
				});
				$('body').on('click', _target + '~.select_wrap>.' + _spanName, function (event) {
					event.preventDefault();
					event.stopPropagation();
					/* Act on the event */
					var _this = $(this)
					var obj_click = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_click(_this, _attrName, _target, obj_click)
				});

			}
			// 搜索联动
			eve(option_1, { type: 1 })
			eve(option_1, { type: 2 })
			eve(option_1, { type: 3 })
			// 自动充值
			eve(option_2, { type: 1 })
			eve(option_3, {
				type: 1,
				click_callback:function(){
					var orgId = $('.meal-select#orgId').attr('org__id')
					_this.getCaseDetail(orgId)
					_this.getSetData(orgId)
				} })
		},
		//模糊搜索事件
		search_fuzzy: function () {
			var default_option = {
				org_attrName: 'org__id',
				com_attrName: 'com__id',
				dep_attrName: 'dep__id',
				org_spanName: 'org__span',
				com_spanName: 'com__span',
				dep_spanName: 'dep__span',
				org_path: '/admin/templ/getOrgListByName',
				com_path: '/admin/templ/getVirList',
				dep_path: '/admin/templ/getDept',
				contextPath: $("#contextPath").val()
			}
			var option_1 = $.extend(true, {}, default_option, {
				org_target: '.default-select#orgId',
				com_target: '.default-select#companyId',
				dep_target: '.default-select#departmentId',
			});
			var option_2 = $.extend(true, {}, default_option, {
				org_target: '.item-select.organ-id',
			});

			function eve(option_, otherOption) {
				var obj = $.extend(true, {}, option_, otherOption);
				var type = obj.type
				var _path, _target, _attrName, _spanName
				if (type == 1) {
					_path = obj.org_path
					_target = obj.org_target
					_attrName = obj.org_attrName
					_spanName = obj.org_spanName
				} else if (type == 2) {
					_path = obj.com_path
					_target = obj.com_target
					_attrName = obj.com_attrName
					_spanName = obj.com_spanName
				} else if (type == 3) {
					_path = obj.dep_path
					_target = obj.dep_target
					_attrName = obj.dep_attrName
					_spanName = obj.dep_spanName
				}
				$('body').on("input", _target, function (event) {
					var _this = $(this)
					var obj_input = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_input(_this, _attrName, _spanName, contextPath, _path, obj_input)
				});
				$('body').on("focus", _target, function (event) {
					var _this = $(this)
					var obj_focus = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_focus(_this, _attrName, _spanName, contextPath, _path, obj_focus)
				});
				$('body').on('blur', _target, function (event) {
					var _this = $(this)
					var obj_blur = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_blur(_this, _attrName, obj_blur)
				});
				$('body').on('click', _target + '~.select_wrap>.' + _spanName, function (event) {
					event.preventDefault();
					event.stopPropagation();
					/* Act on the event */
					var _this = $(this)
					var obj_click = $.extend(true, {}, obj, { "_this": _this });
					cjqt.search_fuzzy.event_click(_this, _attrName, _target, obj_click)
				});

			}
			// 搜索联动
			eve(option_1, { type: 1 })
			eve(option_1, { type: 2 })
			eve(option_1, { type: 3 })
			// 自动充值
			eve(option_2, { type: 1 })
		},
		renderTable: function () {
			var _this = this;
			layui.use('table', function () {
				table = layui.table;

				//方法级渲染
				table.render({
					elem: '#LAY_table_user',
					method: 'post'
					, skin: 'nob' //行边框风格
					, even: true //开启隔行背景
					, size: 'lg' //小尺寸的表格
					, url: $("#contextPath").val() + "/visitor/order/getVisitorOrderList"
					, cols: [[
						{

							title: '序号',
							templet: '#indexTpl',
							width: 80
						}, {
							field: 'organizationName',
							title: '项目',
							minWidth: 180
						}, {
							field: '',
							title: '访客（姓名、手机号、企业）',
							minWidth: 250,
							templet: function (data) {

								  var personStr =''
				            	  if(data.visitorName){
				            		  personStr = data.visitorName +"</br>"
				            	  }
				            	  if(data.visitorPhone){
				            		  personStr = personStr + data.visitorPhone+"</br>"
				            	  }
				            	  if(data.visitorCompanyName){
				            		  personStr = personStr + data.visitorCompanyName+"</br>"
				            	  }
				            	  return personStr
                        }
						}, {
							field: '',
							title: '被访人（姓名、手机号、企业）',
							minWidth: 250,
							templet: function (data) {

								  var personStr =''
				            	  if(data.userName){
				            		  personStr = data.userName +"</br>"
				            	  }
				            	  if(data.userMobile){
				            		  personStr = personStr + data.userMobile+"</br>"
				            	  }
				            	  if(data.virName){
				            		  personStr = personStr + data.virName+"</br>"
				            	  }
				            	  return personStr
                        }
						},{
							field: 'visitorReason',
							title: '到访目的',
							minWidth: 150
						}, {
							field: 'visitorOrderStatus',
							title: '状态',
							width: 100,
							templet: function (data) {
								if (data.visitorOrderStatus == 1) {
									return '已授权'
								} else if (data.visitorOrderStatus == 2) {
									return '未通过'
								} else if (data.visitorOrderStatus == 3) {
									return '已作废'
								} else if (data.visitorOrderStatus == 0) {
									return '未授权'
								}
							}
						}, {
							field: 'visitorCreateTime',
							title: '申请时间',
							minWidth: 150
						}, {
							field: 'visitorStartTime',
							title: '访问时间',
							minWidth: 150
						},
						// {
						// 	field: 'imageFaceUrl',
						// 	title: '照片',
						// 	minWidth: 100,
						// 	templet: function (data) {
						// 		if (data.imageFaceUrl) {
						// 			return '<img style="width: 100px;height: 100px;" src="' + data.imageFaceUrl + '" />'
						// 		} else {
						// 			return '暂无图片'
						// 		}
						// 	}
						// },
						{
							fixed: 'right',
							title: '操作',
							width: 150,
							templet: function (data) {
								var str = ''
								str += "<span data-id=" + data.visitorId + " data-status= " + data.visitorOrderStatus + " class='check-blue-btn check-detail'>详情</span>";
								if ((sessionStorage.getItem("passType").indexOf("3") != -1) && (data.visitorOrderStatus == 1)) {
									str += "<span data-id=" + data.visitorId + " data-status= " + data.visitorOrderStatus + " class='check-blue-btn print-btn1'>打印</span>"
								}
								return str
							}
						}
					]]
					, id: 'testReload'
					, page: true,
					where: {
						orgId: $("#conditionform  #orgId").attr('org__id')
					},
					response: {
						statusName: 'code' //数据状态的字段名称，默认：code
						, statusCode: 200 //成功的状态码，默认：0
						, countName: "count"//数据总数的字段名称，默认：count
						, dataName: "data" //数据列表的字段名称，默认：data
					},
					done: function (res, curr, count) {
						//如果是异步请求数据方式，res即为你接口返回的信息。
						//查看详情
						$(".check-detail").on("click", function () {
							var id = $(this).data("id")
							var status = $(this).data("status")
							//查看订单详情
							_this.ajaxDetail(id);
						});
						//打印
						$(".print-btn1").on("click", function () {
							var id = $(this).data("id")

							_this.ajaxDetail(id, function (data) {
								$(".dialog-wp").remove();
								var html = template.render(tpl.printTpl)(data)
								$("body").append(html);
								layui.use('laydate', function () {
									var laydate = layui.laydate;
									laydate.render({
										elem: '#testTime1'
										, type: 'datetime'
										, min: _this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
									});
								})

								$(".dialog-print-btn").on("click", function () {
									_this.pirntEvent({
										visitorId: data.visitorId,
										name: $(".visitor-name").text(),
										phone: $(".visitor-phone").text(),
										company: $(".visitor-company").text(),
										time: $(".visitor-time").val(),
										number: $(".visitor-number").val(),
										nation: $(".visitor-nation").val(),
										address: $(".visitor-address").val(),
										office: $(".visitor-office").val(),
										visitTime: data.visitTime
									})
								})
								$(".close-btn,.dialog-wp .cancel-btn").on("click", function () {
									$(".dialog-wp").remove();
								})
							});

						});
						//弹出框
						//						        console.log("结束的flag",flag)
						//						        if(flag && res.data.length==1){
						//						        	$(".print-btn1").click();
						//						        	flag = false;
						//
						//
						//						        }
						//2020年0416
						if (res.data.length == 1) {
							$(".print-btn1").click();
							//						        	flag = false;


						}
					}
				});
				//查询
				$('#conditionform  .search-btn').on('click', function () {
					_this.againRenderTable();
				});
			});

		},
		htmlTableData: function(passList) {
			var total = Number(passList.length)
			var pageNum = 10 // 每页数
			var currentPage = 1 // 当前页
			var totalPages = Number(parseInt((total/pageNum).toString())) // 总页数

			if (total%pageNum>0) {
				totalPages = totalPages + 1
			}

			var dataList = passList.slice((currentPage-1)*pageNum, pageNum*currentPage)

			this.upTableData(passList, dataList, total, pageNum, currentPage, totalPages)
		},
		upTableData: function (passList, dataList,total,pageNum,currentPage,totalPages) {
			var _this = this
			$(".details_table").replaceWith(template.render(tpl.detailsTable)({
				dataList,
				total,
				pageNum,
				currentPage,
				totalPages,
			}));
			// 分页点击
			$(".page-btn").on("click",function(){
				var indexRow = Number($(this).attr("data-page"));
				var newDataList = passList.slice((indexRow-1)*pageNum, pageNum*indexRow)
				_this.upTableData(newDataList, total, pageNum, indexRow, totalPages)
			});
			// 上下按钮
			$(".layui-btn").on("click",function(){
				var indexPage = Number(currentPage);
				var indexRow = Number($(this).attr("data-page"));
				if (indexRow == 0) {
					indexPage -=1;
				}
				if (indexRow == 1) {
					indexPage +=1;
				}
				var newDataList = passList.slice((indexPage-1)*pageNum, pageNum*indexPage)
				_this.upTableData(newDataList, total, pageNum, indexPage, totalPages)
			});
			$(".determine-btn").on("click",function(){
				let indexPage = Number($(".input-page").attr("value"))
				if (indexPage>totalPages) {
					indexPage = totalPages;
					$(".input-page").val(indexPage)
				}
				if (indexPage != currentPage) {
					var newDataList = passList.slice((indexPage-1)*pageNum, pageNum*indexPage)
					_this.upTableData(newDataList, total, pageNum, indexPage, totalPages)
				}
			});
		},
		pirntEvent: function (data, type) {
			var _this = this
			if (type == 1) {
				//visitorModelTpl
				$(".dialog-wp").remove();
				$("body").append(template.render(tpl.visitorModelTpl)(data))
				$(".close-btn,.dialog-wp .cancel-btn").on("click", function () {
					$(".dialog-wp").remove();
					_this.againRenderTable();
				})
				$(".dialog-print-btn").on("click", function () {
					$("#printCon").remove();
					$("body").append(template.render(tpl.printModelTpl)(data))
					//_this.scanUpdateVisitorInfo(data,function(){
					$(".dialog-wp").remove();
					_this.openPrint();
					//})

				})
			} else {
				$("#printCon").remove();
				$("body").append(template.render(tpl.printModelTpl)(data))
				_this.scanUpdateVisitorInfo(data, function () {
					$(".dialog-wp").remove();
					_this.openPrint();
				})
			}
		},
		scanUpdateVisitorInfo: function (data, callback) {
			if (data.number && !checkIDCard(data.number)) {
				layer.msg('身份证号有误！');
				return false;
			}
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/lingling/scanUpdateVisitorInfo",
				data: {
					"visitorId": data.visitorId,
					"leaveTime": data.time,//预计离开时间
					"idenNumber": data.number,//身份证编码
					"censusAddr": data.address,//户籍地址
					"race": data.nation,//民族
					"police": data.office//签发机关
				},
				success: function (data) {
					if (data && data.code == 200) {
						callback && callback();
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},

		formatDate: function (date, fmt) {
			if (/(y+)/.test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
			}
			let o = {
				'M+': date.getMonth() + 1,
				'd+': date.getDate(),
				'h+': date.getHours(),
				'm+': date.getMinutes(),
				's+': date.getSeconds()
			}
			for (let k in o) {
				if (new RegExp(`(${k})`).test(fmt)) {
					let str = o[k] + ''
					fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str))
				}
			}
			return fmt
		},
		// 获取访客预约码地址
		getVisitorQenterUrlHandler: function (orgId, callback) {
			console.log('orgId', orgId);
			let contextPath = window.location.hostname === 'localhost'? 'https://wx.palmnest.com/super_cloud' : $("#contextPath").val().split("super_service")[0]+"super_cloud"
			$.ajax({
				type: "post",
				url: contextPath + "/api/organisation/wechat/qenter/getVisitorQenterUrl",
				data: {
					"orgId": orgId,
				},
				success: function (data) {
					if (data && data.code == 200) {
						callback(data.data);
					} else {
						layer.msg(data.msg);
						callback();
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		visitorRegister: function (data, callback) {
			var _this = this;
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/lingling/saveVisitorUserInfo",
				data: {
					"arrarId": 1,
					"startDateTime": _this.formatDate(new Date(), 'yyyy-MM-dd') + " 00:00",
					"endDateTime": _this.formatDate(new Date(), 'yyyy-MM-dd') + " 23:59",
					"leaveTime": data.time,//预计离开时间
					"idenNumber": data.number,//身份证编码
					"censusAddr": data.address,//户籍地址
					"race": data.nation,//民族
					"police": data.office,//签发机关
					"visitorType1": 5,
					"type": 5,
					"visitorPhone1": data.phone,//手机号码
					"virtualArchId": data.companyId,//企业id
					"companyName": data.company,//企业名称
					"visitorName1": data.name,//访客姓名
				},
				success: function (data) {
					if (data && data.code == 200) {
						callback && callback();
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},

		openPrint: function () {
			var myWindow = window.open('', '标题');
			//获取id为app内的html
			var bodyHtml = window.document.getElementById('printCon').innerHTML;
			// 获取head标签内的html
			var headHtml = document.head.innerHTML;
			// 头中的screen换成打印样式print
			headHtml = headHtml.replace('screen', 'screen, print');
			//重新写入文档流
			myWindow.document.write('<html>');
			myWindow.document.write(headHtml);
			myWindow.document.write('<body >');
			myWindow.document.write(bodyHtml);
			myWindow.document.write('<script>setTimeout(function() {window.print(); window.close();}, 500)</');
			myWindow.document.write('script>');
			myWindow.document.write('</body></html>');
		},
		/*重新渲染table*/
		againRenderTable: function (option) {
			var obj = $.extend(true, {}, option);
			var type = obj.type || ''
			var $orgId = $("#conditionform  .single-orgid");
			var orgId = $("#conditionform  #orgId").attr('org__id')
			if (type == 1) {
				table.reload('testReload', {
					where: { //设定异步数据接口的额外参数，任意设
						orgId: $orgId.length ? orgId : '',
						visitorInfo: $(".visitorInfo").val(),
						beginTime: $("#startTime").val(),
						endTime: $("#endTime").val(),
						respondentsInfo: $(".respondentsInfo").val(),
						visitorOrderStatus: $("#visitorOrderStatus").val(),
						objective: $(".objective").val(),
						createBeginTime: $("#createBeginTime").val(),
						createEndTime: $("#createEndTime").val(),
						visitorId: $(".visitorId").val()
					}
					, page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			} else {
				table.reload('testReload', {
					where: { //设定异步数据接口的额外参数，任意设
						orgId: orgId,
						visitorInfo: $(".visitorInfo").val(),
						beginTime: $("#startTime").val(),
						endTime: $("#endTime").val(),
						respondentsInfo: $(".respondentsInfo").val(),
						visitorOrderStatus: $("#visitorOrderStatus").val(),
						objective: $(".objective").val(),
						createBeginTime: $("#createBeginTime").val(),
						createEndTime: $("#createEndTime").val(),
						visitorId: $(".visitorId").val()
					}
					, page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}

		},
		ajaxDetail: function (visitorId, callback) {
			var _this = this
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/lingling/visitorInfo",
				data: {
					"visitorId": visitorId
				},
				success: function (data) {
					if (data && data.code == 200) {
						var html = detailTmp(data.data)
						if (!callback) {
							$("body").append(html)
							if (data.data.passList.length>0) {
								$("#wrap-view").addClass("wrap_height"); // 追加样式
								_this.htmlTableData(data.data.passList)
							}
						}

						callback && callback(data.data);
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		// 获取项目通行方案设计详情
		getCaseDetail(orgid){
			var contextPath = window.location.hostname === 'localhost'? 'http://wx.palmnest.com/super_cloud' : $("#contextPath").val().split("super_service")[0]+"super_cloud";
			$.ajax({
				type: "get",
				// url: "http://wx.palmnest.com/super_cloud" + "/api/organisation/organization/"+orgid,
				url: contextPath + "/api/organisation/organization/"+orgid,
				success: function (data) {
					if (data && data.code == 200) {
						if(data.data.passType=="3"){
							$("input[type='checkbox']").eq(0).attr("checked",true);
						}else if(data.data.passType=="2"){
							$("input[type='checkbox']").eq(1).attr("checked",true);
						}else if(data.data.passType=="4"){
							$("input[type='checkbox']").eq(2).attr("checked",true);
							$(".kaola_info").css("display","block");
							$(".koalaAuthUrl input").val(data.data.koalaAuthUrl)
							$(".koalaUserName input").val(data.data.koalaUserName)
							$(".koalaUserPwd input").val(data.data.koalaUserPwd)
						}else{
							$("input[type='checkbox']").eq(0).attr("checked",false);
							$("input[type='checkbox']").eq(1).attr("checked",false);
							$("input[type='checkbox']").eq(2).attr("checked",false);
						}
					}else{
						$("input[type='checkbox']").eq(0).attr("checked",false);
						$("input[type='checkbox']").eq(1).attr("checked",false);
						$("input[type='checkbox']").eq(2).attr("checked",false);
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		// 获取基础设置数据
		getSetData(orgId) {
			var _this = this
			setData.orgId = orgId
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/visitor/order/getCurrentsetInfo",
				data: {
					orgId
				},
				success: function (data) {
					if (data&&data.code == 200) {
						if (data.data) {
							setData = {
								id: data.data.id,
								orgId: data.data.orgId,
								isLinglingAudit: data.data.isLinglingAudit,
								visitedCompType: data.data.visitedCompType,
								visitedMobileType: data.data.visitedMobileType,
								visitCompType: data.data.visitCompType,
								visitNameType: data.data.visitNameType,
								orderAffirm: data.data.orderAffirm
							}
							fieldList.forEach(item => {
								if (item.label === '被访人公司') {
									item.value = setData.visitedCompType
								}
								if (item.label === '被访人手机号') {
									item.value = setData.visitedMobileType
								}
								if (item.label === '访客公司') {
									item.value = setData.visitCompType
								}
								if (item.label === '访客姓名') {
									item.value = setData.visitNameType
								}
								if (setData.isLinglingAudit == 1) {
									if (item.label === '被访人公司'||item.label === '被访人手机号') {
										item.disabled = false
									}
								} else {
									if (item.label === '被访人公司'||item.label === '被访人手机号') {
										item.disabled = true
									}
								}
							})
							if (setData.isLinglingAudit == 1) {
								$("#audit").attr("checked",true);
							}
							if (setData.orderAffirm == 1) {
								$("#make").attr("checked",true);
							}
							_this.upFieldDataUI()
						}else{
							console.log("111111111111")
							setData = {
								id: "",
								orgId: "",
								isLinglingAudit:"",
								visitedCompType:"",
								visitedMobileType: "",
								visitCompType: "",
								visitNameType: "",
								orderAffirm:""
							}
							$("#audit").attr("checked",false);
							$("#make").attr("checked",false);
							fieldList.forEach(item => {
								if (item.label === '被访人公司') {
									item.value = setData.visitedCompType
								}
								if (item.label === '被访人手机号') {
									item.value = setData.visitedMobileType
								}
								if (item.label === '访客公司') {
									item.value = setData.visitCompType
								}
								if (item.label === '访客姓名') {
									item.value = setData.visitNameType
								}
								if (setData.isLinglingAudit == 1) {
									if (item.label === '被访人公司'||item.label === '被访人手机号') {
										item.disabled = false
									}
								} else {
									if (item.label === '被访人公司'||item.label === '被访人手机号') {
										item.disabled = true
									}
								}
							})
							_this.upFieldDataUI()
						}
					}
				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
		//请求项目列表
		itemAjax: function () {
			$.ajax({
				type: "post",
				url: $("#contextPath").val() + "/admin/templ/getOrgList",
				success: function (data) {
					if (data.code == 200) {
						orgList = data.data;
					} else {
						layer.msg(data.msg)
					}

				},
				error: function (error) {
					layer.msg('error')
				}
			});
		},
	}
	visitorOrder.init();
});
function checkIDCard(idcode) {
	// 加权因子
	var weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
	// 校验码
	var check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];

	var code = idcode + "";
	var last = idcode[17];//最后一位

	var seventeen = code.substring(0, 17);

	// ISO 7064:1983.MOD 11-2
	// 判断最后一位校验码是否正确
	var arr = seventeen.split("");
	var len = arr.length;
	var num = 0;
	for (var i = 0; i < len; i++) {
		num = num + arr[i] * weight_factor[i];
	}

	// 获取余数
	var resisue = num % 11;
	var last_no = check_code[resisue];

	// 格式的正则
	// 正则思路
	/*
	第一位不可能是0
	第二位到第六位可以是0-9
	第七位到第十位是年份，所以七八位为19或者20
	十一位和十二位是月份，这两位是01-12之间的数值
	十三位和十四位是日期，是从01-31之间的数值
	十五，十六，十七都是数字0-9
	十八位可能是数字0-9，也可能是X
	*/
	var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;

	// 判断格式是否正确
	var format = idcard_patter.test(idcode);

	// 返回验证结果，校验码和格式同时正确才算是合法的身份证号码
	return last === last_no && format ? true : false;
}
function detailTmp(res) {
	var html = ''
	html += '<div class="mask">'
	html += '<div id="wrap-view" class="pop_wrap">'
	html += '<div class="pop_title">访客详情<span class="pop_close"></span></div>'
	html += '<div class="pop_content">'

	if (res.nodeStr) {
		var nodeArr = res.nodeStr.split(";");
		html += '<ul class="layui-timeline" style="margin-left: 30px; ">'
		for (var i = 0; i < nodeArr.length; i++) {
			html += ' <li class="layui-timeline-item">'
			html += '<i class="layui-icon layui-timeline-axis"></i>'
			html += '<div class="layui-timeline-content layui-text">'
			html += '<h3 class="layui-timeline-title">' + nodeArr[i] + '</h3>'
			html += '</div>'
			html += '</li>'
		}
		html += '</ul>'
	}
	// 基础信息
	html += '<div class="part_ clearfloat">'
	html += '<div class="part_title float-left part_title_depart">基础信息</div>'
	html += '<div class="part_content float-left"></div>'
	html += '</div>'
	if (res.visitorName) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">访客姓名:</div>'
		html += '<div class="part_content float-left">' + res.visitorName + '</div>'
		html += '</div>'
	}
	if (res.visitorCompany) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">来访公司:</div>'
		html += '<div class="part_content float-left">' + res.visitorCompany + '</div>'
		html += '</div>'
	}
	if (res.visitorTelephone) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">访客电话:</div>'
		html += '<div class="part_content float-left">' + res.visitorTelephone + '</div>'
		html += '</div>'
	}
	if (res.visitTime) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">来访时间:</div>'
		html += '<div class="part_content float-left">' + res.visitTime + '</div>'
		html += '</div>'
	}
	if (res.visitCode) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">访客码:</div>'
		html += '<div class="part_content float-left">' + res.visitCode + '</div>'
		html += '</div>'
	}
	if (res.visitTime) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">来访时间:</div>'
		html += '<div class="part_content float-left">' + res.visitTime + '</div>'
		html += '</div>'
	}
	if (res.visitorImage) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">人脸识别照片:</div>'
		html += '<div class="part_content float-left"><img class="touxiang" src="' + res.visitorImage + '" alt="" /></div>'
		html += '</div>'
	}
	if (res.interviewee) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">受访人:</div>'
		html += '<div class="part_content float-left">' + res.interviewee + '</div>'
		html += '</div>'
	}
	if (res.visitReason) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">到访目的:</div>'
		html += '<div class="part_content float-left">' + res.visitReason + '</div>'
		html += '</div>'
	}
	if (res.visitFloor) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">到访楼层:</div>'
		html += '<div class="part_content float-left">' + res.visitFloor + '</div>'
		html += '</div>'
	}
	if (res.visitToCompany) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">到访公司:</div>'
		html += '<div class="part_content float-left">' + res.visitToCompany + '</div>'
		html += '</div>'
	}
	if (res.leaveTime) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">预计离开时间:</div>'
		html += '<div class="part_content float-left">' + res.leaveTime + '</div>'
		html += '</div>'
	}
	// 身份信息
	if (res.idenNumber) {
		html += '<div class="part_ clearfloat idenNum_top">'
		html += '<div class="part_title float-left part_title_depart">身份证信息</div>'
		html += '<div class="part_content float-left"></div>'
		html += '</div>'
	}
	if (res.idenNumber) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">身份证号码:</div>'
		html += '<div class="part_content float-left">' + res.idenNumber + '</div>'
		html += '</div>'
	}
	if (res.cardId) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">身份证卡ID:</div>'
		html += '<div class="part_content float-left">' + res.cardId + '</div>'
		html += '</div>'
	}
	if (res.censusAddr) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">户籍地址:</div>'
		html += '<div class="part_content float-left">' + res.censusAddr + '</div>'
		html += '</div>'
	}
	if (res.race) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">名族:</div>'
		html += '<div class="part_content float-left">' + res.race + '</div>'
		html += '</div>'
	}
	if (res.birthday) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">出生日期:</div>'
		html += '<div class="part_content float-left">' + res.birthday + '</div>'
		html += '</div>'
	}
	if (res.police) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">签发机关:</div>'
		html += '<div class="part_content float-left">' + res.police + '</div>'
		html += '</div>'
	}
	if (res.idenActiveFrom) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">身份证有效开始时间:</div>'
		html += '<div class="part_content float-left">' + res.idenActiveFrom + '</div>'
		html += '</div>'
	}
	if (res.idenActiveTo) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">身份证有效结束时间:</div>'
		html += '<div class="part_content float-left">' + res.idenActiveTo + '</div>'
		html += '</div>'
	}
	if (res.createTime) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">创建时间:</div>'
		html += '<div class="part_content float-left">' + res.createTime + '</div>'
		html += '</div>'
	}
	if (res.headImgName) {
		html += '<div class="part_ clearfloat">'
		html += '<div class="part_title float-left">身份证头像:</div>'
		html += '<div class="part_content float-left"><img class="touxiang" src="' + res.headImgName + '" alt="" /></div>'
		html += '</div>'
	}

	// 通行记录
	html += '<div class="details_table"></div>'

	html += '</div></div></div>'
	return html
}
