$(function () {
  var ERROK = 200;
  var contextPath = $("#contextPath").val()
  var table;
  var orgList = [];
  var addressList = [];
  var departList = [];
  var companyList = [];
  //记录选中的数据:做缓存使用,作为参数传递给后台
  var ids = [];
  var idsArr = [];
  var imgId = null;
  var imgUrl = null;
  //当前表格中的全部数据:在表格的checkbox全选的时候没有得到数据, 因此用全局存放变量
  var table_data = [];
  template.config("escape", false);
  var orgId = "";
  var canClick = false
  var tpl = {
    "detailOne": '<div class="dialog-wp detailOne">\
					<div class="mask"></div>\
					<div class="dialog dialog-account-con">\
						<div class="title-wp">\
							<span>账号详情</span>\
							<span class="close-btn"></button>\
						</div>\
						<div class="dialog-account-wp ">\
							 <div class="account-list">\
								 <ul class="list1">\
									<li class="li1"><label>手机号码：</label><span><%=mobile%></span></li>\
									<li class="li1"><label>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</label><span><%=userName%></span></li>\
									<li class="li1"><label>积分余额：</label><span><%=integrale%></span></li>\
									<li class="li1"><label>部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门：</label>\
									<%for (var i=0;i<departList.length;i++){ %>\
										<% if(departList[i].id == dept){ %>\
											<span><%=departList[i].itemname%></span>\
										<%}%>\
									<%}%>\
									</li>\
									<li class="li1"><label>送餐地址：</label>\
										<%for (var i=0;i<addressList.length;i++){ %>\
											<% if(addressList[i].id == address){ %>\
												<span><%=addressList[i].itemname%></span>\
											<%}%>\
										<%}%>\
									</li>\
									<li class="other_image lis">\
										<label>识别图片：</label>\
										<% if(facePicList != null){ %>\
											<%for (var i=0;i<facePicList.length;i++){ %>\
												<img class="mr8" src="<%=serveImgUrl+facePicList[i].imageUrl%>" onclick="boostImg(this)"/>\
											<%}%>\
										<%}%>\
									</li>\
									<li class="li1">\
										<label>账号类型：</label>\
										<% if(roleType == "1"){ %>\
											<span>管理员</span>\
										<%}%>\
										<% if(roleType == "2"){ %>\
											<span>个人账户</span>\
										<%}%>\
										<% if(roleType == "3"){ %>\
											<span>可被代订</span>\
										<%}%>\
									</li>\
									<li class="li1 spans"><label>积分明细：</label>\
										<div class="integral">\
										<% if(recodeList != null){ %>\
											<%for (var i=0;i<recodeList.length;i++){ %>\
												<div class="integral-list">\
													<div><span class="left" style="color: #333333; font-size:15px"><%=recodeList[i].opTypeStr%></span>\
													<% if(recodeList[i].exchangeIntegral.indexOf("-") != -1){ %><span class="right greenC"><%=recodeList[i].exchangeIntegral%></span><%}%>\
													<% if(recodeList[i].exchangeIntegral.indexOf("-") == -1){ %><span class="right yellowC">+<%=recodeList[i].exchangeIntegral%></span><%}%>\
													</div>\
													<div style="font-size:13px"><span class="left"><%=recodeList[i].createTime%></span><span class="right">余额:<%=recodeList[i].newIntgrale%></span></div>\
												</div>\
											<%}%>\
										<%}%>\
										</div>\
									</li>\
								 </ul>\
								 <div class="dialog-btns">\
								 	<button class="sure-detail-btn btn-red">确定</button>\
							 	 </div>\
						</div>\
					</div>\
				</div>	',
    "newsetPermissionsTpl": '<div class="dialog-wp set-permession" >\
		<div class="mask"></div>\
			<div class="dialog dialog-persion-con" style="width: 800px;">\
				<div class="title-wp">\
					<span>批量设置通行权限</span>\
					<span class="close-btn"></button>\
				</div>\
			\
				<div class="dialog-account-wp ">\
				 <div class="account-list" style="padding: 20px;">\
					 <ul class="list1">\
						<li class="li1"><label><span class="red">*</span>名称：</label>\
							<select id ="groupId" class="item-select group-id" >\
								<option value="">请选择名称</option>\
								<%for(var i=0;i<names.length;i++){%>\
									<option value="<%=names[i].id%>"><%=names[i].groupName%></option>\
								<%}%>\
							</select>\
						</li>\
					 </ul>\
					 <div class="trees-wrapper">\
						<div class="tree-wrapper-left">\
							<div class="title">未关联</div>\
							<div style="padding: 0 8px;"><input class="search-btn" id="key1"  data-type="2" type="text" placeholder="请输入项目名称"/></div>\
							<div class="tree ztree" id="trees1"></div>\
						</div>\
						<div class="tree-switchs">\
							<div class="switch-left"><<</div>\
							<div class="switch-right">>></div>\
						</div>\
						<div class="tree-wrapper-right">\
							<div class="title">已关联</div>\
		                    <div style="padding: 0 8px;"><input class="search-btn" type="text" id="key2"   data-type="1" placeholder="请输入项目名称"/></div>\
							<div class="tree ztree" id="trees2"></div>\
						</div>\
					</div>	\
					\
			</div>\
		</div>\
		</div>'	,
    "setPermissionsTpl": '<div class="dialog-wp set-permession">\
			<div class="mask"></div>\
			<div class="dialog dialog-account-con">\
				<div class="title-wp">\
					<span>批量设置通行权限</span>\
					<span class="close-btn"></button>\
				</div>\
				<div class="dialog-account-wp ">\
					 <div class="account-list">\
						 <ul class="list1">\
							<li class="li1"><label><span class="red">*</span>名称：</label>\
								<select id ="groupId" class="item-select group-id" >\
									<option value="">请选择名称</option>\
									<%for(var i=0;i<names.length;i++){%>\
										<option value="<%=names[i].id%>"><%=names[i].groupName%></option>\
									<%}%>\
								</select>\
							</li>\
							<li class="li1 hadPeople" style="display:none">\
								<label class="mt15">已有人员：</label>\
								<div class="set-account-num">\
								</div>\
							</li>\
							<li class="li1">\
								<label class="mt15"><span class="red">*</span>设置账号：</label>\
								<div class="set-account-num">\
								<%for(var i=0;i<personList.length;i++){%>\
									<label><input type="checkbox" name="account" value="<%=personList[i].id%>" checked="checked"><span><%=personList[i].userName%></span><span style="padding-left: 8px;"><%=personList[i].mobile%></span></label>\
								<%}%>\
								</div>\
								<div style="padding-left:88px">共计：<span class="txt_blue total"><%=personLen%>人</span></div>\
							</li>\
						 </ul>\
						 <div class="dialog-btns" style="border: 0">\
							 <button class="sure-add-btn grayBtn btn-red" style="margin-top: 25px;background:#ebebeb!important;color: #333;border-color:#ebebeb">确认</button>\
							</div>\
				</div>\
			</div>\
		</div>',
    "sendCardTpl": '<div class="dialog-wp sendCardTpl">\
    <div class="mask"></div>\
    <div class="dialog dialog-account-con">\
      <div class="title-wp">\
        <span>发卡</span>\
        <span class="close-btn"></button>\
      </div>\
			<div class="dialog-account-wp ">\
					<div class="account-list">\
						<div class="account-item required clearfloat">\
							<div class="item-tip">手机号码：</div>\
							<div class="item-con">\
								<label><%=mobile%></label>\
							</div>\
						</div>\
						<div class="account-item required clearfloat">\
							<div class="item-tip">姓名：</div>\
							<div class="item-con">\
								<label><%=userName%></label>\
							</div>\
						</div>\
						<div class="account-item required clearfloat">\
							<div class="item-tip">实体卡号：</div>\
							<div class="item-con">\
								<input class="item-input cardNumber" type="text" value="" placeholder="请输入实体卡号">\
							</div>\
						</div>\
						<div class="dialog-btns" style="border: 0;">\
							<button class="sure-add-btn btn-red">确定</button>\
						</div>\
      		</div>\
    	</div>\
    </div>	',
    "detailTpl": '<div class="dialog-wp detailTpl">\
    <div class="mask"></div>\
    <div class="dialog dialog-account-con">\
      <div class="title-wp">\
        <span>员工通行详情</span>\
        <span class="close-btn"></button>\
      </div>\
			<div class="dialog-account-wp ">\
      <div class="account-list">\
      <div class="account-item required clearfloat">\
        <div class="item-tip">姓名：</div>\
        <div class="item-con">\
          <label><%=userName%></label>\
        </div>\
      </div>\
      <div class="account-item required clearfloat">\
        <div class="item-tip">手机号码：</div>\
        <div class="item-con">\
          <label><%=mobile%></label>\
        </div>\
      </div>\
      <div class="account-item required clearfloat">\
        <div class="item-tip">企业名称：</div>\
        <div class="item-con">\
          <label><%=virName%></label>\
        </div>\
      </div>\
      <div class="account-item required clearfloat">\
        <div class="item-tip">权限分组：</div>\
        <div class="item-con">\
          <label><%=groupName%></label>\
        </div>\
      </div>\
      <div class="account-item required clearfloat">\
      <div class="item-tip">实体卡号：</div>\
        <div class="item-con">\
          <label><%=cardCode%></label>\
        </div>\
      </div>\
      <div class="account-item required clearfloat">\
        <div class="item-tip">发卡时间：</div>\
        <div class="item-con">\
          <label><%=cardCreateTime%></label>\
        </div>\
      </div>\
      <c:if test="${fn:contains(passType,"4")}">\
        <div class="account-item required clearfloat">\
          <div class="item-tip">人脸识别照片：</div>\
          <div class="photo-btn">\
          \
          </div>\
        </div>\
      </c:if>\
      <div class="dialog-btns" style="border: 0;">\
        <button class="sure-edit-btn btn-red">确定</button>\
      </div>\
    </div>\
    	</div>\
    </div>	',
    "editTpl": '<div class="dialog-wp editTpl">\
    <div class="mask"></div>\
    <div class="dialog dialog-account-con">\
      <div class="title-wp">\
        <span>员工通行编辑</span>\
        <span class="close-btn"></button>\
      </div>\
			<div class="dialog-account-wp ">\
          <div class="account-list">\
            <div class="account-item required clearfloat">\
							<div class="item-tip">姓名：</div>\
							<div class="item-con">\
								<label><%=userName%></label>\
							</div>\
						</div>\
						<div class="account-item required clearfloat">\
							<div class="item-tip">手机号码：</div>\
							<div class="item-con">\
								<label><%=mobile%></label>\
							</div>\
						</div>\
						<div class="account-item required clearfloat">\
							<div class="item-tip">企业名称：</div>\
							<div class="item-con">\
								<label><%=virName%></label>\
							</div>\
            </div>\
            <div class="account-item required clearfloat">\
							<div class="item-tip">权限分组：</div>\
							<div class="item-con">\
								<label><%=groupName%></label>\
							</div>\
						</div>\
						<div class="account-item required clearfloat">\
              <div class="item-tip">人脸识别照片：</div>\
							<div class="photo-btn">\
                <input class="photo-file" type="file" />\
                <div class="del-btn"></div>\
              </div>\
						</div>\
						<div class="dialog-btns" style="border: 0;">\
							<button class="sure-edit-btn btn-red">确定</button>\
						</div>\
      		</div>\
    	</div>\
    </div>	',
    "photoTpl": '<div class="photo-item" data-url="<%=url%>">\
       <div class="photo-item-img" style="background-image: url(<%=preview%>)"></div>\
       <div class="del-btn"></div>\
    </div>',
    "loading": '<div class="dialog-wp load-box">\
        <div class="load-img">\
           <img src="../../images/progressBar_m.gif">\
           <div class="load-text">权限处理中...</div>\
        </div>\
     </div>',
  };
  var api = {
    init: function () {
      this.render();
      this.bindEvent();
    },
    render: function () {
      this.rendertable();
      this.itemAjax();
      // this.ajaxDepartAndAddress();
      this.ajaxCompanyList($("#conditionform #orgId").attr('org__id'), function (data) {
        let comArr = "";
        $.each(data, function (index, item) {
          comArr += "<option value='" + item.id + "'>" + item.name + "</option>"
        })
        $("#conditionform #companyId").append(comArr);
      });
    },
    bindEvent: function () {
      var _this = this;
      layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
          elem: '#beginTime' //提交开始时间
        });
        laydate.render({
          elem: '#endTime' //提交结束时间
        });
      });
      //重置
      $(".set-btn").on("click", function () {
        idsArr = []; //清空之前选择的数据
        $("#conditionform input:not('#orgId'),#conditionform select:not('#orgId')").val("");
        _this.againRenderTable();
        _this.ajaxCompanyList($("#conditionform #orgId").attr('org__id'), function (data) {
          let comArr = "<option value=''>请选择企业</option>";
          $("#conditionform #companyId").html(comArr);
        });
      });
      // 项目的change事件
      $("#conditionform #orgId").change(function () {
        setTimeout(function () {
          _this.ajaxCompanyList($("#conditionform #orgId").attr('org__id'), function (data) {
            $("#conditionform #companyId").html("<option value=''>请选择企业</option>");
            let comArr = "";
            $.each(data, function (index, item) {
              comArr += "<option value='" + item.id + "'>" + item.name + "</option>"
            })
            $("#conditionform #companyId").append(comArr);
          });
        }, 200)

      });
      $(".setPermiss").on("click", function () {
        var orgId = $("#conditionform  #orgId").attr('org__id');
        var ztree1, ztree2;
        _this.permissionListAjax(orgId, function (data) {
          $("body").append(template.render(tpl.newsetPermissionsTpl)({
            names: data
          }));
          $(".close-btn").on("click", function () {
            $(".dialog-wp").remove();
          });
          $("#key1,#key2").keypress(function (event) {
            var keyVal = $(this).val();
            var type = $(this).data("type");
            var keycode = (event.keyCode ? event.keyCode : event.which);
            if (keycode == '13') {
              _this.ajaxVirtDeptUser(type, $("#groupId").val(), orgId, keyVal, function (zNodes) {
                var setting = {
                  check: {
                    enable: true
                  },
                  data: {

                  }
                };
                if (type == 1) {
                  ztree2 = $.fn.zTree.init($("#trees2"), setting, zNodes);
                  ztree2.expandAll(true);
                } else {
                  ztree1 = $.fn.zTree.init($("#trees1"), setting, zNodes);
                  ztree1.expandAll(true);
                }

              })
            }

          })

          $(".set-permession #groupId").on("change", function () {
            if (!$("#groupId").val()) {
              layer.msg('请先选择名称');
              return;
            }

            _this.ajaxVirtDeptUser(2, $("#groupId").val(), orgId, '', function (zNodes) {

              var setting = {
                check: {
                  enable: true
                },
                data: {

                }
              };
              ztree1 = $.fn.zTree.init($("#trees1"), setting, zNodes);
              ztree1.expandAll(true);
            })
            _this.ajaxVirtDeptUser(1, $("#groupId").val(), orgId, '', function (zNodes) {
              console.log('zNodes', zNodes)
              var setting = {
                check: {
                  enable: true
                },
                data: {

                }
              };
              ztree2 = $.fn.zTree.init($("#trees2"), setting, zNodes);
              ztree2.expandAll(true);
            })
            $(".switch-right").on("click", function () {
              $("body").append(template.render(tpl.loading)({}));

              var nodes1 = ztree1.getCheckedNodes();
              var persons = [];
              for (var i = 0; i < nodes1.length; i++) {
                if (nodes1[i].getCheckStatus().half != true) {
                  if (nodes1[i].children.length == 0 && (nodes1[i].level == 1 || nodes1[i].level == 2)) {
                    if (persons.indexOf(nodes1[i].id) == -1)
                      persons.push(nodes1[i].id)
                  }
                  ztree1.removeNode(nodes1[i]);
                }
              }
              //    				  var nodes2 = ztree2.getNodes();
              //    				  if(nodes2){
              //    					  for(var i=0;i<nodes2.length;i++){
              //        					  for(var j=0;j<nodes2[i].children.length;j++){
              //        						  if(nodes2[i].children[j].children.length==0){
              //        							  if(persons.indexOf(nodes2[i].children[j].id) == -1)
              //        							  persons.push(nodes2[i].children[j].id)
              //        						  }else{
              //        							  for(var l=0;l<nodes2[i].children[j].children.length;l++){
              //        								  if(persons.indexOf(nodes2[i].children[j].children[l].id) == -1)
              //        								  persons.push(nodes2[i].children[j].children[l].id)
              //        							  }
              //        						  }
              //        					  }
              //        				  }
              //    				  }

              if (!$(".dialog-wp #groupId").val()) {
                layer.msg("名称必填");
                return false;
              }
              _this.ajaxAddUserPerm(persons, $(".dialog-wp #groupId").val(), function () {
                _this.ajaxVirtDeptUser(1, $("#groupId").val(), orgId, $("#key2").val(), function (zNodes) {
                  var setting = {
                    check: {
                      enable: true
                    },
                    data: {

                    }
                  };
                  ztree2 = $.fn.zTree.init($("#trees2"), setting, zNodes);
                  ztree2.expandAll(true);
                  $(".load-box").remove();
                })
              });
            })
            $(".switch-left").on("click", function () {
              $("body").append(template.render(tpl.loading)({}));
              var nodes1 = ztree2.getCheckedNodes();
              var persons = [];
              for (var i = 0; i < nodes1.length; i++) {
                if (nodes1[i].getCheckStatus().half != true) {
                  if (nodes1[i].children.length == 0 && (nodes1[i].level == 1 || nodes1[i].level == 2)) {
                    if (persons.indexOf(nodes1[i].id) == -1)
                      persons.push(nodes1[i].id)
                  }
                  ztree2.removeNode(nodes1[i]);
                }
              }
              //    				  var nodes2 = ztree2.getNodes();
              //    				  if(nodes2){
              //    					  for(var i=0;i<nodes2.length;i++){
              //        					  for(var j=0;j<nodes2[i].children.length;j++){
              //        						  if(nodes2[i].children[j].children.length==0){
              //        							  if(persons.indexOf(nodes2[i].children[j].id) == -1)
              //        							  persons.push(nodes2[i].children[j].id)
              //        						  }else{
              //        							  for(var l=0;l<nodes2[i].children[j].children.length;l++){
              //        								  if(persons.indexOf(nodes2[i].children[j].children[l].id) == -1)
              //        								  persons.push(nodes2[i].children[j].children[l].id)
              //        							  }
              //        						  }
              //        					  }
              //        				  }
              //    				  }
              if (!$(".dialog-wp #groupId").val()) {
                layer.msg("名称必填");
                return false;
              }
              _this.ajaxDeleteUserPerm(persons, $(".dialog-wp #groupId").val(), function () {
                _this.ajaxVirtDeptUser(2, $("#groupId").val(), orgId, $("#key1").val(), function (zNodes) {
                  var setting = {
                    check: {
                      enable: true
                    },
                    data: {

                    }
                  };
                  ztree1 = $.fn.zTree.init($("#trees1"), setting, zNodes);
                  ztree1.expandAll(true);
                  $(".load-box").remove();
                })
              });
            })
          })
        })
      })
      //      $(".setPermiss").on("click",function(){
      //
      //    	  var orgId = $("#conditionform  #orgId").attr('org__id');
      //    	  _this.permissionListAjax(orgId, function (data) {
      //              $("body").append(template.render(tpl.newsetPermissionsTpl)({
      ////                personLen: personList.length,
      ////                personList: personList,
      //                names: data
      //              }));
      //              //关闭弹窗
      //              $(".close-btn").on("click", function () {
      //                $(".dialog-wp").remove();
      //              });
      //              //确认添加
      //            $(".sure-add-btn").on("click", function () {
      //            	var persons = []
      //          	 var treeObj = $.fn.zTree.getZTreeObj("trees2");
      //   			 var nodes = treeObj.getNodes();
      //   			 console.log(nodes);
      //   			 for(var j=0;j<nodes.length;j++){
      //   				 if(nodes[j].level==0){
      //   					 var childs = nodes[j].children;
      //   					 if(childs && childs.length>0){
      //   						 for(var k=0;k<childs.length;k++){
      //   							persons.push(childs[k].id)
      //   						 }
      //   					 }else{
      //   						persons.push(childs[j].id)
      //   					 }
      //   				 }
      //   			 }
      ////              if (!$(".dialog-wp #groupId").val()) {
      ////                layer.msg("名称必填");
      ////                return false;
      ////              }
      ////              _this.setUserPerm(persons, function () {
      ////                  $(".dialog-wp").remove();
      ////                  layer.msg("设置成功！")
      ////                  _this.againRenderTable();
      ////                  canClick = false
      ////                });
      ////            });
      //              $(".set-permession #groupId").on("change", function () {
      //            	  if(!$("#groupId").val()){
      //            		  layer.msg('请先选择名称');
      //         			 return;
      //            	  }
      //            	 _this.ajaxVirtDeptUser($("#groupId").val(),orgId,'',function(zNodes){
      //            		 var setting = {
      //        					check: {
      //        						enable: true,
      //        						chkboxType: {"Y":"ps","N":"ps"}
      //        					},
      //        					data: {
      //
      //        					}
      //        				};
      //            		 var zTree1 = $.fn.zTree.init($("#trees1"), setting, zNodes);
      //            		 fuzzySearch('trees1','#key1',null,true);
      //            		 _this.ajaxCustomerList($("#groupId").val(),function(data){
      //
      //                   	  for(var i=0;i<data.length;i++){
      //                   		var node = zTree1.getNodeByParam("id", data[i].userId);
      //                   		if(node){
      //                   			zTree1.checkNode(node, true)
      //                   		}
      //                   	  }
      //
      //                   	var nodes1 = zTree1.getCheckedNodes();
      //                   	for (var i = 0, l = nodes1.length; i < l; i++) {
      //                   		zTree1.checkNode(nodes1[i], true, true);
      //                   	}
      //                   	zTree1.refresh();
      //                 	 $(".switch-right").on("click",function(){
      //            			 var treeObj = $.fn.zTree.getZTreeObj("trees1");
      //            			 var nodes = treeObj.getCheckedNodes(true);
      //                		 console.log('nodes',nodes);
      //                		 var chooseList = [];
      //                		 if(nodes.length==0){
      //                			 layer.msg('请勾选要关联的项目');
      //                			 return;
      //                		 }
      //                		 for(var i=0;i<nodes.length;i++){
      //                			 if(nodes[i].level == 0){
      //                				 var obj = {
      //                					name: nodes[i].name,
      //                					id: nodes[i].id,
      //                					children: [],
      //                					checked: true
      //                				 }
      //                				 for(var j=0;j<nodes[i].children.length;j++){
      //                					 if(nodes[i].children[j].checked){
      //                						 nodes[i].children[j].checked = true
      //                						 //obj.children.push(node[i].children[j]);
      //                						 if(nodes[i].children[j].children && nodes[i].children[j].children.length>0){
      //                							 var list = nodes[i].children[j].children;
      //                							 var childs = [];
      //                							 for(var m=0;m<list.length;m++){
      //                								 if(list[m].checked){
      //                									 list[m].checked = true
      //                									 childs.push(list[m])
      //                								 }
      //                							 };
      //                							 nodes[i].children[j].children = childs;
      //                						 }
      //                						 obj.children.push(nodes[i].children[j]);
      //                					 }
      //                				 };
      //                				 chooseList.push(obj)
      //                			 }
      //                		 };
      //                		 var setting1 = {
      //             					check: {
      //             						enable: true,
      //             						//chkboxType: {"Y":"p","N":"s"}
      //             					},
      //             					data: {
      //
      //             					}
      //             				};
      //                 		 var treeObj2 = $.fn.zTree.init($("#trees2"), setting1, chooseList);
      //                 		treeObj2.expandAll(true);
      //                 		fuzzySearch('trees2','#key2',null,true);
      //                 		var nodes2 = treeObj2.getCheckedNodes();
      //                       	for (var i = 0, l = nodes2.length; i < l; i++) {
      //                       		treeObj2.checkNode(nodes2[i], false, true);
      //                       	}
      //                       	zTree1.refresh();
      //
      //                 		 $(".switch-left").on("click",function(){
      //                 			 var nodes2 = treeObj2.getCheckedNodes(true);
      //                    		 console.log('nodes2',nodes2);
      //                    		 if (nodes2.length>0) {
      //                    			 for(var i=0;i<nodes2.length;i++){
      //
      //                    				// 过滤父节点,nodes[i].getCheckStatus().half===true表示是半选中
      ////                    				 console.log(nodes2[i].getCheckStatus().half);debugger
      ////                                     if (nodes2[i].getCheckStatus().half != true) {
      ////
      ////                                     }
      //
      //
      //                    				 if(nodes2[i].getCheckStatus().half !=true){
      //                    					 treeObj2.removeNode(nodes2[i]);
      ////                    					 zTree1.checkNode(nodes1[i],false,true);debugger
      //                    					 var node = zTree1.getNodeByParam("id", nodes2[i].id);
      //                                		 if(node){
      //                                			zTree1.checkNode(node, false)
      //                                		 }
      //                    				 }
      //
      //                    			 }
      //                    		 };
      ////                    		 var nodes1 = zTree1.getCheckedNodes(true);
      ////                    		 console.log('nodes1',nodes1);
      ////                    		 if (nodes1.length>0) {
      ////                    			 for(var i=0;i<nodes1.length;i++){
      ////                    				 zTree1.cancelSelectedNode(nodes1[i]);
      ////                    			 }
      ////
      ////                    		 }
      //                 		 })
      //                	 });
      //
      //                	 $(".switch-right").click();
      //                     });
      //
      //            	 });
      //              });
      //
      //            });
      //
      //      })
      // 设置通行权限
      //      $("#setPermissions").on("click", function () {
      //        // var checkStatus = table.checkStatus('testReload');
      //        var checkStatus = idsArr;
      //        // if (checkStatus.length == 0) {
      //        // 	layer.msg("请先选择设置权限人员");
      //        // 	return false
      //        // };
      //        var orgId = $("#conditionform  #orgId").attr('org__id');
      //        var list = checkStatus;
      //        var personList = [];
      //        $.each(list, function (index, item) {
      //          if (item.isEnabled == "1") {
      //            personList.push(item)
      //          }
      //        })
      //        _this.permissionListAjax(orgId, function (data) {
      //          $("body").append(template.render(tpl.setPermissionsTpl)({
      //            personLen: personList.length,
      //            personList: personList,
      //            names: data
      //          }));
      //
      //          $(".set-permession input:checkbox").on("change", function () {
      //            $(".set-permession .total").html($('.set-account-num input[name=account]:checkbox:checked').length + "人");
      //          });
      //          var persons = [];
      //          //关闭弹窗
      //          $(".close-btn").on("click", function () {
      //            $(".dialog-wp").remove();
      //          });
      //          $(".set-permession #groupId").on("change", function () {
      //        	$(".grayBtn").css("cssText","background:#ebebeb!important;color:#333!important;border-color:#ebebeb!important")
      //        	canClick = false
      //            $(".hadPeople .set-account-num").html('');
      //            var groupId = $("#groupId").val();
      //            if (groupId != '') {
      //              _this.ajaxCustomerList($("#groupId").val());
      //            } else {
      //              $(".hadPeople").css("display", "none");
      //            }
      //          });
      //          //确认添加
      //          $(".sure-add-btn").on("click", function () {
      ////            $('.set-account-num input:checkbox:checked').each(function () {
      ////              persons.push($(this).val())
      ////            })
      //        	 var treeObj = $.fn.zTree.getZTreeObj("trees2");
      // 			 var nodes = treeObj.getNodes();
      // 			 console.log(nodes);
      //            if (!$(".dialog-wp #groupId").val()) {
      //              layer.msg("名称必填");
      //              return false;
      //            }
      // if (persons.length == 0) {
      // 	layer.msg("设置账号必选");
      // 	return false;
      // }
      //            if(canClick){
      //                _this.setUserPerm(persons, function () {
      //                    $(".dialog-wp").remove();
      //                    layer.msg("设置成功！")
      //                    _this.againRenderTable();
      //                    canClick = false
      //                  });
      //            }
      //          });
      //        });
      //      })
      // 模糊搜索
      _this.search_fuzzy()

    },
    // 模糊搜索事件
    search_fuzzy: function () {
      $('body').on("input", '#orgId', function (event) {
        var _this = $(this)
        cjqt.search_fuzzy.event_input(_this, 'org__id', 'org__span', contextPath, '/admin/templ/getOrgListByName')
      });
      $('body').on("focus", '#orgId', function (event) {
        var _this = $(this)
        cjqt.search_fuzzy.event_focus(_this, 'org__id', 'org__span', contextPath, '/admin/templ/getOrgListByName')
      });
      $('body').on('blur', '#orgId', function (event) {
        var _this = $(this)
        cjqt.search_fuzzy.event_blur(_this, 'org__id')
      });
      $('body').on('click', '.select_wrap>.org__span', function (event) {
        event.preventDefault();
        event.stopPropagation();
        /* Act on the event */
        var _this = $(this)
        cjqt.search_fuzzy.event_click(_this, 'org__id', '#orgId')
      });
    },
    rendertable: function () {
      var _this = this;
      layui.use('table', function () {
        table = layui.table;
        //方法级渲染
        table.render({
          elem: '#LAY_table_user',
          url: $("#contextPath").val() + "/admin/appUser/getEmployeeList",
          method: "post",
          where: {
            orgId: $("#orgId").attr('org__id'),
            hasPermGroup: $("#hasPermGroup").val()
          },
          skin: 'nob' //行边框风格
          ,
          even: true //开启隔行背景
          ,
          size: 'lg' //小尺寸的表格
          ,
          cols: [
            [{
              type: 'checkbox',
              fixed: 'left'
            },
            {
              field: 'index',
              title: 'ID',
              width: '80',
              templet: '#indexTpl'
            }, {
              field: 'userName',
              title: '姓名',
              minWidth: 200
            }, {
              field: 'mobile',
              title: '手机号码',
              minWidth: 200
            }, {
              field: 'virName',
              title: '企业名称',
              minWidth: 200
            }, {
              field: 'groupName',
              title: '权限分组',
              minWidth: 200
            }, {
              field: 'cardCode',
              title: '实体卡号',
              minWidth: 200,
            }, {
              field: 'cardCreateTime',
              title: '发卡时间',
              minWidth: 200

            }, {
              title: '操作',
              fixed: 'right',
              width: 200,
              align: 'center',
              templet: function (data) {
                var str = '';
                if (data.passType.indexOf("2") != -1 && data.cardCode) {
                  str += '<button class="t-btn t-red-btn t-collection-btn" data-id=' + data.id + ' data-type="1" data-cardid =' + data.cardId + ' data-cardcode =' + data.cardCode + '>收卡</button>';
                } else if (data.passType.indexOf("2") != -1 && !data.cardCode) {
                  str += '<button class="t-btn t-red-btn t-payment-btn" data-id=' + data.id + ' data-type="1">发卡</button>';
                }
                if (data.passType.indexOf("4") != -1) {
                  str += '<button class="t-btn t-red-btn t-edit-btn" data-id=' + data.id + ' data-type="1" lay-event="edit" >编辑</button>';
                  str += '<button class="t-btn t-red-btn t-publish-btn" data-id=' + data.id + ' data-type="1" lay-event="detail" >详情</button>';
                }
                return str;
              }
            }
            ]
          ],
          id: 'testReload',
          page: true,
          response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            ,
            statusCode: 200 //成功的状态码，默认：0
            ,
            countName: "count" //数据总数的字段名称，默认：count
            ,
            dataName: "data" //数据列表的字段名称，默认：data
            ,
            msgName: 'msg' //规定状态信息的字段名称，默认：msg
          },
          request: {
            pageName: 'pageNo' //页码的参数名称，默认：page
            ,
            limitName: 'pageSize' //每页数据量的参数名，默认：limit
          },
          where: {
            orgId: $("#conditionform  #orgId").attr('org__id'),
          },
          done: function (res, curr, count) {
            // //影藏设置权限等按钮
            var isShow = res.msg;
            if (isShow.indexOf("2") != -1) {
              document.querySelector("#setPermissions").style.display = 'inline-block';
            } else {
              document.querySelector("#setPermissions").style.display = 'none';
            }
            //复现之前选择数据
            table_data = res.data;
            //在缓存中找到id ,然后设置data表格中的选中状态
            //循环所有数据，找出对应关系，设置checkbox选中状态
            for (var i = 0; i < res.data.length; i++) {
              for (var j = 0; j < idsArr.length; j++) {
                //数据id和要勾选的id相同时checkbox选中
                if (res.data[i].id == idsArr[j].id) {
                  //这里才是真正的有效勾选
                  res.data[i]["LAY_CHECKED"] = 'true';
                  //找到对应数据改变勾选样式，呈现出选中效果
                  var index = res.data[i]['LAY_TABLE_INDEX'];
                  $('.layui-table-fixed-l tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                  $('.layui-table-fixed-l tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                }
              }
            }
            //设置全选checkbox的选中状态，只有改变LAY_CHECKED的值， table.checkStatus才能抓取到选中的状态
            var checkStatus = table.checkStatus('testReload');
            if (checkStatus.isAll) {
              $(' .layui-table-header th[data-field="0"] input[type="checkbox"]').prop('checked', true);
              $('.layui-table-header th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');
            }
            //详情
            $(".t-publish-btn").on("click", function () {
              var id = $(this).data("id");
              _this.ajaxDetail(id, function (data) {
                $("body").append(template.render(tpl.detailTpl)(data));
                if (imgUrl) {
                  $(".photo-btn").css("background", "url(" + imgUrl + ") no-repeat center center");
                }
                //关闭弹窗
                $(".close-btn,.sure-detail-btn").on("click", function () {
                  $(".dialog-wp").remove();
                });
              })
            });
            // 编辑
            $(".t-edit-btn").on("click", function () {
              var id = $(this).data("id");
              _this.ajaxDetail(id, function (data) {
                $("body").append(template.render(tpl.editTpl)(data));
                if (imgUrl) {
                  $(".photo-btn").css("background", "url(" + imgUrl + ") no-repeat center center");
                  $(".del-btn").show()
                }else{
                  $(".del-btn").hide()
                }
                //上传人脸图片
                $(".photo-file").on("change", function () {
                  var file = $(this)[0].files[0];
                  var fileName = $(this)[0].value;
                  var suffixIndex = fileName.lastIndexOf(".");
                  var suffix = fileName.substring(suffixIndex + 1).toUpperCase();
                  if ($(".photo-item").length == 1) {
                    layer.msg("餐品照片最多上传5张!");
                    return false;
                  }
                  if (suffix != "BMP" && suffix != "JPG" && suffix != "JPEG" && suffix != "PNG" && suffix != "GIF") {
                    layer.alert("请上传图片（格式BMP、JPG、JPEG、PNG等）!");
                    return false;
                  }
                  if (file) {
                    var reader = new FileReader();
                    reader.onload = function (evt) {
                      var imgstr = evt.target.result; //这就是base64字符串
                      _this.uploadImg(imgstr)
                    };
                    reader.readAsDataURL(file);
                  }
                })
                $(".sure-edit-btn").on("click", function () {
                  _this.updateImg(id, function (data) {
                    layer.msg("编辑成功！")
                    $(".dialog-wp").remove();
                  })
                })
                //关闭弹窗
                $(".close-btn,.sure-detail-btn").on("click", function () {
                  $(".dialog-wp").remove();
                });
                $(".del-btn").on("click", function() {
                  $(".photo-btn").css("background", "url(../../images/admin/add_icon.svg) no-repeat center center");
                  imgId = null
                  imgUrl = ''
                  $(this).hide()
                })
              });
            })
            //发卡
            $(".t-payment-btn").on("click", function () {
              var id = $(this).data("id");
              _this.ajaxDetail(id, function (data) {
                $("body").append(template.render(tpl.sendCardTpl)(data));
                //关闭弹窗
                $(".close-btn,.sure-detail-btn").on("click", function () {
                  $(".dialog-wp").remove();
                });
                //确认添加
                $(".sure-add-btn").on("click", function () {
                  _this.sendCard(id, function () {
                    $(".dialog-wp").remove();
                    layer.msg("发卡成功！")
                    _this.againRenderTable();
                  });
                });
              })
            });
            //收卡
            $(".t-collection-btn").on("click", function () {
              var cardId = $(this).data("cardid");
              var cardCode = $(this).data("cardcode")
              var userId = $(this).data("id")
              _this.deleteCard(cardId, cardCode,userId, function () {
                layer.msg("收卡成功！")
                _this.againRenderTable();
              });
            });
          }
        });
        //复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组
        table.on('checkbox(user)', function (obj) {
          if (obj.checked == true) {
            if (obj.type == 'one') {
              idsArr.push(obj.data);
            } else {
              for (var i = 0; i < table_data.length; i++) {
                idsArr.push(table_data[i]);
              }
            }
          } else {
            if (obj.type == 'one') {
              for (var i = 0; i < idsArr.length; i++) {
                if (idsArr[i].id == obj.data.id) {
                  idsArr.remove(i);
                }
              }
            } else {
              for (var i = 0; i < idsArr.length; i++) {
                for (var j = 0; j < table_data.length; j++) {
                  if (idsArr[i].id == table_data[j].id) {
                    idsArr.remove(i);
                  }
                }
              }
            }
          };
          var newIdsArr = [];
          for (var i = 0; i < idsArr.length; i++) {
            var flag = true;
            for (var j = 0; j < newIdsArr.length; j++) {
              if (idsArr[i].id == newIdsArr[j].id) {
                flag = false;
              };
            };
            if (flag) {
              newIdsArr.push(idsArr[i]);
            };
          };
          //					console.log('newIdsArr',newIdsArr);
          //					console.log('idsArr',idsArr);
          idsArr = newIdsArr;
        });

        table.on('toolbar(user)', function (obj) {
          var checkStatus = table.checkStatus(obj.config.id);
          switch (obj.event) {
            case 'getCheckData':
              var data = checkStatus.data;
              layer.alert(JSON.stringify(data));
              break;
            case 'getCheckLength':
              var data = checkStatus.data;
              layer.msg('选中了：' + data.length + ' 个');
              break;
            case 'isAll':
              layer.msg(checkStatus.isAll ? '全选' : '未全选')
              break;
          };
        });
        //查询
        $('#conditionform  .search-btn').on('click', function () {
          idsArr = []; //清空之前选择的数据
          _this.againRenderTable();
        });
      });
    },
    /**
     * 上传图片
     * @param file file文件
     */
    uploadImg: function (filedata) {
      var _this = this;
      var orgId = $("#conditionform  #orgId").attr('org__id')
      $.ajax({
        type: "post",
        url: contextPath + "/member/uploadKoalaPhoto",
        data: {
          orgId: orgId,
          imageBase64: filedata
        },
        success: function (data) {
          if (data.flag) {
            $(".photo-btn").css("background", "url(" + data.url + ") no-repeat center center");
            imgId = data.id
            imgUrl = data.url
            $(".del-btn").show()
          } else {
            layer.msg(data.desc)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    /**
     * 删除模板
     * @param id 模板id
     * @param callback
     */
    ajaxDelTemp: function (id, type, callback) {
      var str = "";
      if (type == "1") {
        str = "确认禁用?";
      } else if (type == "2") {
        str = "确认启用?";
      } else if (type == "3") {
        str = "确认删除?";
      }
      layer.confirm(str, {
        btn: ['确定', '取消']
      }, function (index, layero) {
        layer.close(index); //如果设定了yes回调，需进行手工关闭
        $.ajax({
          type: "post",
          url: $("#contextPath").val() + "/admin/appUser/updateConsumer",
          data: {
            "id": id,
            "type": type
          },
          success: function (data) {
            if (data.code == 200) {
              callback();
            } else {
              layer.msg(data.msg)
            }
          },
          error: function () {
            // layer.msg('系统繁忙...')
          }
        });
      }, function (index) {

      });
    },

    /*重新渲染table*/
    againRenderTable: function () {
      idsArr = []; //清空之前选择的数据
      table.reload('testReload', {
        where: {
          mobile: $("#conditionform .loginName").val(),
          userName: $("#conditionform .userName").val(),
          orgId: $("#conditionform  #orgId").attr('org__id'),
          virtualArchId: $("#companyId").val(),
          hasPermGroup: $("#hasPermGroup").val()
        },
        page: {
          curr: 1 //重新从第 1 页开始
        }
      });
    },
    //请求项目列表
    itemAjax: function () {
      $.ajax({
        type: "post",
        url: contextPath + "/admin/templ/getOrgList",
        success: function (data) {
          if (data.code == ERROK) {
            orgList = data.data;
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    //请求权限组列表
    permissionListAjax: function (orgId, callback) {
      $.ajax({
        type: "post",
        url: contextPath + "/lingling/getEmployeeGroupList",
        data: {
          orgId: orgId
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback(data.data)
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    // 添加权限用户关系
    setUserPerm: function (list, callback) {
      var userIds = list.join(";");
      $.ajax({
        type: "post",
        url: contextPath + "/lingling/setUserPerm",
        data: {
          groupId: $("#groupId").val(),
          userIds: userIds
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback()
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    /**
     * 请求详情
     * @param id
     * @param callback
     */
    ajaxDetail: function (id, callback) {
      var _this = this;
      $.ajax({
        type: "post",
        url: contextPath + "/admin/appUser/getConsumerInfo",
        data: {
          id: id
        },
        success: function (data) {
          if (data.code == ERROK) {
            data.data.addressList = addressList;
            data.data.departList = departList;
            data.data.id = id;
            imgId = data.data.facePlusImageId
            imgUrl = data.data.imageUrl01
            callback(data.data)
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    /**
     * 新增或修改账号
     * @param callback
     * @param id
     */
    submitAdd: function (callback, id, imageUrlids, removeUrlids) {
      var _this = this;
      var formdata = new FormData();
      if (!!id) {
        formdata.append("id", id)
      }
      //项目
      var orgId = $(".item-con #orgId").attr('org__id');
      if (!orgId) {
        layer.msg("请选择项目");
        return false;
      };
      formdata.append("orgId", orgId)

      // 企业
      var virtualArchId = $(".company-id").val();
      if (!virtualArchId) {
        layer.msg("请选择企业");
        return false;
      };
      formdata.append("virtualArchId", $(".company-id").val());


      //手机号码
      var myreg = /^1[3456789]\d{9}$/;
      if (!$(".mobile-phone").val()) {
        layer.msg("请选择手机号码");
        return false;
      }
      if (!myreg.test($(".mobile-phone").val())) {
        layer.msg("请输入正确的手机号码！");
        return false;
      }
      formdata.append("mobilePhone", $(".mobile-phone").val())

      //姓名
      var name = $(".user-name").val()
      if (!name) {
        layer.msg("请输入姓名");
        return false;
      }
      if (_this.strlen(name) > 20) {
        layer.msg("姓名最多10个汉字");
        return false;
      }
      formdata.append("userName", $(".user-name").val())

      //积分
      var integral = $(".integral-balance").val();
      if (!integral) {
        layer.msg("请输入积分");
        return false;
      }
      formdata.append("integral", $(".integral-balance").val())

      //部门
      var dept = $(".dept").val();
      if (!dept) {
        layer.msg("请选择部门");
        return false;
      }
      formdata.append("deptid", $(".dept").val());
      formdata.append("deptStr", $(".dept  option:selected").text())

      //送餐地址
      var address = $(".dinner-address").val();
      if (!address) {
        layer.msg("请选择送餐地址！");
        return false;
      }
      if (_this.strlen(address) > 100) {
        layer.msg("送餐地址最多50个汉字");
        return false;
      }
      formdata.append("dinnerAddress", $(".dinner-address").val());


      let addimgUrls = "";
      // 识别图片
      for (var i = 0; i < $(".photo-item").length; i++) {
        if ($(".photo-item")[i].getAttribute("data-url")) {
          addimgUrls += $(".photo-item")[i].getAttribute("data-url") + ",";
        }
      }
      // console.log(addimgUrls);
      formdata.append("addimgUrls", addimgUrls);

      //类型
      formdata.append("userType", $(".user-type:checked").data("status"));
      if (!id) {
        _this.ajaxAdd(formdata, function () {
          callback();
        })
      } else {
        formdata.append("imageUrlids", imageUrlids.join(","));
        formdata.append("removeUrlids", removeUrlids.join(","));
        _this.ajaxUpdate(formdata, function () {
          callback();
        })
      }
    },
    /**
     * 新增
     * @param data
     * @param callbck
     */
    ajaxAdd: function (data, callback) {
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/admin/appUser/saveUpdateUserInfo",
        data: data,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {

            callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    /**
     * 修改
     * @param data
     * @param callbck
     */
    ajaxUpdate: function (data, callback) {
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/admin/appUser/saveUpdateUserInfo",
        data: data,
        cache: false, // 不缓存
        processData: false, // 告诉jQuery不要去处理发送的数据
        contentType: false, // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {
          if (data.code == 200) {

            callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    strlen: function (str) {
      var len = 0;
      for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
          len++;
        } else {
          len += 2;
        }
      }
      return len;
    },
    /**
     * 获取部门和地址
     * @param id
     */
    ajaxDepartAndAddress: function (id) {
      var _this = this;
      //获取部门
      $.ajax({
        type: "post",
        url: contextPath + "/admin/appUser/getDeptAndAddress",
        data: {
          type: 1
        },
        success: function (data) {
          if (data.code == ERROK) {

            departList = data.data;

          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
      //获取地址
      $.ajax({
        type: "post",
        url: contextPath + "/admin/appUser/getDeptAndAddress",
        data: {
          type: 2
        },
        success: function (data) {
          if (data.code == ERROK) {
            addressList = data.data;
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    /**
     * 获取企业列表
     * @param organizationId
     */
    ajaxCompanyList: function (organizationId, callback) {
      var _this = this;
      //获取部门
      $.ajax({
        type: "post",
        url: contextPath + "/busi/property/getvirtualArchTypeOne",
        data: {
          organizationId: organizationId
        },
        success: function (data) {
          companyList = data;
          callback(companyList);
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    // 两个数组去重
    array_diff: function (a, b) {
      for (var i = 0; i < b.length; i++) {
        for (var j = 0; j < a.length; j++) {
          if (a[j] == b[i]) {
            a.splice(j, 1);
            j = j - 1;
          }
        }
      }
      return a;
    },
    /**
     * 发卡
     * @param id
     * @param callback
     */
    sendCard: function (id, callback) {
      if (!$(".cardNumber").val()) {
        layer.msg("请输入实体卡号");
        return false
      }
      $.ajax({
        url: $("#contextPath").val() + "/lingling/provideCard",
        type: "POST",
        data: {
          cardCode: $(".cardNumber").val(),
          userId: id
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (xhr, textStatus) {

        }
      });
    },
    /**
     * 收卡
     * @param id
     * @param callback
     */
    deleteCard: function (id, cardCode,userId, callback) {
      var str = "确认收卡?";
      layer.confirm(str, {
        btn: ['确定', '取消']
      }, function (index, layero) {
        layer.close(index); //如果设定了yes回调，需进行手工关闭
        $.ajax({
          url: $("#contextPath").val() + "/lingling/recycleCard",
          type: "POST",
          data: {
            id: id,
            cardCode: cardCode,
            userId:userId
          },
          success: function (data) {
            if (data.code == ERROK) {
              callback();
            } else {
              layer.msg(data.msg)
            }
          },
          error: function (xhr, textStatus) { }
        });
      }, function (index) { });
    },
    /**
     * 更新人脸识别图片
     * @param id
     * @param callback
     */
    updateImg: function (id, callback) {
      // if (!imgId) {
      //   layer.msg("请上传图片");
      //   return false
      // }
      $.ajax({
        url: $("#contextPath").val() + "/member/updateKoalaImg",
        type: "POST",
        data: {
          userId: id,
          imgId: imgId,
          imgUrl: imgUrl
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (xhr, textStatus) {

        }
      });
    },
    //添加 权限用户关系
    ajaxAddUserPerm: function (ids, groupId, callback) {
      $.ajax({
        url: $("#contextPath").val() + "/lingling/addUserPerm",
        type: "POST",
        data: {
          groupId: groupId,
          userIds: ids.join(';')
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback && callback();
          } else {
            layer.msg(data.msg)
            $(".load-box").remove();
          }
        },
        error: function (xhr, textStatus) {
          $(".load-box").remove();
        }
      });
    },
    //删除 权限用户关系
    ajaxDeleteUserPerm: function (ids, groupId, callback) {
      $.ajax({
        url: $("#contextPath").val() + "/lingling/deleteUserPerm",
        type: "POST",
        data: {
          groupId: groupId,
          userIds: ids.join(';')
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback && callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (xhr, textStatus) {

        }
      });
    },
    /**
     * 获取权限组下的用户列表
     * @param id
     * @param callback
     */
    ajaxCustomerList: function (groupId, callback) {
      $.ajax({
        url: $("#contextPath").val() + "/lingling/getGroupUser",
        type: "POST",
        data: {
          groupId: groupId
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback && callback(data.data)
            //            if (data.data.length > 0) {
            //              // $(".hadPeople .set-account-num").html('');
            //              var str = "";
            //              var list = data.data;
            //              $.each(list, function (index, item) {
            //                str += "<label><input type='checkbox' name='personed' value='" + item.userId + "' checked='checked'><span>" + item.userName + "</span><span style='padding-left: 8px;'>" + item.mobile + "</span></label>"
            //              })
            //              $(".hadPeople").css("display", "block");
            //              $(".hadPeople .set-account-num").append(str);
            //            } else {
            //              $(".hadPeople").css("display", "none");
            //            }
            //            $(".grayBtn").css("cssText","background:#FF9400!important;color:#fff!important;border-color:#FF9400!important")
            //            canClick = true
          } else {
            // layer.msg(data.msg)
          }
        },
        error: function (xhr, textStatus) {

        }
      });
    },
    /**
     * 获取指定权限组下的用户列表new
     * @param id
     * @param callback
     * @type 1-指定权限组下的已分配的用户 2-指定权限组下的未分配的用户
     */
    ajaxVirtDeptUser: function (type, groupId, orgId, name, callback) {
      $.ajax({
        url: $("#contextPath").val() + "/lingling/getVirtDeptUser",
        type: "POST",
        data: {
          groupId: groupId,
          orgId: orgId,
          name: name,
          type: type
        },
        success: function (data) {
          if (data.code == ERROK) {
            var res = data.data;
            var treeList = [];
            for (var item in res) {
              treeList.push({
                name: res[item].virtName,
                id: res[item].virtId,
                children: [],
                pid: 0
              })
              var deptList = res[item].deptList;
              var children1 = treeList[treeList.length - 1].children
              for (var dep in deptList) {
                children1.push({
                  name: deptList[dep].name,
                  id: dep,
                  children: [],
                  pid: res[item].virtId
                });
                var userList = deptList[dep].userVoList;
                for (var i = 0; i < userList.length; i++) {
                  children1[children1.length - 1].children.push({
                    name: userList[i].name,
                    id: userList[i].userId,
                    openId: userList[i].openId,
                    mobile: userList[i].mobile,
                    pid: userList[i].deptId,
                    children: []
                  })
                }
              };
              if (res[item].userList) {
                for (var j = 0; j < res[item].userList.length; j++) {
                  children1.push({
                    name: res[item].userList[j].name,
                    id: res[item].userList[j].userId,
                    openId: res[item].userList[j].openId,
                    mobile: res[item].userList[j].mobile,
                    pid: res[item].userList[j].virtId,
                    children: []
                  });
                }
              }

            };

            callback && callback(treeList)
          } else {
            layer.msg(data.msg)
          }
          $(".load-box").remove();
        },
        error: function (xhr, textStatus) {
          $(".load-box").remove();
        }
      });
    },
  };
  api.init();
})

function boostImg(obj) {

  $(".alert-bo").css("display", "block")
  $(".alert-bo img").attr("src", obj.src)
}

function closeAlert() {
  $(".alert-bo").css("display", "none")
}

//删除数组自定义函数
Array.prototype.remove = function (dx) {
  if (isNaN(dx) || dx > this.length) {
    return false;
  }
  for (var i = 0, n = 0; i < this.length; i++) {
    if (this[i] != this[dx]) {
      this[n++] = this[i]
    }
  }
  this.length -= 1
}
