var count = 1;
var add = 1;
var indexRow = 0;
var ctx = $("#ctx").val();
var type = $("#type").val();
var remakflag = false;
var base = "";
var flag = false;
var calendar;
var calendar1;
var passType = sessionStorage.getItem('passType');
var orgId = sessionStorage.getItem('orgId')
var visitedCompType = $("#visitedCompType").val() // 被访人公司 1-必填；2-选填；3-不展示；
var visitedMobileType = $("#visitedMobileType").val() // 被访人手机号 1-必填；2-选填；3-不展示；
var visitCompType = $("#visitCompType").val() // 访客公司 1-必填；2-选填；3-不展示；
var visitNameType = $("#visitNameType").val() // 访客姓名 1-必填；2-选填；3-不展示；
var orderAffirm = $("#orderAffirm").val() // 预约信息确认 1-需要确认; 0-不需要确认

$(function () {
	if (!passType) {
		passType = $("#passType").val();
	}
	if (!orgId) {
		orgId = $("#orgId").val();
	}
	console.log('visitedCompType == ', visitedCompType);
	console.log('visitedMobileType == ', visitedMobileType);
	console.log('visitCompType == ', visitCompType);
	console.log('visitNameType == ', visitNameType);
	console.log('orderAffirm == ', orderAffirm);

	//initDate();
	changeStyle()

	if (orgId == 969||orgId == 1247) {
		$('#shareHead').hide()
	}
	isShare()
	$(".share-btn").click(function () {
		$(".share-mask").show();
	});
	$(".share-mask").click(function () {
		$(".share-mask").hide();
	});
	$(".formBottomText").click(function (event) {
		$(".specification-mask").show();
	});
	$(".back-visitor").click(function (event) {
		$(".specification-mask").hide();
	});

	var userMobile = sessionStorage.getItem('mobile');

	if (userMobile&&(userMobile != ''||userMobile != null)) {
		$('.phone-value').val(userMobile);
	}

	 var datetime = new Date();
     var year = datetime.getFullYear();
     var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
     var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
     $('.select-value3').val(year+'-'+month+'-'+date);

	getSettingTime();


	$("#addVistor").click(function () {
		var length = $(".userTip").length + 1;
		//console.log('length',length);
		count++;
		add++;
		indexRow++;
		var html;
		if (passType.indexOf("4") != -1) {
			html = "<div class='userTip visitor-person-wp' id='userTip" + count + "'>" +
					"<div class='tippp' >访客" + indexRow + "<span class='left-icon' ></span><div href='javascript: void(0);'  class='userDel' onclick='deleteVistor(" + count + ")'></div></div>" +
					"<div class='userForm' style='display: flex'>" +
					"<input type='hidden' class='count' value='" + count + "' />" +
					"<input type='hidden' name='imageUrl" + count + "' id='imageUrl" + count + "' />" +
					"<input type='hidden' name='showimageUrl" + count + "' id='showimageUrl" + count + "' />" +
					"<input type='hidden' name='imageFacePlusId" + count + "' id='imageFacePlusId" + count + "' />" +
					"<div class='userHead' style='flex: 0 0 73px;width: 73px' id='userHead" + count + "'>" +
					"<input type='file' id='fileinput" + count + "' pictype='30010003' data-role='none' accept='image/*' onchange='selectFileImage(" + count + ",this)'  />" +
					"</div>" +
					"<div class='userInfo' style='flex: 1' id='userInfo" + count + "'>"
					if (visitNameType != 3) {
						html += "<div class='infor-line'><div class='info-text infor-tip'>"
						if (visitNameType == 1) {
							html += "<i style='color: red;font-style: normal;'>*</i>"
						}
						html += "姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</div><div class='infor-text'><input id='visitorName" + count + "' type='text' name='visitorName" + count + "' placeholder='请输入访客姓名' value='' /></div></div>"
					}
					html += "<div class='infor-line'>	<div class='info-text infor-tip'><i style='color: red;font-style: normal;'>*</i>手机号码：</div><div class='infor-text'><input type='text' placeholder='请输入访客手机号码' id='visitorPhone" + count + "' value='' name='visitorPhone" + count + "' /></div></div>" +
					"</div>" +
					"" +
					"</div>" +
					"</div>";
		} else {
			html = "<div class='userTip visitor-person-wp' id='userTip" + count + "'>" +
					"<div class='tippp' >访客" + indexRow + "<span class='left-icon' ></span><div href='javascript: void(0);' class='userDel' onclick='deleteVistor(" + count + ")'></div></div>" +
					"<div class='userForm'>" +
					"<input type='hidden' class='count' value='" + count + "' />" +
					"<input type='hidden' name='imageUrl" + count + "' id='imageUrl" + count + "' />" +
					"<input type='hidden' name='showimageUrl" + count + "' id='showimageUrl" + count + "' />" +
					"<input type='hidden' name='imageFacePlusId" + count + "' id='imageFacePlusId" + count + "' />" +
					"<div class='userInfo' id='userInfo" + count + "'>"
					if (visitNameType != 3) {
						html += "<div class='infor-line'><div class='info-text infor-tip'>"
						if (visitNameType == 1) {
							html += "<i style='color: red;font-style: normal;'>*</i>"
						}
						html += "姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</div><div class='infor-text'><input id='visitorName" + count + "' type='text' name='visitorName" + count + "' placeholder='请输入访客姓名' value='' /></div></div>"
					}
					html += "<div class='infor-line'><div class='info-text infor-tip'><i style='color: red;font-style: normal;'>*</i>手机号码：</div><div class='infor-text'><input type='text' placeholder='请输入访客手机号码' id='visitorPhone" + count + "' value='' name='visitorPhone" + count + "' /></div></div>" +
					"</div>" +
					"" +
					"</div>" +
					"</div>";
		}
		if (add >= 5) {
			$("#addVistor").hide();
		}
		$(".formBottom").before(html);
	});
	// $("#company_df").on('focus',function(event) {

	// });
	$("#company_df").on("input", function (event) {
		var orgId = sessionStorage.getItem("orgId");
		var virName = $("#company_df").val()
		// 设置定时器检测用户输入时间
		if (typeof (delayClock) != "undefined") {
			clearTimeout(delayClock);
		}
		delayClock = setTimeout(function () {
			$.ajax({
				url: $("#ctx").val() + "/wechat/visitor/virList",
				type: "POST",
				dataType: "json",
				data: {
					orgId: orgId,
					virName: virName
				},
				success: function (data) {
					var dataArr = data.data
					var html = ''
					if (dataArr.length) {
						$('.select_wrap').show()
						$.each(dataArr, function (index, el) {
							html += '<span class="companySpan" id="' + el.id + '">'
							html += el.name
							html += '</span>'
						});
						$('.select_wrap').empty().append(html)
					} else {
						$('.select_wrap').empty().hide()
					}
				}
			});
		}, 300);
	});
	$('.select_wrap').on('click', '.companySpan', function (event) {
		event.preventDefault();
		event.stopPropagation();
		/* Act on the event */
		var _this = $(this)
		var companyId = _this[0].id
		var companyName = _this[0].innerText
		$('#company_df').val(companyName).attr({
			companyId: companyId
		});
		$('.select_wrap').hide()
	});
	$("#company_df").on('blur', function (event) {
		/* Act on the event */
		closeClock = setTimeout(function () {
			$('.select_wrap').hide()
		}, 200)
		// 清除定时器检
		if (typeof (delayClock) != "undefined") {
			clearTimeout(delayClock);
		}
	});
	$('#phone_visitor').on('blur', function (event) {
		var reg = /^\s*$/g;
		var regPhone = /^1[0-9]{10}$/;
		var phone_visitor = $("#phone_visitor").val();
		var employeeCompanyId = $('#company_df').attr('companyId')
		if (reg.test(phone_visitor)) {
			showMessage("请输入访问人手机号");
			return;
		}
		if (!regPhone.test(phone_visitor)) {
			showMessage("手机号码格式有误 ，请重填");
			return;
		}
		$.ajax({
			url: $("#ctx").val() + "/wechat/visitor/checkEmployee",
			type: "POST",
			dataType: "json",
			data: {
				employeeCompanyId: employeeCompanyId,
				employeePhone: phone_visitor
			},
			success: function (data) {
				if (data.code != 200) {
					showMessage(data.msg);
				}
			}
		});



	})
	$("#saveuser").click(function () {
		if (!$(".select-value3").val()) {
			showMessage("请选择日期");
			return;
		}
		var countInput = $(".count");
		var strcount = "";
		$.each(countInput, function (index, obj) {
			strcount += $(obj).val() + ",";
		});
		$("#arrarId").val(strcount);
		saveInfo(strcount);
	});

	$("#submit").click(function () {
		$("#visitorWelComing").val($("#remark").val());
		if (remakflag) {
			var reg = /^\s*$/g;
			if (reg.test($("#remark").val())) {
				flag = false;
				showMessage("请输入欢迎语");
				return;
			} else {
				var _reg = /^\S{1,40}$/;
				if (!_reg.test($("#remark").val())) {
					flag = false;
					showMessage("欢迎语，长度必须在1-40之间");
					$("#remark").focus();
					return;
				}
				$("#remark").css("border", "1px solid #e5e5e5");
			}
		}
		saveVisitorInfo();
	});
});
function changeStyle() {
	// 令令通行去掉头像 //20200413新增
	if (passType.indexOf("4") === -1) {
		$('.userHead').hide()
		$('.userInfo').css({
			width: '100%',
		});
	}
	// type 2-员工填写(白名单) 1-员工分享由访客填写 3-访客自己发起/填写(非白名单)
	if (type != 2) {
		$('.imgHead').hide()
	}
	// 非白名单
	if (type == 3&&(visitedCompType != 3||visitedMobileType != 3)) {
		$(".visitor-person-wp").show();
		$(".visitor-person-wp.test").addClass("padding-style")
		//        $('.whiteList').show()
		//        $('.tippp_bf').show()

		if (visitedCompType != 3) {
			$(".tippp-company").show();
			if (visitedCompType == 1) {
				$(".tippp-company-must").show();
			}
		}
		if (visitedMobileType != 3) {
			$(".tippp-phone").show();
			if (visitedMobileType == 1) {
				$(".tippp-phone-must").show();
			}
		}

	}

	if (visitCompType != 3) {
		$(".userTip-company").show();
		if (visitCompType == 1) {
			$(".userTip-company-must").show();
		}
	}
	if (visitNameType != 3) {
		$(".userTip-name").show();
		if (visitNameType == 1) {
			$(".userTip-name-must").show();
		}
	}
}
function isShare() {
	if (type != 2) {
		function onBridgeReady() {
			WeixinJSBridge.call('hideOptionMenu');
		}
		if (typeof WeixinJSBridge == "undefined") {
			if (document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
			} else if (document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			}
		} else {
			onBridgeReady();
		}
	} else {
		shareAppMessage();
	}

}
function saveVisitorInfo() {
	var arrarId = $("#arrarId").val();
	var dateValue = $(".select-value3").val() + ' ' + '00:00';
	var stopValue = $(".select-value3").val() + ' ' + '23:59';
	//	var dateValue = $("#dateValue").html() + ' ' +'00:00';
	//	var stopValue = $("#dateValue").html() + ' ' +'23:59';
	var visitorWelComing = $("#visitorWelComing").val();
	if (visitorWelComing == null || visitorWelComing == '') {
		visitorWelComing = " ";
	}
	var openId = $("#openId").val();
	var type = $("#type").val();
	var visitorIdentification = $("#visitorIdentification").val();
	var visitorOpenId = $("#visitorOpenId").val();
	if (visitorOpenId == null || visitorOpenId == '') {
		visitorOpenId = " ";
	}
	var companyName = $("#companyId").val();
	var employeeCompanyId = $("#company_df").attr('companyId');
	var employeePhone = $("#phone_visitor").val();
	var ids = arrarId.split(",");
	if (employeeCompanyId === null||employeeCompanyId === undefined ||employeeCompanyId === 'null') {
		employeeCompanyId = ''
	}
	var data = "{arrarId:'" + arrarId +"',orgId:'" + orgId + "',startDateTime:'" + dateValue + "',endDateTime:'" + stopValue + "'" +
		",visitorWelComing:'" + visitorWelComing + "',openId:'" + openId + "',type:'" + type + "'" +
		",visitorIdentification:'" + visitorIdentification + "',visitorOpenId:'" + visitorOpenId + "'" +
		",companyName:'" + companyName + "'";
	if (type == 3) {
		data += (",employeeCompanyId:'" + employeeCompanyId + "'")
		data += (",employeePhone:'" + employeePhone + "'")
	}
	for (var i = 0; i < ids.length; i++) {
		if (ids[i] != '') {
			var visitorName = $('#visitorName' + ids[i] + '').val();
			var visitorPhone = $('#visitorPhone' + ids[i] + '').val();
			var imageUrl = $('#imageUrl' + ids[i] + '').val();
			var showimageUrl = $('#showimageUrl' + ids[i] + '').val();
			var imageFacePlusId = $('#imageFacePlusId' + ids[i] + '').val();
			if (imageUrl == null || imageUrl == '') {
				imageUrl = " ";
			}
			var visitorType = $('#visitorType' + ids[i] + '').val();
			if (visitorType === null||visitorType === undefined ||visitorType === 'null') {
				visitorType = ''
			}
			data += ",visitorName" + ids[i] + ":'" + visitorName + "'" +
				",visitorPhone" + ids[i] + ":'" + visitorPhone + "'" +
				",imageUrl" + ids[i] + ":'" + imageUrl + "'" +
				",visitorType" + ids[i] + ":'" + visitorType + "'" +
				",showimageUrl" + ids[i] + ":'" + showimageUrl + "'" +
				",imageFacePlusId" + ids[i] + ":'" + imageFacePlusId + "'";
		}
	}
	data += "}";
	var obj = eval('(' + data + ')');
	$.ajax({
		url: $("#ctx").val() + "/wechat/visitor/saveVisitorUserInfo",
		type: "POST",
		dataType: "json",
		data: obj,
		beforeSend: function (xhr) {
			layer.open({
				type: 2,
				content: '提交信息中'
			});
		},
		success: function (data) {
			layer.closeAll();
			if (data.flag) {
				showMessage(data.desc);
				if (data.visitorOrderId) {
					$("#visitorOrderId").val(data.visitorOrderId);
					$("#strPassType").val(data.passType);
					$("#tt").show();
					$("#getVisitorInfoform").submit();
				} else {
					let openId = sessionStorage.getItem("openId");
					let orgId = sessionStorage.getItem("orgId");
					let developId = sessionStorage.getItem("developId");
					let state = sessionStorage.getItem("state");
					let userToken = sessionStorage.getItem("userToken");

					location.href = $("#ctx").val() + "/wechat/visitor/authorVisitor?userId=" + data.userId + "&openId=" + openId + "&orgId=" + orgId + "&state=" + state + "&userToken=" + userToken + "&developId=" + developId;
					// location.href = $("#ctx").val() + "/wechat/visitor/visitorlist?userId=" + data.userId + "&openId=" + openId + "&orgId=" + orgId + "&developId=" + developId;
				}

				// if (data.type == '2') {
				// 	location.href = $("#ctx").val() + "/wechat/visitor/visitorlist?userId=" + data.userId + "&openId=" + data.openId + "&orgId=" + orgId + "&developId=" + developId;
				// 	//  WeixinJSBridge.call("closeWindow");
				// }
				// if (data.type == '1') {
				// 	WeixinJSBridge.call("closeWindow");
				// 	//location.href=$("#ctx").val()+"/wechat/visitor/getVisitorInfoList?visitorOrderId="+data.visitorOrderId+"&type="+data.type;
				// }
				// if (data.type == '3') {//非白名单用户
				// 	WeixinJSBridge.call("closeWindow");
				// 	$('.action').hide()
				// }
			} else {
				showMessage(data.desc);

			}
		}
	});
}

function saveInfo(strcount) {
	var yzrmek = false;
	var ids = strcount.split(","); //拆分ID
	var dateValue = $(".select-value3").val() + ' ' + '00:00';
	var stopValue = $(".select-value3").val() + ' ' + '23:59';
	//	var dateValue = $("#dateValue").html()+' '+'00:00'; //开始时间
	//	var stopValue = $("#dateValue").html()+' '+'23:59'; //结束时间
	var companyName = $("#companyId").val(); //公司名称
	var reg = /^\s*$/g;
	var regPhone = /^1[0-9]{10}$/;
	var flag = false;
	// 判断白名单
	if (type == 3&&(visitedCompType != 3||visitedMobileType != 3)) {

		if (visitedCompType == 1) {
			var company_df = $("#company_df").val();
			if (reg.test(company_df)) {
				showMessage("请输入到访公司名称");
				$("#company_df").focus();
				flag = true;
				return;
			} else {
				// var _reg = /^\S{1,14}$/;
				// if (!_reg.test(visitorName)) {
				// 	flag = true;
				// 	showMessage("姓名长度必须在1-14之间");
				// 	$("#visitorName" + ids[i] + "").focus();
				// 	return;
				// }
			}
			var companyId = $("#company_df").attr('companyId')
			if (!companyId) {
				showMessage("请输入正确的到访公司名称");
				flag = true;
				return;
			}
		}
		if (visitedMobileType == 1) {
			var phone_visitor = $("#phone_visitor").val();
			if (reg.test(phone_visitor)) {
				showMessage("请输入访问人手机号");
				flag = true;
				$("#phone_visitor").focus();
				return;
			}
			if (!regPhone.test(phone_visitor)) {
				showMessage("手机号码格式有误 ，请重填");
				flag = true;
				$("#vphone_visitor").focus();
				return;
			}
		}
	}
	if (visitCompType != 3) {
		if (visitCompType == 1) {
			if (reg.test(companyName)) {
				showMessage("请输入访客公司名称");
				$("#companyId").focus();
				flag = true;
				return;
			} else {
				var _reg = /^\S{1,14}$/;
				if (!_reg.test(companyName)) {
					flag = true;
					showMessage("公司名称长度必须在1-14之间！");
					$("#companyId").focus();
					return;
				}
			}
		} else {
			// 正常判断
			if (!reg.test(companyName)) {
				var _reg = /^\S{1,14}$/;
				if (!_reg.test(companyName)) {
					flag = true;
					showMessage("公司名称长度必须在1-14之间！");
					$("#companyId").focus();
					return;
				}
			}
		}
	}

	for (var i = 0; i < ids.length; i++) {
		if (ids[i] != '') {
			if (visitNameType != 3) {
				var visitorName = $("#visitorName" + ids[i] + "").val();
				if (visitNameType == 1) {
					if (reg.test(visitorName)) {
						showMessage("请输入姓名");
						$("#visitorName" + ids[i] + "").focus();
						flag = true;
						return;
					} else {
						var _reg = /^\S{1,14}$/;
						if (!_reg.test(visitorName)) {
							flag = true;
							showMessage("姓名长度必须在1-14之间");
							$("#visitorName" + ids[i] + "").focus();
							return;
						}
					}
				} else {
					if (!reg.test(visitorName)) {
						var _reg = /^\S{1,14}$/;
						if (!_reg.test(visitorName)) {
							flag = true;
							showMessage("姓名长度必须在1-14之间");
							$("#visitorName" + ids[i] + "").focus();
							return;
						}
					}
				}
			}
			var visitorPhone = $("#visitorPhone" + ids[i] + "").val();
			if (reg.test(visitorPhone)) {
				showMessage("请输入手机号码");
				flag = true;
				$("#visitorPhone" + ids[i] + "").focus();
				return;
			}
			if (!regPhone.test(visitorPhone)) {
				showMessage("手机号码有误 ，请重填");
				flag = true;
				$("#visitorPhone" + ids[i] + "").focus();
				return;
			}
			if (passType.indexOf("4") != -1) {//判断passType 1:face++ 2:二维码
				var userHeadSize = $("#userHead" + ids[i] + " img").length;
				if (userHeadSize == 0) {
					showMessage("请添加头像");
					flag = true;
					$("#userHead" + ids[i]).css("border", "1px dashed #de3838");
					return;
				}
			}
		}
	}

	$("#clearfix").html("<div class='clearfix-top'><p name='companycount' id='companycount' value=''></p>" +
		"<div class='appoint-time'><label name='appointtimehead' id='appointtimehead'>到访时间： </label><span name='appointtime' id='appointtime' value=''></span></div>" +
		"<p id='remarkP' style='display: none;'><input type='text' name='remark' id='remark' placeholder='备注信息：如欢迎语' value='' /></p><div class='line-img'><div class='line-img-left'></div><div class='line-img-right'></div></div></div><div class='clearfix-btm'></div>");
	var count = 0;
	// var week = getMyDay(new Date(dateValue));
	// var date = new Date(dateValue);
	$("#appointtime").html($(".select-value3").val());
	if (flag) {
		return;
	}
	for (var i = 0; i < ids.length; i++) {
		if (ids[i] != '') {
			count += 1;
			if ($("#visitorType" + ids[i] + "").val() == null || $("#visitorType" + ids[i] + "").val() == '' || typeof ($("#visitorType" + ids[i] + "").val()) == "undefined") {
				$(".riqi").append("<input type='hidden' id='visitorType" + ids[i] + "' name='visitorType" + ids[i] + "' value='0'/>");
			}
			var html = "<div class='child clearfix'>";
			if ($("#imageUrl" + ids[i] + "").val() == "") {
				if (passType.indexOf("4") != -1) {
					html += "<img src='../../images/visitor/user.png'/>";
				}
			}
			if ($("#imageUrl" + ids[i] + "").val() != "") {
				var server = $("#showimageUrl" + ids[i] + "").val();
				if (passType.indexOf("4") != -1) {
					html += "<img src='" + server + "'/>";
				}
			}
			if ($("#visitorName" + ids[i] + "").val()&&$("#visitorName" + ids[i] + "").val() !== '') {
				html += "<input type='text' name='guestname' id='guestname' value='" + $("#visitorName" + ids[i] + "").val() + "' disabled='true'>"
			} else {
				html += "<input type='text' name='guestname' id='guestname' value='" + "访客" + (i+1) + "' disabled='true'>"
			}
			html += "<input type='text' name='guestphone' id='guestphone' value='" + $("#visitorPhone" + ids[i] + "").val() + "' disabled='true'>";
			if ($("#visitorType" + ids[i] + "").val() == 0) {
				html += "<span class='gueststate' id='vips" + ids[i] + "' onclick='authorVip(" + ids[i] + ",1)'>VIP</span>" +
					"<span class='gueststateVip' id='vip" + ids[i] + "' onclick='authorVip(" + ids[i] + ",0)' style='display:none'>VIP</span>";
			}
			if ($("#visitorType" + ids[i] + "").val() == 1) {
				yzrmek = true;
				html += "<span class='gueststateVip' id='vip" + ids[i] + "' onclick='authorVip(" + ids[i] + ",0)'>VIP</span>" +
					"<span class='gueststate' id='vips" + ids[i] + "' onclick='authorVip(" + ids[i] + ",1)' style='display:none'>VIP</span>";
			}
			html += "</div>"
			if (yzrmek) {
				$("#remarkP").show();
			}
			$("#clearfix .clearfix-btm").append(html);
		}
	}
	$("#companycount").html(companyName + " &nbsp;&nbsp; 共有" + count + "位到访");

	if (orderAffirm == 0) {
		saveVisitorInfo();
		return;
	}
	$(".outDiv").hide();
	$("#div2").show();

}

function updateVistor() {
	$(".outDiv").show();
	$("#div2").hide();
}

function authorVip(val, ids) {
	if ($("#type").val() == 1 || $("#type").val() == '1') {
		return;
	}
	$("#visitorType" + val + "").val(ids);
	if (ids == 1) {
		var d = document.getElementById("vip" + val + "");
		d.style.backgroundColor = '#f5a623';
		$("#vips" + val + "").hide();
		$("#vip" + val + "").show();
		remakflag = true;
	}
	if (ids == 0) {
		remakflag = false;
		var d = document.getElementById("vip" + val + "");
		d.style.backgroundColor = '#e5e5e5';
		$("#vips" + val + "").show();
		$("#vip" + val + "").hide();
		var arrarId = $("#arrarId").val();
		var ids = arrarId.split(","); //拆分ID
		for (var i = 0; i < ids.length; i++) {
			if (ids[i] != "") {
				var status = $("#visitorType" + ids[i] + "").val();
				if (status == 1) {
					remakflag = true;
				}
			}
		}
	}
	if (remakflag) {
		$("#remarkP").show();
	}
	if (!remakflag) {
		$("#remarkP").hide();
	}
}

function getMyDay(date) {
	var week;
	if (date.getDay() == 0) week = "周日"
	if (date.getDay() == 1) week = "周一"
	if (date.getDay() == 2) week = "周二"
	if (date.getDay() == 3) week = "周三"
	if (date.getDay() == 4) week = "周四"
	if (date.getDay() == 5) week = "周五"
	if (date.getDay() == 6) week = "周六"
	return week;
}

function deleteVistor(count) {
	$("#userTip" + count + "").remove();
	add--;

	var userTitles = $(".userTitle");
	$.each(userTitles, function (index, obj) {
		if (index + 1 <= add) {
			$(obj).html("访客" + (index + 1));
		}
	});
	if (add < 5) {
		$("#addVistor").show();
	}
}

function delImage(val) {
	var html = "<input type='file' id='fileinput" + val + "' pictype='30010003' data-role='none' accept='image/*' onchange='selectFileImage(" + val + ",this)'  />" +
		"<input type='hidden' name='imageUrl" + val + "' id='imageUrl" + val + "' />" +
		"<input type='hidden' name='showimageUrl" + val + "' id='showimageUrl" + val + "' />" +
		"<input type='hidden' name='imageFacePlusId" + val + "' id='imageFacePlusId" + val + "' />";
	$("#imageUrl" + val + "").val("");
	$("#showimageUrl" + val + "").val("");
	$("#imageFacePlusId" + val + "").val("");
	$("#userHead" + val + "").html(html);
}

//初始化 选择默认的时间
function initDate() {
	var date = new Date();
	var startDay = date.getDate();
	var startHours = date.getHours();
	var startMinutes = date.getMinutes() + 5;
	if (startDay < 10) {
		startDay = "0" + startDay;
	}
	//显示年月日，传的时候加时分
	$("#dateValue").html(date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + startDay);
	calendar = new datePicker();
	calendar.init({
		'trigger': '#dateValue',
		/*按钮选择器，用于触发弹出插件*/
		'type': 'date',
		/*模式：date日期；datetime日期时间；time时间；ym年月；*/
		'minDate': date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + startDay,
		/*最小日期*/
		'maxDate': '2100-12-31',
		/*最大日期*/
		'onSubmit': function () { /*确认时触发事件*/
			var theSelectData = calendar.value;
		},
		'onClose': function () { /*取消时触发事件*/ }
	});
}

function showTime() {
	$(".timemask").show();
}

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

function yzstartDateTime() {
	var reg = /^\s*$/g;
	var dateValue = $("#dateValue").html();
	if (reg.test(dateValue)) {
		$("#dateValue").focus();
		showMessage("请选择日期");
		return false;
	}
	return true;
}

function shareAppMessage() {
	var type = '';
	type = passType.split(",").join('')
	console.log(type, 'passType')
	var state = $("#openId").val() + ',' + $("#visitorIdentification").val() + "," + $("#developId").val() + "," + type + "," + sessionStorage.getItem('orgId');
	$.ajax({
		url: $("#ctx").val() + "/wechat/visitor/fenxiang",
		type: "POST",
		async: true,
		cache: false,
		dataType: "json",
		data: {
			url: location.href.split('#')[0],
			developId: $("#developId").val()
		},
		success: function (data) {

			wx.config({
				debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
				appId: data.appid, // 必填，公众号的唯一标识
				timestamp: data.timestamp, // 必填，生成签名的时间戳
				nonceStr: data.nonceStr, // 必填，生成签名的随机串
				signature: data.signature, // 必填，签名，见附录1
				jsApiList: ['checkJsApi',
					'hideOptionMenu',
					'onMenuShareAppMessage',
					'hideMenuItems',
					'hideAllNonBaseMenuItem'
				] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
			});
			var url = $("#webUrl").val() + "/wechat/visitor/visitorUserAuthor?appid=" + data.appid + "&state=" + state;
			wx.ready(function () {
				if (orgId == 969||orgId == 1247) {
					wx.hideAllNonBaseMenuItem()
				} else {
					wx.checkJsApi({
						jsApiList: [
							'onMenuShareAppMessage',
							'hideMenuItems'
						],
						success: function (res) {
							//alert(res.errMsg);
						}
					});
					wx.hideMenuItems({
						menuList: ['menuItem:share:timeline', 'menuItem:share:qq', 'menuItem:share:weiboApp', 'menuItem:favorite', 'menuItem:share:QZone',
							'menuItem:copyUrl', 'menuItem:openWithQQBrowser', 'menuItem:openWithSafari',
							'menuItem:share:email'] // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
					});
					//alert(url);
					wx.onMenuShareAppMessage({
						title: '访客预约',
						link: url,
						desc: $("#userName").val() + '邀请你来访' + $("#companyName").val() + '，点击自助登记来访信息',
						imgUrl: $("#webUrl").val() + '/images/visitor/log.png'
					});
				}
			});

			wx.error(function (res) {
				console.log('res', res)
				wx.hideOptionMenu();
			});
		}
	});
}

function getSettingTime() {

	var method3 = $('.select-value3').mPicker({
		level: 1,
		dataJson: [{ name: 1, value: 1 }],
		Linkage: false,
		rows: 6,
		idDefault: true,
		header: '<div class="mPicker-header">选择时间</div>',
		confirm: function (json) {
			console.info('当前选中json：', json);
		},
		cancel: function (json) {
			console.info('当前选中json：', json);
		}
	})
	$.ajax({
		url: $("#ctx").val() + "/wechat/visitor/getDateInfoByOrgId",
		type: "POST",
		data: {
			orgId: orgId,
		},
		success: function (data) {
			if (data&&data.code == 200) {
				var dataJson = [];
				if (data.data != null&&data.data != undefined&&data.data != '') {
					data.data.forEach(function (item) {
						dataJson.push({
							name: item,
							value: item
						})
					})
				}
				var method3 = $('.select-value3').mPicker({
					level: 1,
					dataJson: dataJson,
					Linkage: false,
					rows: 6,
					idDefault: true,
					header: '<div class="mPicker-header">选择时间</div>',
					confirm: function (json) {
						console.info('当前选中json：', json);
					},
					cancel: function (json) {
						console.info('当前选中json：', json);
					}
				})
			};
		}, error: function (xhr, textStatus) {

		}
	});
}

function GetUrlParam(paraName) {
	var url = document.location.toString();
	var arrObj = url.split("?");
	if (arrObj.length > 1) {
		var arrPara = arrObj[1].split("&");
		var arr;
		for (var i = 0; i < arrPara.length; i++) {
			arr = arrPara[i].split("=");
			if (arr != null && arr[0] == paraName) {
				return arr[1];
			}
		}
		return "";
	} else {
		return "";
	}
}
