
var permDelete = $("#perm-delete").val();//删除权限
var permEdit = $("#perm-edit").val();//编辑权限

/*
 * 企业管理
 */
$(function() {
	var tpl = {
			"checkPaper": '<div class="dialog-wp">\
				<div class="mask"></div>\
				<div class="dialog dialog-paper-con">\
					<div class="title-wp">\
						<span>查看证件</span>\
						<span class="close-btn"></button>\
					</div>\
					<div class="dialog-paper-wp">\
						<div class="paper-wip">\
							<span class="red">*</span>点击图片可查看大图\
						</div>\
						<div class="paper-list clearfloat">\
							<div class="paper-item">\
								<div class="p-img-wp">\
									<% if(!data.businessImageUrl){%>\
										上传\
									<% }else{ %>\
										<img src="<%=data.businessImageUrl%>" />\
									<%} %>	\
								</div>\
								<div class="p-i-name">营业执照</div>\
								<div class="upload-wp">\
									重新上传\
									<input type="file" class="c-file-btn" data-dom = "this" data-type="1">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%=data.businessImage%>" />\
								</div>\
							</div>\
							<div class="paper-item">\
								<div class="p-img-wp f-img-wp">\
									<% if(!data.attorneyImageUrl){%>\
										上传\
									<% }else{ %>\
										<img src="<%=data.attorneyImageUrl%>" />\
									<%} %>	\
								</div>\
								<div class="p-i-name">法人代表授权委托书</div>\
								<div class="upload-wp">\
									重新上传\
									<input type="file" class="c-file-btn" data-dom = "this" data-type="2">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%=data.attorneyImage%>"/>\
								</div>\
							</div>\
							<div class="paper-item">\
								<div class="p-img-wp s-img-wp">\
									<% if(!data.faceImageUrl){%>\
										上传\
									<% }else{ %>\
										<img src="<%=data.faceImageUrl%>" />\
									<%} %>	\
								</div>\
								<div class="p-i-name">身份证人像面</div>\
								<div class="upload-wp">\
									重新上传\
									<input type="file" class="c-file-btn" data-dom = "this" data-type="3">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%=data.faceImage%>"/>\
								</div>\
							</div>\
							<div class="paper-item">\
								<div class="p-img-wp sb-img-wp" >\
									<% if(!data.nationImageUrl){%>\
										上传\
									<% }else{ %>\
										<img src="<%=data.nationImageUrl%>" />\
									<%} %>	\
								</div>\
								<div class="p-i-name">身份证国徽面</div>\
								<div class="upload-wp">\
									重新上传\
									<input type="file" class="c-file-btn" data-dom = "this" data-type="4">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%=data.nationImage%>"/>\
								</div>\
							</div>\
						</div>\
						<div class="paper-btns">\
							<button class="btn-big-red paper-change-btn ">确认更改</button>\
							<button class="btn-big-black paper-cancel-btn ">取消</button>\
						</div>\
					</div>\
				</div>\
			</div>	',
			"addDialog": '<div class="dialog-wp"> \
							<div class="mask"></div>\
							<div class="dialog dialog-enterprise-con">\
								<div class="title-wp">\
									<span>添加企业</span>\
									<span class="close-btn"></button>\
								</div>\
								<div class="dialog-enterprise-wp">\
									<div class="top-title">\
										<span class="left-line"></span>\
										<span class="title">企业信息</span>	\
										<span class="right-line"></span>\
									</div>\
									<div class="floors-wp clearfloat">\
										<div class="choose-floors">\
											<span class="tips">楼宇</span>\
											<select class="select-width180 build-org">\
												<option value="10">尚美科技大厦</option>\
											</select>\
										</div>\
										<div class="choose-floors">\
											<span class="tips">入驻时间</span>\
											<input class="input-black-width180 enter-time" id="enterTime" type="text" placeholder="请选择" readonly/>\
										</div>				\
										<div class="choose-room clearfloat">\
											<span class="tips">楼层房间号</span>\
											<select class="select-width100 floors-select">\
												<option value="">楼层</option>\
												<% for(var i=0;i<floorList.length;i++){%>\
													<option value="<%=floorList[i].id %>"><%=floorList[i].name%></option>\
												<%} %>\
											</select>\
											<div class="rooms-select">\
												<div class="rooms-select-btn">房间号</div>\
												<ul class="room-list">\
												</ul>\
											</div> \
											<div class="select-room-wp clearfloat"></div>\
										</div>\
									</div>\
									<div class="enterprise-info-wp clearfloat">\
										<div class="enter-wp">\
											<span class="tips">企业名称</span>\
											<input class="input-black-width180 enterprise-name" type="text" placeholder="请输入该公司名称">\
										</div>\
										<div class="enter-wp">\
											<span class="tips">公司编号</span>\
											<input class="input-black-width180 enterprise-code" type="text" placeholder="请输入该公司编号">\
										</div>\
										<div class="enter-wp">	\
											<span class="tips">月度免费时长</span>\
											<input class="input-black-width180 enterprise-freeLenTime"  type="text" placeholder="请输入月度免费时长">\
										</div>\
										<div class="enter-wp">	\
											<span class="tips">月度剩余时长</span>\
											<input class="input-black-width180 enterprise-remainderTime" type="text" placeholder="请输入月度剩余时长">\
										</div>\
										<div class="enter-wp">\
											<span class="tips">备注</span>\
											<input class="input-black-width420 enterprise-remark" type="text" placeholder="备注">\
										</div>\
									</div>\
								   <div class="enterprise-file-wp clearfloat">\
										<div class="e-f-wp e-business-license">\
											<div class="del-btn"></div>\
											<input type="file" class="file-btn">\
											<input type="hidden" id="business" name="serviceIcon"/>\
											<div class="img-wp"></div>\
										</div>\
										<div class="e-f-wp e-certificate">\
											<div class="del-btn"></div>\
											<input type="file" class="file-btn">\
											<input type="hidden" id="business" name="serviceIcon"/>\
											<div class="img-wp"></div>\
										</div>\
										<div class="e-f-wp e-id-facade">\
											<div class="del-btn"></div>\
											<input type="file" class="file-btn">\
											<input type="hidden" id="business" name="serviceIcon"/>\
											<div class="img-wp"></div>\
										</div>\
										<div class="e-f-wp e-id-back">\
											<div class="del-btn"></div>\
											<input type="file" class="file-btn">\
											<input type="hidden" id="business" name="serviceIcon"/>\
											<div class="img-wp"></div>\
										</div>\
									</div>	\
									<div class="choose-list-wp">\
										<span class="tips">企业在租状态</span>\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="zu" class="radio-item enterprise-rent" data-status="1" name="status" checked/>\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="zu">在租</label>\
										</div>\
										<div class="radio-wp">\
										   <span class="radio-input">\
											 <input type="radio" id="qian" class="radio-item enterprise-move" data-status="0" name="status"/>\
											  <span class="radio-inner"></span>\
										   </span>		\
										   <label class="radio-con" for="qian">已迁出</label>\
										</div>\
										<span class="bill-tips tips">账单推送方式</span>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="wx" class="check-item enterprise-wx" />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="wx">微信</label>\
										</div>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="email" class="check-item enterprise-email"  />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="email">邮箱</label>\
										</div>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="msg" class="check-item enterprise-msg" />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="msg">短信</label>\
										</div>\
									</div>\
									<div class="top-title">\
										<span class="left-line"></span>\
										<span class="title">负责人信息</span>	\
										<span class="right-line"></span>\
									</div>\
									<div class="leader-first">\
										<span class="tips">负责人1</span>\
										<input class="input-black-width180 charge-name-1" type="text" placeholder="姓名">\
										<input class="input-black-width180 charge-mobile-1" type="text" placeholder="电话">\
										<input class="input-black-width180 charge-email-1" type="text" placeholder="邮箱">\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="w1" class="check-item charge-good-1" />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="w1">物品放行权限</label>\
										</div>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="b1" class="check-item charge-bill-1" />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="b1">账单推送</label>\
										</div>\
									</div>\
									<div class="leader-second leader">\
										<span class="tips">负责人2</span>\
										<input class="input-black-width180 charge-name-2" type="text" placeholder="姓名">\
										<input class="input-black-width180 charge-mobile-2" type="text" placeholder="电话">\
										<input class="input-black-width180 charge-email-2" type="text" placeholder="邮箱">\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="w2" class="check-item charge-good-2" />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="w2">物品放行权限</label>\
										</div>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="b2" class="check-item charge-bill-2" />\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="b2">账单推送</label>\
										</div>\
									</div>\
									<div class="enterprise-btns">\
										<button class="btn-big-red paper-change-btn ">确定添加</button>\
										<button class="btn-big-black paper-cancel-btn ">取消</button>\
									</div>\
								</div>\
							</div>\
						</div>',
				"updateDialog": '<div class="dialog-wp"> \
					<div class="mask"></div>\
					<div class="dialog dialog-enterprise-con">\
						<div class="title-wp">\
							<span>编辑企业</span>\
							<span class="close-btn"></button>\
						</div>\
						<div class="dialog-enterprise-wp">\
							<div class="top-title">\
								<span class="left-line"></span>\
								<span class="title">企业信息</span>	\
								<span class="right-line"></span>\
							</div>\
							<div class="floors-wp clearfloat">\
								<div class="choose-floors">\
									<span class="tips">楼宇</span>\
									<select class="select-width180 build-org">\
										<option value="10">尚美科技大厦</option>\
									</select>\
								</div>\
							<div class="choose-floors">\
								<span class="tips">入驻时间</span>\
								<input class="input-black-width180 enter-time" id="enterTime" type="text" placeholder="请选择" value="<%=data.virInfoEnterTime%>" readonly/>\
							</div>\
								<div class="choose-room clearfloat">\
									<span class="tips">楼层房间号</span>\
									<select class="select-width100 floors-select">\
										<option value="">楼层</option>\
										<% for(var i=0;i<floorList.length;i++){%>\
											<option value="<%=floorList[i].id %>"><%=floorList[i].name%></option>\
										<%} %>\
									</select>\
									<div class="rooms-select">\
										<div class="rooms-select-btn">房间号</div>\
										<ul class="room-list">\
										</ul>\
									</div> \
									<div class="select-room-wp clearfloat">\
										<% for(var i=0;i<data.mapList.length;i++){ %>\
											<span class="select-room" data-roomid="<%=data.mapList[i].roomId%>" data-roomname="<%=data.mapList[i].roomName%>" data-floorid="<%=data.mapList[i].floorId%>" data-floorname="<%=data.mapList[i].floorName%>"><%=data.mapList[i].floorName%>楼<%=data.mapList[i].roomName%><span class="del-select-btn" title="删除">×</span></span>\
										<% } %>\
									</div>\
								</div>\
							</div>\
							<div class="enterprise-info-wp clearfloat">\
								<div class="enter-wp">	\
									<span class="tips">企业名称</span>\
									<input class="input-black-width180 enterprise-name" data-creator="<%=data.virInfo.creator%>" data-createtime = "<%=data.virInfo.createTime%>" data-isenabled="<%=data.virInfo.isEnabled%>"  value="<%=data.virInfo.name%>" type="text" placeholder="请输入该公司名称">\
								</div>\
								<div class="enter-wp">	\
									<span class="tips">公司编号</span>\
									<input class="input-black-width180 enterprise-code" value="<%=data.virInfo.customerNumber%>" type="text" placeholder="请输入该公司编号">\
								</div>\
								<div class="enter-wp">	\
									<span class="tips">月度免费时长</span>\
									<input class="input-black-width180 enterprise-freeLenTime" value="<%=data.virInfo.freeLenTime%>" type="text" placeholder="请输入月度免费时长">\
								</div>\
								<div class="enter-wp">	\
									<span class="tips">月度剩余时长</span>\
									<input class="input-black-width180 enterprise-remainderTime" value="<%=data.virInfo.remainderTime%>" type="text" placeholder="请输入月度剩余时长">\
								</div>\
								<div class="enter-wp">	\
									<span class="tips">备注</span>\
									<input class="input-black-width420 enterprise-remark" value="<%=data.virInfo.remark%>" type="text" placeholder="备注">\
								</div>\
							</div>\
						   <div class="enterprise-file-wp clearfloat">\
								<div class="e-f-wp e-business-license <%if(data.virInfo.businessImageUrl){%> no-active <%}%>">\
									<div class="del-btn" ></div>\
									<input type="file" class="file-btn">\
									<input type="hidden" id="business" name="serviceIcon"  data-img="<%if(data.virInfo.businessImageUrl){%><%=data.virInfo.businessImageUrl%><%}%>"/>\
									<div class="img-wp">\
										<% if(data.virInfo.businessImageUrl){ %>\
											<img src="<%=data.businessImageUrl%>" />\
										<%}%>\
									</div>\
								</div>\
								<div class="e-f-wp e-certificate <%if(data.virInfo.powerAttorneyImageUrl){%> no-active <%}%>">\
									<div class="del-btn"></div>\
									<input type="file" class="file-btn">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%if(data.virInfo.powerAttorneyImageUrl){%><%=data.virInfo.powerAttorneyImageUrl%><%}%>"/>\
									<div class="img-wp">\
										<% if(data.virInfo.powerAttorneyImageUrl){ %>\
											<img src="<%=data.attorneyImageUrl%>" />\
										<%}%>\
									</div>\
								</div>\
								<div class="e-f-wp e-id-facade <%if(data.virInfo.powerFaceImageUrl){%> no-active <%}%>">\
									<div class="del-btn"></div>\
									<input type="file" class="file-btn">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%if(data.virInfo.powerFaceImageUrl){%><%=data.virInfo.powerFaceImageUrl%><%}%>"/>\
									<div class="img-wp">\
										<% if(data.virInfo.powerFaceImageUrl){ %>\
											<img src="<%=data.faceImageUrl%>" />\
										<%}%>\
									</div>\
								</div>\
								<div class="e-f-wp e-id-back <%if(data.virInfo.powerNationImageUrl){%> no-active <%}%>">\
									<div class="del-btn"></div>\
									<input type="file" class="file-btn">\
									<input type="hidden" id="business" name="serviceIcon" data-img="<%if(data.virInfo.powerNationImageUrl){%><%=data.virInfo.powerNationImageUrl%><%}%>"/>\
									<div class="img-wp">\
										<% if(data.virInfo.powerNationImageUrl){ %>\
											<img src="<%=data.nationImageUrl%>" />\
										<%}%>\
									</div>\
								</div>\
							</div>	\
							<div class="choose-list-wp">\
								<span class="tips">企业在租状态</span>\
								<div class="radio-wp">\
								   <span class="radio-input">\
									 <input type="radio" id="zu" class="radio-item enterprise-rent" data-status="1" name="status" <%if(data.virInfo.leaseStatus==1){%>checked<%}%>/>\
									  <span class="radio-inner"></span>\
								   </span>		\
								   <label class="radio-con" for="zu">在租</label>\
								</div>\
								<div class="radio-wp">\
								   <span class="radio-input">\
									 <input type="radio" id="qian" class="radio-item enterprise-move" data-status="0" name="status" <%if(data.virInfo.leaseStatus==0){%>checked<%}%>/>\
									  <span class="radio-inner"></span>\
								   </span>		\
								   <label class="radio-con" for="qian">已迁出</label>\
								</div>\
								<span class="bill-tips tips">账单推送方式</span>\
								<div class="checkbox-wp">\
								   <span class="checkbox-input">\
									 <input type="checkbox" id="wx" class="check-item enterprise-wx" <%if(data.virInfo.isWechat==1){%>checked<%}%>/>\
									  <span class="checkbox-inner"></span>\
								   </span>		\
								   <label class="checkbox-con" for="wx">微信</label>\
								</div>\
								<div class="checkbox-wp">\
								   <span class="checkbox-input">\
									 <input type="checkbox" id="email" class="check-item enterprise-email"  <%if(data.virInfo.isEmail==1){%>checked<%}%>//>\
									  <span class="checkbox-inner"></span>\
								   </span>		\
								   <label class="checkbox-con" for="email">邮箱</label>\
								</div>\
								<div class="checkbox-wp">\
								   <span class="checkbox-input">\
									 <input type="checkbox" id="msg" class="check-item enterprise-msg" <%if(data.virInfo.isMessage==1){%>checked<%}%>//>\
									  <span class="checkbox-inner"></span>\
								   </span>		\
								   <label class="checkbox-con" for="msg">短信</label>\
								</div>\
							</div>\
							<div class="top-title">\
								<span class="left-line"></span>\
								<span class="title">负责人信息</span>	\
								<span class="right-line"></span>\
							</div>\
							<% if(data.appUserList.length>1 ){%>\
								<% for(var i=0;i<data.appUserList.length;i++){ %>\
									<div class="leader-first <% if(i==1){%> leader <%} %>">\
										<span class="tips">负责人<%=i+1%></span>\
										<input class="input-black-width180 charge-name-<%=i+1%>" data-id="<%=data.appUserList[i].id %>" type="text" data-creator="<%=data.appUserList[i].creator%>" data-createtime = "<%=data.appUserList[i].createTime%>" data-isenabled="<%=data.appUserList[i].isEnabled%>" data-isresponsible="<%= data.appUserList[i].isResponsible %>" value="<%=data.appUserList[i].userName %>" placeholder="姓名">\
										<input class="input-black-width180 charge-mobile-<%=i+1%>" type="text" value="<%=data.appUserList[i].userMobile %>" placeholder="电话">\
										<input class="input-black-width180 charge-email-<%=i+1%>" type="text" value="<%=data.appUserList[i].email %>" placeholder="邮箱">\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="w<%=i+1%>" class="check-item charge-good-<%=i+1%>" <% if(data.appUserList[i].isReleasePower==1){ %> checked <%} %>/>\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="w<%=i+1%>">物品放行权限</label>\
										</div>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="b<%=i+1%>" class="check-item charge-bill-<%=i+1%>"  <% if(data.appUserList[i].isPushPower==1){ %> checked <%} %>/>\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="b<%=i+1%>">账单推送</label>\
										</div>\
									</div>\
								<% } %>\
							<%}else if(data.appUserList.length ==0){ %>\
								<div class="leader-first">\
									<span class="tips">负责人1</span>\
									<input class="input-black-width180 charge-name-1" type="text" placeholder="姓名">\
									<input class="input-black-width180 charge-mobile-1" type="text" placeholder="电话">\
									<input class="input-black-width180 charge-email-1" type="text" placeholder="邮箱">\
									<div class="checkbox-wp">\
									   <span class="checkbox-input">\
										 <input type="checkbox" id="w1" class="check-item charge-good-1" />\
										  <span class="checkbox-inner"></span>\
									   </span>		\
									   <label class="checkbox-con" for="w1">物品放行权限</label>\
									</div>\
									<div class="checkbox-wp">\
									   <span class="checkbox-input">\
										 <input type="checkbox" id="b1" class="check-item charge-bill-1" />\
										  <span class="checkbox-inner"></span>\
									   </span>		\
									   <label class="checkbox-con" for="b1">账单推送</label>\
									</div>\
								</div>\
								<div class="leader-second leader">\
									<span class="tips">负责人2</span>\
									<input class="input-black-width180 charge-name-2" type="text" placeholder="姓名">\
									<input class="input-black-width180 charge-mobile-2" type="text" placeholder="电话">\
									<input class="input-black-width180 charge-email-2" type="text" placeholder="邮箱">\
									<div class="checkbox-wp">\
									   <span class="checkbox-input">\
										 <input type="checkbox" id="w2" class="check-item charge-good-2" />\
										  <span class="checkbox-inner"></span>\
									   </span>		\
									   <label class="checkbox-con" for="w2">物品放行权限</label>\
									</div>\
									<div class="checkbox-wp">\
									   <span class="checkbox-input">\
										 <input type="checkbox" id="b2" class="check-item charge-bill-2" />\
										  <span class="checkbox-inner"></span>\
									   </span>		\
									   <label class="checkbox-con" for="b2">账单推送</label>\
									</div>\
								</div>\
							<% }else if(data.appUserList.length ==1){ %>\
								<% for(var i=0;i<data.appUserList.length;i++){ %>\
									<div class="leader-first <% if(i==1){%> leader <%} %>">\
										<span class="tips">负责人<%=i+1%></span>\
										<input class="input-black-width180 charge-name-<%=i+1%>" data-id="<%=data.appUserList[i].id %>" data-creator="<%=data.appUserList[i].creator%>" data-createtime = "<%=data.appUserList[i].createTime%>" data-isenabled="<%=data.appUserList[i].isEnabled%>"  data-isresponsible="<%= data.appUserList[i].isResponsible %>" value="<%=data.appUserList[i].userName %>" type="text" value="<%=data.appUserList[i].userName %>" placeholder="姓名">\
										<input class="input-black-width180 charge-mobile-<%=i+1%>" type="text" value="<%=data.appUserList[i].userMobile %>" placeholder="电话">\
										<input class="input-black-width180 charge-email-<%=i+1%>" type="text" value="<%=data.appUserList[i].email %>" placeholder="邮箱">\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="w<%=i+1%>" class="check-item charge-good-<%=i+1%>" <% if(data.appUserList[i].isReleasePower==1){ %> checked <%} %>/>\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="w<%=i+1%>">物品放行权限</label>\
										</div>\
										<div class="checkbox-wp">\
										   <span class="checkbox-input">\
											 <input type="checkbox" id="b<%=i+1%>" class="check-item charge-bill-<%=i+1%>"  <% if(data.appUserList[i].isPushPower==1){ %> checked <%} %>/>\
											  <span class="checkbox-inner"></span>\
										   </span>		\
										   <label class="checkbox-con" for="b<%=i+1%>">账单推送</label>\
										</div>\
									</div>\
								<% } %>\
								<div class="leader-second leader">\
									<span class="tips">负责人2</span>\
									<input class="input-black-width180 charge-name-2" type="text" placeholder="姓名">\
									<input class="input-black-width180 charge-mobile-2" type="text" placeholder="电话">\
									<input class="input-black-width180 charge-email-2" type="text" placeholder="邮箱">\
									<div class="checkbox-wp">\
									   <span class="checkbox-input">\
										 <input type="checkbox" id="w2" class="check-item charge-good-2" />\
										  <span class="checkbox-inner"></span>\
									   </span>		\
									   <label class="checkbox-con" for="w2">物品放行权限</label>\
									</div>\
									<div class="checkbox-wp">\
									   <span class="checkbox-input">\
										 <input type="checkbox" id="b2" class="check-item charge-bill-2" />\
										  <span class="checkbox-inner"></span>\
									   </span>		\
									   <label class="checkbox-con" for="b2">账单推送</label>\
									</div>\
								</div>\
							<% } %>\
							<div class="enterprise-btns">\
								<button class="btn-big-red paper-change-btn ">确定添加</button>\
								<button class="btn-big-black paper-cancel-btn ">取消</button>\
							</div>\
						</div>\
					</div>\
				</div>',
			"roomList": '<option value="">选择房间号</option><% for(var i=0;i<roomList.length;i++){%>\
					<option value="<%=roomList[i].roomInfo.id%>"><%=roomList[i].roomInfo.name%></option>\
				<%}%>'	,
		  "roomItem": '<% for(var i=0;i<list.length;i++){ %>\
			  			<li class="room-item <%if(selectArr.indexOf(list[i].roomInfo.id)!=-1){%> select <%}%> <%if(list[i].isLess == 1 && selectArr.indexOf(list[i].roomInfo.id)==-1){%> disabled <%}%>"  data-roomid="<%=list[i].roomInfo.id %>" data-roomname="<%=list[i].roomInfo.name %>" data-floorid="<%=floorId %>" data-floorname="<%=floorName%>" ><%=list[i].roomInfo.name %></li>\
			  	<% } %>'	,
	      "selectRoom": '<% for(var i=0;i<selectArr.length;i++){ %>\
	    	  	<span class="select-room" data-roomid="<%=selectArr[i].roomId %>" data-roomname="<%=selectArr[i].roomName %>" data-floorid="<%=selectArr[i].floorId %>" data-floorname="<%=selectArr[i].floorName%>"><%= selectArr[i].floorName %>楼<%= selectArr[i].roomName %><span class="del-select-btn" title="删除">×</span></span>\
	    	 <% } %> \
	    	  ',
	    	  "floorsTpl":	  '<option value="">选择楼层</option><% for(var i=0;i<floorList.length;i++){%>\
					<option value="<%=floorList[i].id%>"><%=floorList[i].name%></option>\
					<%}%>'	
	    	  
	   };
	var layer;
	var table;
	layui.use('layer', function(){
		   layer = layui.layer;  
	}); 
	var enterprise = {
		init: function(){
			this.render();
			this.bindEvent();
		},
		render: function(){
			var _this = this;
//			_this.fnCheck("#checkAll","input[name='chkBtn']");
			//渲染楼层列表
			_this.renderFloor(10);
			//渲染table
			-this.renderTable();
		},
		bindEvent: function(){
			var _this = this;
			var $checkBtn = $(".check-btn");
			var $editBtn = $(".edit-btn");
			var $addEnterpriseBtn = $(".add-enterprise-btn");
			//查询
			$("#conditionform input[type='text']").on("keydown",function(event){
				if(event.keyCode == 13){
					$("#conditionform .search-btn").click();
				}
			});
			
			//重置
			$(".reset-btn").on("click",function(){
				$("#conditionform").find("select").val("");
				$("#conditionform").find("input").val("");
				$("#conditionform .room-select").html($("<option value=''>选择房间号</option>"))
			})
			//下载模板
			$(".download-btn").on("click",function(){
				location.href=$("#contextPath").val()+"/upload/VirtualArch.xlsx";
			});
			//导入
			$("#excelFile").on("change",function(){
				_this.exportFile();
			});
		   //添加企业
			$addEnterpriseBtn.on("click",function(){
				_this.ajaxFloors('add',10,[]);
				//请求楼层
			})
		},
		/**
		 * 渲染table
		 */
		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()+ "/admin/virtual/getVirTualArchList"
				    ,cols: [[
				      {
			    		   field:'orgName', 
			    		   title: '楼宇', 
			    		   width:200
			    	  },{
			    		  field:'floorNames',
			    		  title: '楼层',
			    		  width:200
		    		  },{
		    			  field:'roomNames', 
		    			  title: '房间号', 
		    			  width:200
	    			  },{
	    				  field:'customerNumber', 
	    				  title: '企业编号', 
	    				  width:120
	  				  },{
	  					  field:'virName', 
	  					  title: '公司名',
	  					  width: 200
//	  					  templet: function(data){
//	  						  if(data.state == 0){
//	  							  return "<span class='red'>未审核<span>"
//	  						  }else if(data.state == 1){
//	  							  return '已发布'
//	  						  }else if(data.state == 2){
//	  							  return '已驳回'
//	  						  }else if(data.state ==3){
//	  							  return '原文链接'
//	  						  } 
//	  					  }
	  				  },{
	  					  field:'id', 
	  					  title: '账单推送', 
	  					  width: 180,
	  					  templet: function(data){
	  						  var str = '';
	  						  if(data.isEmail==1){
	  							  str+= '邮件,'
	  						  };
	  						  if(data.isWechat==1){
	  							  str+='微信,'
	  						  };
	  						  if(data.isMessage==1){
	  							  str+='短信,'
	  						  };
	  						  return str.substring(0, str.length-1);
	  					  }
					  },{
						  field:'leaseStatus', 
						  title: '在租状态', 
						  width:200,
						  templet: function(data){
							if(data.leaseStatus==0){
								return '已迁出';
							}else{
								return '在租'
							}	
						  }
					  },{
	  					  field:'enterTime', 
	  					  title: '入驻时间', 
	  					  width:120
					  },{
	  					  field:'userName1', 
	  					  title: '负责人1姓名', 
	  					  width:120
					  },{
	  					  field:'userTel1', 
	  					  title: '负责人1手机', 
	  					  width:120
					  },{
	  					  field:'userEmail1', 
	  					  title: '负责人1邮箱', 
	  					  width:120
					  },{
	  					  field:'userName1', 
	  					  title: '负责人1放行权限', 
	  					  width: 180,
	  					  templet: function(data){
							if(data.userName1){
								if(data.isReleasePower1==1){
									return '有权限'
								}else{
									return '无权限'
								}
							}else{
								return '';
							}
						  }
					  },{
	  					  field:'userName1', 
	  					  title: '负责人1推送权限', 
	  					  width:180,
	  					  templet: function(data){
							if(data.userName1){
								if(data.isPushPower1==1){
									return '有权限'
								}else{
									return '无权限'
								}
							}else{
								return '';
							}
						  }
					  },{
	  					  field:'userName2', 
	  					  title: '负责人2姓名', 
	  					  width:120
					  },{
	  					  field:'userTel2', 
	  					  title: '负责人2手机', 
	  					  width:120
					  },{
	  					  field:'userEmail2', 
	  					  title: '负责人2邮箱', 
	  					  width:120
					  },{
	  					  field:'userName2', 
	  					  title: '负责人2放行权限', 
	  					  width:180,
	  					  templet: function(data){
							if(data.userName2){
								if(data.isReleasePower1==1){
									return '有权限'
								}else{
									return '无权限'
								}
							}else{
								return '';
							}
						  }
					  },{
	  					  field:'userName2', 
	  					  title: '负责人2推送权限', 
	  					  width:180,
	  					  templet: function(data){
							if(data.userName2){
								if(data.isPushPower2==1){
									return '有权限'
								}else{
									return '无权限'
								}
							}else{
								return '';
							}
						  }
					  },{
	  					  field:'freeLenTime', 
	  					  title: '月度免费时长', 
	  					  width:120
					  },{
	  					  field:'remainderTime', 
	  					  title: '剩余免费时长', 
	  					  width:120
					  },{
	  					  field:'remark', 
	  					  title: '备注', 
	  					  width:120
					  },{
	  					  field:'id', 
	  					  title: '证件', 
	  					  width:120,
	  					  fixed: 'right', 
	  					  templet: function(data){
	  						return "<span data-id="+data.id+" class='check-blue-btn'>查看证件<span>"
	  					  }
					  },{
						  field:'id', 
						  title: '操作', 
						  width: 120,
						  fixed: 'right', 
						  templet: function(data){
							  var str = '';
							  if (permEdit == 1){
							    str += '<button class="t-btn t-red-btn t-publish-btn" data-id='+data.id+' data-type="1">编辑</button>';
                              }
                              if (permDelete == 1){
                                  str += '<button class="t-btn t-white-btn t-reject-btn" data-id='+data.id+' data-type="2">删除</button>';
							  }
  								return str;
						  }
					  }
					  ]]
					    ,id: 'testReload'	
					    ,page: true,
					    where: {
					    		floorId: $(".floor-select").val(),
					    		roomId: $(".room-select").val(),
					    		isZuStatus: $(".zu-status-select").val(),
					    		virName: $(".virname-text").val()
					    	},
					    response: {
					    	  statusName: 'code' //数据状态的字段名称，默认：code
					    	  ,statusCode: 200 //成功的状态码，默认：0
					    	  ,countName: "count"//数据总数的字段名称，默认：count
					    	  ,dataName: "data" //数据列表的字段名称，默认：data
					    	}   ,
					    done: function(res, curr, count){
					        //如果是异步请求数据方式，res即为你接口返回的信息。
					        $(".check-blue-btn").on("click",function(){
					        	var id = $(this).data("id")
					  
					        	//查看证件
					        	_this.ajaxEnterprisefile(id,_this.uploadImg.bind(_this));	
					        });
					        //删除
					        $(".t-reject-btn").on("click",function(){
					        	var id = $(this).data("id");
								_this.ajaxDelEnterprise(id);
					        });
					        //编辑
					        $(".t-publish-btn").on("click",function(){
					        	var id = $(this).data("id");
					        	_this.ajaxEnterpriseDetail(id);
					        });
					      }
				  });
				  //查询
				  $('#conditionform  .search-btn').on('click', function(){
					  table.reload('testReload', {
						  where: { //设定异步数据接口的额外参数，任意设
							  floorId: $(".floor-select").val(),
					    		roomId: $(".room-select").val(),
					    		isZuStatus: $(".zu-status-select").val(),
					    		virName: $(".virname-text").val()
						  }
						  ,page: {
						    curr: 1 //重新从第 1 页开始
						  }
					}); 
				  });
				});
		},
		//导入企业
		exportFile: function(){
			var _this = this;
			var fileName=$("#excelFile").val();
			var extension=fileName.substring(fileName.lastIndexOf(".")+1,fileName.length);
			if(extension=="xlsx"){
				if(fileName == null || fileName == ""){
					layer.alert("数据导入为空,请按照模板填写资料后再导入!");
					return;
				}
				//2018-08-28  lmz  首先判断该项目下楼宇有多少个，如果是单个的，就传单个的id,如果是多个，就弹窗让用户选择楼宇，选完了之后再弹出让其选择导入的文件
				 $.ajaxFileUpload
		         (
		             {
		            	 //url: $("#contextPath").val()+ "/admin/virtual/importVirtualArchData", //用于文件上传的服务器端请求地址
		                 url: $("#contextPath").val()+ "/admin/virtual/importVirtualInfo", //用于文件上传的服务器端请求地址
		                 secureuri: false, //是否需要安全协议，一般设置为false
		                 fileElementId: 'excelFile', //文件上传域的ID
		                 dataType: 'json', //返回值类型 一般设置为json
		                 data:{
		                	 buildId:'613'
		                 },
		                 success: function (data, status)  //服务器成功响应处理函数
		                 {
		                	$("#excelFile").on("change",function(){
		         				_this.exportFile();
		         			});
		                     if (data.code == '200') {
		                    	 table.reload('testReload', {
		   						  where: { //设定异步数据接口的额外参数，任意设
		   							  floorId: $(".floor-select").val(),
		   					    		roomId: $(".room-select").val(),
		   					    		isZuStatus: $(".zu-status-select").val(),
		   					    		virName: $(".virname-text").val()
		   						  }
		   						  ,page: {
		   						    curr: 1 //重新从第 1 页开始
		   						  }
		   					}); 
		                     } else {
		                    	 layer.alert(data.msg);
		                     }
		                 }
		             }
		         )		
			}
			else{
				alert("请上传xlsx格式的文件");
			}
		},
		/*
		 * 请求房间信息 
		 * @param floorId
		 * @param $dom
		 * @param type
		 * @param floorName 
		 * @patam selectArr
		 */
		ajaxRoomList: function(floorId,$dom,type,floorName,selectArr){
			var _this = this;
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/room/getRoomList", 
				   data: {
					   floorId: floorId
				   },
				   success: function(data){
					   var data = JSON.parse(data);
					   if(data.code == '200'){
						   if(type !=2){
							   $dom.html(template.render(tpl.roomList)({roomList: data.data}));
						   }else{
							   
							   $dom.html(template.render(tpl.roomItem)({ list:  data.data, floorName: floorName, floorId: floorId,selectArr: _this.toNumArr(selectArr)}));
							   console.log( _this.toNumArr(selectArr))
							   $(".room-item:not(.disabled)").on("click",function(){
								   var $this = $(this);
								   if($this.hasClass("select")){
									   $this.removeClass("select");
									   _this.delSelectRoom($this.data("roomid"),selectArr);
								   }else{
									   $this.addClass("select");
									   selectArr.push({
											"floorId": $this.data("floorid"),
											"floorName":  $this.data("floorname"),
											"roomId":  $this.data("roomid"),
											"roomName":  $this.data("roomname")
									   });
									   $(".select-room-wp").html(template.render(tpl.selectRoom)({selectArr: selectArr}));
									    $(".del-select-btn").on("click",function(){
									    	var $this = $(this)
									    	_this.delSelectRoom($this.closest(".select-room").data("roomid"),selectArr);
											$(this).closest(".select-room").remove();
											
											
											 //$(".select-room-wp").html(template.render(tpl.selectRoom)({selectArr: selectArr}));
										})
								   }
							   })
						   }
						  
//						   _this.renderRoomDialog(floorId);
						   //$("#conditionform").submit();
					   }   
				   },
				   error: function(){   
				   }
			   });
		},
		/**
		 * 把选中的数组对象转换成id的数组
		 * @param selectArr
		 */
		toNumArr: function(selectArr){
			var arr = [];
			for(var i = 0;i<selectArr.length;i++){
				arr.push(+selectArr[i].roomId);
			};
			return arr;
		},
		/**
		 * 删除选中房间
		 * @param roomId
		 * @param selectaRR
		 */
		delSelectRoom: function(roomId,selectArr){
			var _this = this;
			var index ;
			for(var i=0;i<selectArr.length;i++){
				if(roomId == selectArr[i].roomId){
					index = i;
				}
			};
			if(!isNaN(index)){
				selectArr.splice(index,1);
				$(".select-room-wp").html(template.render(tpl.selectRoom)({selectArr: selectArr}));
				$(".room-item").each(function(index,ele){
					if($(ele).data("roomid") == roomId){
						$(ele).removeClass("select");
					}
				})
				
				$(".del-select-btn").on("click",function(){
					var $this = $(this);
					_this.delSelectRoom($this.closest(".select-room").data("roomid"),selectArr);
					$(this).closest(".select-room").remove();
					
//					 $(".select-room-wp").html(template.render(tpl.selectRoom)({selectArr: selectArr}));
				})
			}
			
		},
		
		/**
		 * 导入excel
		 * @param fileName
		 */
		ajaxExportFile: function(fileName){
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/virtual/importVirtualArchData", 
				   data: {
					   "MultipartFile excelFile": fileName
				   },
				   success: function(data){
					   var data = JSON.parse(data);
					   if(data.code == '200'){
						   $(".room-select").html(template.render(tpl.roomList)({roomList: data.data}));
//						   _this.renderRoomDialog(floorId);
						   //$("#conditionform").submit();
					   }   
				   },
				   error: function(){   
				   }
			   });
		},
		/**
		 * 获取企业详情
		 * @param id
		 */
		ajaxEnterpriseDetail: function(id){
			var _this = this;
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/virtual/getVirtualById", 
				   data: {
					   "virId": id
				   },
				   success: function(data){
					   var data = JSON.parse(data);
					   if(data.code == '200'){
//						   console.log(data.data);
						   
						   _this.ajaxFloors('update',10,data.data.mapList,data.data,id);
//						   $(".room-select").html(template.render(tpl.roomList)({roomList: data.data}));
//						   _this.renderRoomDialog(floorId);
						   //$("#conditionform").submit();
					   } else{
						   layer.alert(data.msg);
					   }  
				   },
				   error: function(){   
				   }
			   });
		},

		/**
		 * 上传图片
		 * @param $dom 上传按钮
		 * @param $imgWp 图片容器
		 * @param $base64Wp 存放base64得input
		 * @param callback 回调
		 */
		selectFileImage:function ($dom,$imgWp,$base64Wp ,callback) {
			
			var file = $dom[0].files[0];
			var Orientation = null;
			$dom.val("");//上传传按钮
			if (file) {
				console.log("正在上传,请稍后...");
				var rFilter = /^(image\/jpeg|image\/png)$/i; // 检查图片格式
				if (!rFilter.test(file.type)) {
					layer.msg('图片格式有误，请上传(jpeg,png)');
					return;
				}
				EXIF.getData(file, function() {
					EXIF.getAllTags(this);
					Orientation = EXIF.getTag(this, 'Orientation');
				});

				var oReader = new FileReader();
				oReader.onload = function(e) {
					var image = new Image();
					image.src = e.target.result;
					image.onload = function() {
						var expectWidth = this.naturalWidth;
						var expectHeight = this.naturalHeight;

						if (this.naturalWidth > this.naturalHeight
								&& this.naturalWidth > 800) {
							expectWidth = 800;
							expectHeight = expectWidth * this.naturalHeight
									/ this.naturalWidth;
						} else if (this.naturalHeight > this.naturalWidth
								&& this.naturalHeight > 1200) {
							expectHeight = 1200;
							expectWidth = expectHeight * this.naturalWidth
									/ this.naturalHeight;
						}
						var canvas = document.createElement("canvas");
						var ctx = canvas.getContext("2d");
						canvas.width = expectWidth;
						canvas.height = expectHeight;
						ctx.drawImage(this, 0, 0, expectWidth, expectHeight);
						var base64 = null;
						var clearBase64 = null;
//						var mpImg = new MegaPixImage(image);
//						mpImg.render(canvas, {
//							maxWidth : 800,
//							maxHeight : 1200,
//							quality : 0.6,
//							orientation : Orientation
//						});
						base64 = canvas.toDataURL("image/png", 2);
						if (base64 != null) {
							clearBase64 = base64.substr(base64.indexOf(',') + 1)
						}
//						$imgWp.html("<div class='img' style='background-image: url('"+base64+"')'></div>");
						$imgWp.html("<img src='"+base64+"' alt='' />");//图片容器
						$base64Wp.val(clearBase64);//存放base64得
//						if($("#id").val()!=""){我自己注释的
//							$("#actype").val("1");
//						}
						callback(base64);
					};
				};
				oReader.readAsDataURL(file);
			}
		},
		/*
		 * 证件重新上传
		 * 
		 */
		uploadImg: function(){
			var _this = this;
			$(".paper-item .c-file-btn").on("change",function(){
				var $this = $(this);
				var $imgWp = $(this).closest(".paper-item").find(".p-img-wp");
				var $base64Wp = $(this).closest(".paper-item").find("#business");
				
//				 * @param $imgWp 图片容器
//				 * @param $base64Wp 存放base64得input
//				 * @param callback 回调
				_this.selectFileImage($this,$imgWp,$base64Wp,function(base64){
					$(".dialog .p-img-wp img").zoomify();
					_this.ajaxUploadImg(base64,$this.closest(".paper-item"))
				})
			})
		},
		/**
		 * 上传图片
		 * @param base64
		 * @param $$item
		 */
		ajaxUploadImg: function(base64,$item){
			var _this = this;
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/virtual/getAttMagePath", 
				   data: {
					   "serviceIcon": base64
				   },
				   success: function(data){
					   var result = JSON.parse(data);
					   if(result.code == '200'){
						   $item.find("#business").data("img",result.data.path);
					   	   $item.addClass("no-active");	
//						   $("#conditionform").submit();
					   }   
				   },
				   error: function(){   
				   }
			   });
		},
		/**
		 * 获取楼层列表
		 * @param type
		 * @param orgid
		 * @param selectArr
		 * @param data 详情所有数据
		 * @param id 企业id
		 */
		ajaxFloors: function(type,orgid,selectArr,detail,id){
			var selectArr = selectArr;
			var  _this = this;
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/floor/getFloorList", 
				   data: {
					   "orgId": orgid
				   },
				   success: function(data){
					   var result = JSON.parse(data);
					   if(result.code == '200'){
						 //显示弹窗
						    if(type == 'update'){
						    	if(detail.appUserList.length==1 && detail.appUserList[0].reOrder !=1){
						    		var appList = [];
						    		for(var i=0;i<detail.appUserList.length;i++){
						    			appList.push({userName: '',userMobile: '',reOrder: 1,email: '',isPushPower: 0,isReleasePower:0});
						    			appList.push(detail.appUserList[0])
						    		};
						    		detail.appUserList = appList;
						    	}
						    	$("body").append(template.render(tpl.updateDialog)({floorList: result.data,data: detail }));
						    	layui.use('laydate', function(){
									  var laydate = layui.laydate;
									  //执行一个laydate实例
									  laydate.render({
									    elem: '#enterTime' //提交开始时间
									  });
								});
//						    	$(".e-f-wp .del-btn").on("click",function(){debugger
//						    		var $this = $(this);
//						    		
//						    	});
						    	_this.delUploadImg($(".e-f-wp"));
						    	$(".del-select-btn").on("click",function(){
									 var $this = $(this)
									 _this.delSelectRoom($this.closest(".select-room").data("roomid"),selectArr);
									$(this).closest(".select-room").remove();
								})
						    	
						    }else{
						    	layui.use('laydate', function(){
									  var laydate = layui.laydate;
									  //执行一个laydate实例
									  laydate.render({
									    elem: '#enterTime' //提交开始时间
									  });
									});
						    	$("body").append(template.render(tpl.addDialog)({floorList: result.data}));
						    }
							
							//关闭弹窗
							$(".close-btn").on("click",function(){
								$(".dialog-wp").remove();
							});
							//判断编码是否唯一
							$(".enterprise-code").on("blur",function(){
								var val = $(this).val();
//								var id = $("").data("id");
								_this.ajaxCode(val,id);
							})
							//通过楼层删选房间
							$(".floors-select").on("change",function(){
								var floorId = $(this).val();
								var floorName = $(".floors-select option:selected").text();
								if(!floorId){
									$(".room-list").hide();
//									$(".room-list").html($("<option value=''>房间号</option>"))
								}else{
									 $(".select-room-wp").html(template.render(tpl.selectRoom)({selectArr: selectArr}))
									//$(".room-list").show();
									 $(".del-select-btn").on("click",function(){
										 var $this = $(this)
										 _this.delSelectRoom($this.closest(".select-room").data("roomid"),selectArr);
										$(this).closest(".select-room").remove();
										
										
										 //$(".select-room-wp").html(template.render(tpl.selectRoom)({selectArr: selectArr}));
									})
									_this.ajaxRoomList(floorId,$(".room-list"),2,floorName,selectArr);
								}
							});

							 $(".dialog-wp").on("click",function(){
								 if($(".rooms-select").hasClass("active")){
									 $(".rooms-select").removeClass("active");
								 }
							 });
							 $(".rooms-select-btn").on("click",function(event){
								  event.stopPropagation();
								  var $parent = $(this).parent(".rooms-select");
							 		if($(".floors-select").val()){
							 			 if($parent.hasClass("active")){
											   $parent.removeClass("active")
										   }else{
											   $parent.addClass("active") 
										   }
							 		}
							   });
							 $(".room-list").on("click",function(event){
								 event.stopPropagation();
							 })
							
							//上传证件
							$(".dialog .file-btn").on("change",function(){
								var $this = $(this);
								var $item =  $(this).closest(".e-f-wp");
								var $imgWp = $(this).closest(".e-f-wp").find(".img-wp");
								var $base64Wp = $(this).closest(".e-f-wp").find("#business");						
								_this.selectFileImage($this,$imgWp,$base64Wp,function(base64){
									_this.ajaxUploadImg(base64,$item);
									_this.delUploadImg($item)
								})
							});
							
							//确认添加
							$(".paper-change-btn").on("click",function(){
								_this.ajaxAddEnterprise(id);
							});
							//取消
							$(".paper-cancel-btn").on("click",function(){
								$(".dialog-wp").remove();
							});
//						   _this.renderRoomDialog(floorId);
						   //$("#conditionform").submit();
					   }   
				   },
				   error: function(){   
				   }
			   });
		},
		/**
		 * 删除证件
		 * @param $item
		 */
		delUploadImg: function($item){
			var _this  = this;
			$item.find(".del-btn").on("click",function(){
				 $(this).closest(".e-f-wp").find("#business").data("img",'');
				 $(this).closest(".e-f-wp").removeClass("no-active");
				 $(this).closest(".e-f-wp").find(".img-wp").html("");
			})
		},
		/*
		 * 判断code是否唯一
		 * @param code
		 */
		ajaxCode: function(code,id){
			if(code){
				 $.ajax({
					   type: "post",
					   url: $("#contextPath").val()+ "/admin/virtual/getVirByCusNumber", 
					   data: {
						   "cusNumber": code,"virId": !!id ? id : ""
					   },
					   success: function(data){
						   var result = JSON.parse(data);
						   if(result.code == '200'){
							   
						   }else{
							   layer.alert(result.msg);
						   }   
					   },
					   error: function(){   
					   }
				   });
			}
		},
		/*
		 * 确认添加企业
		 */
		ajaxAddEnterprise: function(id){
			var _this = this;
			var enterprise = {
				virtualArchitecture: {
					name: '',
					enterTime :'',
					organizationId: '',
					floorIds: '',
					roomIds: '',
					floorNames: '',
					roomNames: '',
					remark:'',
					customerNumber:'',
					freeLenTime:'',
					remainderTime:'',
					leaseStatus: '',
					isEmail: '',
					isWechat: '',
					isMessage: '',
					businessImageUrl: '',
					powerAttorneyImageUrl: '',
					powerFaceImageUrl: '',
					powerNationImageUrl: '',
					id: id,
					isEnabled: $(".enterprise-name").data("isenabled"),
					creator: $(".enterprise-name").data("creator"),
					createTime: $(".enterprise-name").data("createtime")
				},
				userList: []
			}
			//房间楼层好信息
			var $roomRoom = $(".select-room");
			var floorIds = [];
			var roomIds =[];
			var floorNames = [];
			var roomNames = [];
			//入驻时间
			 var $enterTime = $(".enter-time").val();
				if(!$enterTime){
					alert("请选择入驻时间");
					return false;
			}; 
			enterprise.virtualArchitecture["enterTime"] = $enterTime;
			if(!$roomRoom.length){
				alert("请选择楼层房间信息");
				return false;
			}else{
				$roomRoom.each(function(index,ele){
					var floorId = $(this).data("floorid");
					var floorName = $(this).data("floorname");
					var roomId = $(this).data("roomid");
					var roomName = $(this).data("roomname");
					if(floorIds.indexOf(floorId) == -1){
						floorIds.push(floorId);
					};
					if(roomIds.indexOf(roomId) == -1){
						roomIds.push(roomId);
					}
					if(floorNames.indexOf(floorName) == -1){
						floorNames.push(floorName);
					}
					if(roomNames.indexOf(roomName) == -1){
						roomNames.push(roomName);
					}
				})
			};
			enterprise.virtualArchitecture["organizationId"] = 10;
			enterprise.virtualArchitecture["floorIds"] = floorIds.join(";")+";";
			enterprise.virtualArchitecture["roomIds"] = roomIds.join(";")+";";
			enterprise.virtualArchitecture["floorNames"] = floorNames.join(";")+";";
			enterprise.virtualArchitecture["roomNames"] = roomNames.join(";")+";";
			//公司名称
			var $eName = $(".enterprise-name");
			if(!$eName.val()){
				alert("请输入公司名");
				return false;
			};
			enterprise.virtualArchitecture["name"] = $eName.val();
			//公司编号
			var $eCode = $(".enterprise-code");
			
			if(!$eCode.val()){
				alert("请输入公司编号");
				return false;
			};
			enterprise.virtualArchitecture["customerNumber"] = $eCode.val();
			//免费时长
			var $eTime = $(".enterprise-freeLenTime");
			enterprise.virtualArchitecture["freeLenTime"] = $eTime.val();
			//剩余时长
			var $eRemTime = $(".enterprise-remainderTime");
			enterprise.virtualArchitecture["remainderTime"] = $eRemTime.val();
			//备注
			var $eRemark = $(".enterprise-remark");
			enterprise.virtualArchitecture["remark"] = $eRemark.val();
			//营业执照
			var eBusiness = $(".e-business-license #business").data("img");
			enterprise.virtualArchitecture["businessImageUrl"] = eBusiness;
			//授权书
			var eCert = $(".e-certificate #business").data("img");
			enterprise.virtualArchitecture["powerAttorneyImageUrl"] = eCert;
			//身份证人头
			var eFacade = $(".e-id-facade #business").data("img");
			enterprise.virtualArchitecture["powerFaceImageUrl"] = eFacade;
			
			//身份证国徽
			var eBack = $(".e-id-back #business").data("img");
			enterprise.virtualArchitecture["powerNationImageUrl"] = eBack;
			//在租状态
			var leaseStatus = $(".radio-wp .radio-item:checked").data("status");
			enterprise.virtualArchitecture["leaseStatus"] = leaseStatus;
			//是否微信
			var isWechat = $(".enterprise-wx").is(':checked') ? 1: 0;
			enterprise.virtualArchitecture["isWechat"] = isWechat;
			//是否email
			var isEmail = $(".enterprise-email").is(':checked') ? 1: 0;
			enterprise.virtualArchitecture["isEmail"] = isEmail;
			//是都短息
			var isMessage = $(".enterprise-msg").is(':checked') ? 1: 0;
			enterprise.virtualArchitecture["isMessage"] = isMessage;
			if(!(isWechat|| isEmail || isMessage)){
				alert("请选择账单推送方式");
				return false;
			}
			//负责人1信息
			var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
			var emailReg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
			var $cName1 = $(".charge-name-1");
			if(!$cName1.val()){
				alert("请输入负责人1的姓名")
				return false; 
			};
			var $cMobile1 = $(".charge-mobile-1");
			if(!$cMobile1.val()){
				alert("请输入负责人1的电话")
				return false; 
			}else{
		        if (!myreg.test($cMobile1.val())) {
		        	alert("请输入正确的电话号码")
					return false; 
		       }
			};
			var $eEmail1 = $(".charge-email-1");
			if(!$eEmail1.val() || !emailReg.test($eEmail1.val())){
				alert("请输入正确的负责人1的邮件")
				return false; 
			};
			//负责人2
			var $cName2 = $(".charge-name-2");
			var $cMobile2;
			var $eEmail2;
			
			if(!$cName2.val()){
				if(!($(".charge-good-1").is(':checked') && $(".charge-bill-1").is(':checked'))){
					alert("请勾选物品放行权限和账单推送");
					return false;
				}else{
					
				};
				
			}else{
				$cMobile2 = $(".charge-mobile-2");
				if(!$cMobile2.val()){
					alert("请输入负责人2的电话")
					return false; 
				}else{
			        if (!myreg.test($cMobile2.val())) {
			        	alert("请输入正确的电话号码")
						return false; 
			       }
				};;
				$eEmail2= $(".charge-email-2");
				if(!$eEmail2.val() || !emailReg.test($eEmail2.val())){
					alert("请输入正确的负责人2的邮件")
					return false; 
				};
				if(!($(".charge-good-1").is(':checked') || $(".charge-good-2").is(':checked'))){
					alert("请勾选物品放行权限");
					return false;
				};
				if(!($(".charge-bill-1").is(':checked') || $(".charge-bill-2").is(':checked'))){
					alert("请勾选账单推送");
					return false;
				};
			};
			
			var userName1 = $(".charge-name-1").val(),
			    userMobile1 = $(".charge-mobile-1").val(),
			    email1 = $(".charge-email-1").val(),
			    isPushPower1 = $(".charge-bill-1").is(':checked')? 1: 0,
			    isReleasePower1 =  $(".charge-good-1").is(':checked')? 1: 0
			    reOrder1 = 1;
				id1  = $(".charge-name-1").data("id");
				isEnabled1 =  $(".charge-name-1").data("isenabled"),
				creator1= $(".charge-name-1").data("creator"),
				createTime1= $(".charge-name-1").data("createtime")
				isResponsible1 = $(".charge-name-1").data("isresponsible")
			enterprise.userList.push({
				userName: userName1,
				userMobile : userMobile1,
				email: email1,
				isPushPower: isPushPower1,
				isReleasePower: isReleasePower1,
				reOrder: reOrder1,
				id: id1,
				isEnabled: isEnabled1,
				creator: creator1,
				createTime: createTime1,
				isResponsible: isResponsible1
			});
			if($cName2.val()){
				var userName2 = $(".charge-name-2").val(),
			    userMobile2 = $(".charge-mobile-2").val(),
			    email2 = $(".charge-email-2").val(),
			    isPushPower2 = $(".charge-bill-2").is(':checked')? 1: 0,
			    isReleasePower2 =  $(".charge-good-2").is(':checked')? 1: 0
			    reOrder2 = 2;
				id2 = $(".charge-name-2").data("id");
				isEnabled2 =  $(".charge-name-2").data("isenabled"),
				creator2= $(".charge-name-2").data("creator"),
				createTime2= $(".charge-name-2").data("createtime");
				isResponsible2 = $(".charge-name-2").data("isresponsible")
				enterprise.userList.push({
					userName: userName2,
					userMobile : userMobile2,
					email: email2,
					isPushPower: isPushPower2,
					isReleasePower: isReleasePower2,
					reOrder: reOrder2,
					id: id2,
					isEnabled: isEnabled2,
					creator: creator2,
					createTime: createTime2,
					isResponsible: isResponsible2
				});
			};
//			console.log(enterprise);
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/virtual/saveVirtualArch", 
				   data:JSON.stringify(enterprise),
				   contentType: "application/json",  
			       dataType : 'text',  
				   success: function(data){
					   var result = JSON.parse(data);
					   if(result.code == '200'){
						  
						   table.reload('testReload', {
								  where: { //设定异步数据接口的额外参数，任意设
									  floorId: $(".floor-select").val(),
							    		roomId: $(".room-select").val(),
							    		isZuStatus: $(".zu-status-select").val(),
							    		virName: $(".virname-text").val()
								  }
								  ,page: {
								    curr: 1 //重新从第 1 页开始
								  }
							}); 
						   $(".dialog-wp").remove();
//						   $("#conditionform").submit();
					   } else{
						   layer.alert(result.msg);
					   }  
				   },
				   error: function(){   
				   }
			   });
		},
		/*
		 * 删除企业
		 * @param id
		 */
		ajaxDelEnterprise: function(id){
			var _this = this;
			layer.confirm('确定删除该企业?', {
				  btn: ['确定', '取消'] 
				}, function(index, layero){
					 layer.close(index); //如果设定了yes回调，需进行手工关闭
					 $.ajax({
						   type: "post",
						   url: $("#contextPath").val()+ "/admin/virtual/removeVirInfo", 
						   data: {
							   "virId": id
						   },
						   success: function(data){
							   var result = JSON.parse(data);
							   if(result.code == '200'){
								   table.reload('testReload', {
										  where: { //设定异步数据接口的额外参数，任意设
											  floorId: $(".floor-select").val(),
									    		roomId: $(".room-select").val(),
									    		isZuStatus: $(".zu-status-select").val(),
									    		virName: $(".virname-text").val()
										  }
										  ,page: {
										    curr: 1 //重新从第 1 页开始
										  }
									}); 
							   }   
						   },
						   error: function(){   
						   }
					   });
				}, function(index){
					
				});
		},
		/**
		 * 查看证件
		 * @param id
		 * @param callback
		 */
		ajaxEnterprisefile: function(id,callback){
			var _this = this;
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/virtual/getVirImages", 
				   data: {
					   "virId": id
				   },
				   success: function(data){
					   var result = JSON.parse(data);
					   if(result.code == '200'){
//						   $("#conditionform").submit();
						 //显示弹窗
							$("body").append(template.render(tpl.checkPaper)({data: result.data}));
							//关闭弹窗
							$(".close-btn").on("click",function(){
								$(".dialog-wp").remove();
							});
							$(".dialog .p-img-wp img").zoomify()
							//取消
							$(".paper-cancel-btn").on("click",function(){
								$(".dialog-wp").remove();
							});
							//确定修改
							$(".paper-change-btn").on("click",function(){
								_this.ajaxSureFile(id);
							});
							callback();
					   }   
				   },
				   error: function(){   
				   }
			   });
		},
		/*
		 * 确定修改证件
		 *@param id
		 *
		*/
		ajaxSureFile: function(id){
			var businessImage = $(".paper-item").eq(0).find("#business").data("img");
			var attorImage = $(".paper-item").eq(1).find("#business").data("img");
			var nationImage = $(".paper-item").eq(3).find("#business").data("img");
			var faceImage = $(".paper-item").eq(1).find("#business").data("img");
			$.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/virtual/updateVirtualImage", 
				   data: {
					   "virId": id,
					   "businessImage": businessImage,
					   "nationImage": nationImage,
					   "attorImage": attorImage,
					   "faceImage": faceImage
				   },
				   success: function(data){
					   var result = JSON.parse(data);
					   if(result.code == '200'){
							layer.msg("修改成功")
						   	$(".dialog-wp").remove();
						   
					   } else{
						   layer.alert(result.msg)
					   }  
				   },
				   error: function(){   
				   }
			   });
		},
		/**
		 * 渲染楼层列表
		 * @param id 楼栋id
		 */
		renderFloor: function(id){
			var _this = this;
			 $.ajax({
				   type: "post",
				   url: $("#contextPath").val()+ "/admin/floor/getFloorList", 
				   data: {
					   "orgId": id
				   },
				   success: function(data){
					   var result = JSON.parse(data);
					   if(result.code == '200'){
						   $(".floor-select").html(template.render(tpl.floorsTpl)({floorList: result.data}));
						    //通过楼层筛选房间
							$(".floor-select").on("change",function(e){
								var floorId = $(this).val();
								if(!floorId){
									$(".room-select").html($("<option value=''>选择房间号<option>"))
								}else{
									_this.ajaxRoomList(floorId,$(".room-select"));
								}
							});
						   //floorsTpl
					   }else{
						   layer.alert(result.msg);
					   }   
				   },
				   error: function(){   
				   }
			   });
		}
	}
	enterprise.init();
});
