function UpdateFuncApply(data) {
  html="<table border='0' cellspacing='0' style='border-collapse: collapse; border-spacing: 0;'>"
  for(let i=0; i<data.funcList.length; i++){
    html +="<tr>"+
        "<td style='width:150px;border:1px solid #DDDDDD;padding: 0px 2px;color:#555555;'>"+
        "<div class='checkbox-wp level-1'>"+
        "<span class='checkbox-input'>"+
        "<input type='checkbox' id='wx-"+i+"' class='check-item staple-food' data-id='"+data.funcList[i].id+"'/>"+
        "<span class='checkbox-inner'></span>"+
        "</span>"+
        "<label class='checkbox-con' for='wx-"+i+"'>"+data.funcList[i].name+"</label>"+
        "</div>"+
        "</td>"+
        "<td style='width:150px;border:1px solid #DDDDDD;padding: 0px 2px;color:#555555;'>";
    // let secondTree=this.spliceFuncTree(data.funcList[i].serviceId,data.funcChildLis)
    let secondTree=[];
    data.funcChildList.forEach(function(item) {
      if(item.serviceId===data.funcList[i].serviceId){
        secondTree.push(item);
      }
    });
    for(let j=0; j<secondTree.length; j++){
      html+="<div class='checkbox-wp level-2'>"+
          "<span class='checkbox-input'>"+
          "<input type='checkbox' id='cwx-"+j+"' class='check-item staple-food' data-id='"+secondTree[j].id+"' data-code='"+secondTree[j].code+"' father-id='"+data.funcList[i].id+"'/>"+
          "<span class='checkbox-inner'></span>"+
          "</span>"+
          "<label class='checkbox-con' for='wx-"+i+"'>"+secondTree[j].name+"</label>"+
          "</div>";
    }
    html+="</td>"+
        "</tr>";
  }
  html+="</table>";
  $("#funcApply").html(html);
  $("#funcApply").on('click','.check-item',function(){
    if(this.dataset.code==='1000'){
      if(this.checked){
        $(".checkRole").css('display','block');
      }else {
        $(".checkRole").css('display','none');
        $.each($('.checkRole input:checkbox:checked'),function(){
          this.checked=false;
        });
      }
    }
  });
}

function CheckFather(arr, arr2, fathers) {
  for (var i = 0; i < fathers.length; i++) {
    var hasFather = 0;
    for (var j = 0; j < arr.length; j++) {
      if (fathers[i] == arr[j]) {
        hasFather = 1;
        break;
      }
    }
    if (hasFather == 0) {
      return false;
    }
  }
  return true;
}

// 设备列表
$(function () {
  var ERROK = 200;
  var contextPath = $("#contextPath").val()
  var table;
  template.config("escape", false);
  var orgId = $("#orgId").attr('org__id');
  var virAccountInfo = $("#virAccountInfo").val()
  var tpl = {
    "addTpl": '<div class="dialog-wp">\
    <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">\
          <%if(isAdmin == "true"){%>\
            <div class="account-item required clearfloat">\
              <div class="item-tip"><span class="red">*</span>校区：</div>\
              <div class="item-con">\
                <div class="layui-input-inline">\
                <input class="pop-select orgId layui-input" name="orgId" id="orgId" autocomplete="off" placeholder="请选择校区" />\
                <span class="select_wrap _hide"></span>\
              </div>\
            </div>\
            </div>\
          <%}%>\
          <%if(isAdmin  == "false"){%>\
            <input class="pop-select orgId layui-input" name="orgId" id="orgId" autocomplete="off" type="hidden" value="<%=orgId%>" org__id="<%=orgId%>"/>\
          <%}%>\
          <div class="account-item required clearfloat">\
            <div class="item-tip"><span class="red">*</span>企业名称：</div>\
            <div class="item-con">\
              <%if(!virAccountInfo){%>\
                <input class="item-select company-id" name="companyId" id="companyId"  autocomplete="off" placeholder="请输入企业名称"／>\
                <span class="select_wrap _hide"></span>\
              <%}%>\
              <%if(virAccountInfo){%>\
                <input class="item-select company-id" disabled name="companyId" com__id="<%=virId%>" value="<%=virName%>" id="companyId" autocomplete="off"/>\
              <%}%>\
           </div>\
          </div>\
          <div class="account-item required clearfloat">\
            <div class="item-tip"><span class="red">*</span>身份类型名称：</div>\
            <div class="item-con">\
              <input  type="text" class="item-input companyType" placeholder="请输入身份类型名称">\
            </div>\
          </div>\
          <div class="account-item required clearfloat heiAu">\
            <div class="item-tip"><span class="red">*</span>功能权限：</div>\
            <div class="item-con" id="funcApply">\
              <%for(var j=0;j<funcList.length;j++){%>\
                <div class="checkbox-wp">\
                  <span class="checkbox-input">\
                    <input type="checkbox" id="wx-<%=j%>" class="check-item staple-food" data-id="<%=funcList[j].id%>"/>\
                    <span class="checkbox-inner"></span>\
                  </span>		\
                  <label class="checkbox-con" for="wx-<%=j%>"><%=funcList[j].name%></label>\
                </div>\
              <%}%>\
            </div>\
            <div class="checkbox-wp checkRole" style="display:none;">\
              <div class="item-tip"><span class="red">&nbsp;</span></div>\
              <span class="checkbox-input">\
                <input type="checkbox" class="check-item staple-food"/>\
              <span class="checkbox-inner"></span>\
              </span>\
              <label class="checkbox-con">设为放行审核人</label>\
            </div>\
          </div>\
         </div>\
          <div class="dialog-btns">\
            <button class="sure-add-btn btn-red">确定</button>\
          </div>\
         </div>\
      </div>\
    </div>\
  </div>	',
    "modifyTpl": '<div class="dialog-wp">\
    <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"><span class="red">*</span>校区：</div>\
            <div class="item-con">\
              <div class="layui-input-inline">\
                <input class="pop-select orgId layui-input disabled" name="orgId" id="orgId" autocomplete="off" org__id="<%=orgId%>" value="<%=orgName%>" disabled/>\
              </div>\
            </div>\
          </div>\
          <div class="account-item required clearfloat">\
            <div class="item-tip"><span class="red">*</span>企业名称：</div>\
            <div class="item-con">\
              <div class="layui-input-inline">\
                <input class="item-select companyId layui-input disabled" name="companyId" id="companyId" autocomplete="off" com__id="<%=virId%>" value="<%=virName%>" disabled/>\
              </div>\
            </div>\
          </div>\
          <div class="account-item required clearfloat">\
            <div class="item-tip"><span class="red">*</span>身份类型名称：</div>\
            <div class="item-con">\
              <input type="text" class="item-input companyType" value="<%=name%>" placeholder="请输入身份类型名称">\
            </div>\
          </div>\
          <div class="account-item required clearfloat heiAu">\
            <div class="item-tip"><span class="red">*</span>功能权限：</div>\
            <div class="item-con" id="funcApply">\
              <!--\
              <%for(var j=0;j<funcList.length;j++){%>\
                <div class="checkbox-wp">\
                  <span class="checkbox-input">\
                    <input type="checkbox" id="wx-<%=j%>" class="check-item staple-food" data-id="<%=funcList[j].id%>" <%if(funcList[j].checked){%>checked<%}%>/>\
                    <span class="checkbox-inner"></span>\
                  </span>		\
                  <label class="checkbox-con" for="wx-<%=j%>"><%=funcList[j].name%></label>\
                </div>\
              <%}%>\
              -->\
              <table border="0" cellspacing="0" style="border-collapse: collapse; border-spacing: 0;">\
              <%for(var i=0;i<funcList.length;i++){%>\
                <tr>\
                  <td style="width:150px;border:1px solid #DDDDDD;padding: 0px 2px;color:#555555;">\
                    <div class="checkbox-wp level-1">\
                      <span class="checkbox-input">\
                        <input type="checkbox" id="awx-<%=i%>" class="check-item staple-food" data-id="<%=funcList[i].id%>" <%if(funcList[i].checked){%>checked<%}%>/>\
                        <span class="checkbox-inner"></span>\
                      </span>\
                      <label class="checkbox-con" for="bwx-<%=i%>"><%=funcList[i].name%></label>\
                    </div>\
                  </td>\
                  <td style="width:150px;border:1px solid #DDDDDD;padding: 0px 2px;color:#555555;">\
                    <%for(var j=0;j<funcChildList.length;j++){if(funcChildList[j].serviceId!=funcList[i].serviceId)continue;%>\
                      <div class="checkbox-wp level-2">\
                        <span class="checkbox-input">\
                          <input type="checkbox" id="cwx-<%=j%>" class="check-item staple-food" data-id="<%=funcChildList[j].id%>" data-code="<%=funcChildList[j].code%>" father-id="<%=funcList[i].id%>" <%if(funcChildList[j].checked){%>checked<%}%>/>\
                          <span class="checkbox-inner"></span>\
                        </span>\
                        <label class="checkbox-con" for="dwx-<%=i%>"><%=funcChildList[j].name%></label>\
                      </div>\
                    <%}%>\
                  </td>\
                </tr>\
              <%}%>\
              </table>\
            </div>\
          </div>\
          <div class="checkbox-wp checkRole" style="display:none;">\
            <div class="item-tip"><span class="red">&nbsp;</span></div>\
            <span class="checkbox-input">\
              <input id="checkRole" type="checkbox" class="check-item staple-food"/>\
              <span class="checkbox-inner"></span>\
            </span>\
            <label class="checkbox-con">设为放行审核人</label>\
          </div>\
          <div class="dialog-btns">\
            <button class="sure-add-btn btn-red">确定</button>\
          </div>\
         </div>\
      </div>\
    </div>\
  </div>'
  };
  var api = {
    init: function () {
      this.render();
      this.bindEvent();
    },
    render: function () {
      this.rendertable();
    },
    bindEvent: function () {
      var _this = this;
      //重置
      $(".set-btn").on("click", function () {
        if(virAccountInfo){
          var $dom = $("#conditionform #virPermName")
          $dom.val("")
          _this.againRenderTable({type:1});
				}else{
          var $orgId = $("#conditionform  .single-orgid");
          var $dom = $("#conditionform input,#conditionform select")
          if($orgId.length){
            $dom.val("").removeAttr('dep__id')
          }else{
            $dom.val("").removeAttr('org__id')
          }
          _this.againRenderTable({type:1});
        }
      });
      //新增
      $(".add-ele-btn").on("click", function () {
        let funcList = []
        let orgId = $("#conditionform #orgId").attr('org__id')
        let isAdmin = $("#isAdmin").val()
        if(isAdmin == "false") {
          _this.getFuncList(orgId,function (data) {
            $("body").append(template.render(tpl.addTpl)({
              isAdmin: $("#isAdmin").val(),
              orgId: orgId,
              funcList: data,
              virAccountInfo: virAccountInfo,
              virId: $("#conditionform #companyId").attr("com__id"),
              virName: $("#conditionform #companyId").val()
            }));
            UpdateFuncApply(data);
             //关闭弹窗
            $(".close-btn,.cancel-add-btn").on("click", function () {
              $(".dialog-wp").remove();
            });
            //确认添加
            $(".sure-add-btn").on("click", function () {
              let serviceId = ''
              let serviceChildId=''
              let arr = []
              let arr2 = []
              let fathers = []
              let checkRole = 0
              if (!$(".dialog-wp #orgId").attr('org__id')) {
                layer.msg("请选择校区");
                return false;
              }
              if (!$(".dialog-wp #companyId").attr('com__id')) {
                layer.msg("请选择企业");
                return false;
              }
              if (!$(".dialog-wp .companyType").val()) {
                layer.msg("请输入身份类型名称");
                return false;
              }
              $.each($('.level-1 input:checkbox:checked'),function(){
                arr.push($(this).attr('data-id'))
              });

              $.each($('.level-2 input:checkbox:checked'),function(){
                arr2.push($(this).attr('data-id'));
                fathers.push($(this).attr('father-id'));
              });

              if (!CheckFather(arr, arr2, fathers)) {
                layer.msg("请正确选择功能权限");
                return false;
              }

              $.each($('.checkRole input:checkbox:checked'),function(){
                checkRole=1;
              });

              serviceId = arr.join(';')
              serviceChildId = arr2.join(';')
              if (arr.length == 0) {
                layer.msg("请选择功能权限");
                return false;
              }
              _this.submitAdd(function () {
                layer.msg("操作成功");
                $(".dialog-wp").remove();
                _this.againRenderTable();
              },serviceId,null,serviceChildId,checkRole);
            });
          })
        }else{
          $("body").append(template.render(tpl.addTpl)({
            isAdmin: $("#isAdmin").val(),
            orgId: orgId,
            funcList: funcList,
            virAccountInfo: virAccountInfo,
            virId: $("#conditionform #companyId").attr("com__id"),
            virName: $("#conditionform #companyId").val()
          }));
           //关闭弹窗
          $(".close-btn,.cancel-add-btn").on("click", function () {
            $(".dialog-wp").remove();
          });
          //确认添加
          $(".sure-add-btn").on("click", function () {
            let serviceId = ''
            let serviceChildId=''
            let arr = []
            let arr2 = []
            let fathers = []
            let checkRole =0
            if (!$(".dialog-wp #orgId").attr('org__id')) {
              layer.msg("请选择校区");
              return false;
            }
            if (!$(".dialog-wp #companyId").attr('com__id')) {
              layer.msg("请选择企业");
              return false;
            }
            if (!$(".dialog-wp .companyType").val()) {
              layer.msg("请输入身份类型名称");
              return false;
            }
            $.each($('.level-1 input:checkbox:checked'),function(){
              arr.push($(this).attr('data-id'))
            });

            $.each($('.level-2 input:checkbox:checked'),function(){
              arr2.push($(this).attr('data-id'));
              fathers.push($(this).attr('father-id'));
            });

            $.each($('.checkRole input:checkbox:checked'),function(){
              checkRole=1;
            });

            let index=arr2.findIndex(function (item) {
              return item===$("#is_1000").attr('data-id')
            })
            if(checkRole===1&& index===-1){
              layer.msg("请选择审核权限");
              return false;
            }
            if (!CheckFather(arr, arr2, fathers)) {
              layer.msg("请正确选择功能权限");
              return false;
            }
            if($("#is_1000").val()==='1000'&&checkRole===1&&arr2.length===0){
              layer.msg("请选择审核权限");
              return false;
            }
            serviceId = arr.join(';')
            serviceChildId = arr2.join(';')
            if (arr.length ===0) {
              layer.msg("请选择功能权限");
              return false;
            }
            _this.submitAdd(function () {
              layer.msg("操作成功");
              $(".dialog-wp").remove();
              _this.againRenderTable();
            },serviceId,null,serviceChildId,checkRole);
          });
        }
      });
      // 模糊搜索
      _this.search_fuzzy()
    },
    // 模糊搜索校区
    search_fuzzy: function(){
      var _this = this
      var default_option = {
        org_attrName:'org__id',
        com_attrName:'com__id',
        dep_attrName:'dep__id',
        org_spanName:'org__span',
        com_spanName:'com__span',
        dep_spanName:'dep__span',
        org_path:'/admin/templ/getOrgListByName',
        com_path:'/admin/templ/getVirList',
        dep_path:'/admin/templ/getDept',
        contextPath:$("#contextPath").val()
      }
      var option_1 = $.extend(true,{},default_option,{
        org_target:'.default-select#orgId'
      });
      var option_2 = $.extend(true,{},default_option,{
        org_target:'.pop-select#orgId',
        com_target:'.item-select#companyId'
      });
      
      function eve(option_,otherOption){
        var obj = $.extend(true, {}, option_, otherOption);
        var type = obj.type
        var _path, _target, _attrName, _spanName
        if(type == 1){
          _path = obj.org_path
          _target = obj.org_target
          _attrName = obj.org_attrName
          _spanName = obj.org_spanName
        }else if(type == 2){
          _path = obj.com_path
          _target = obj.com_target
          _attrName = obj.com_attrName
          _spanName = obj.com_spanName
        }else if(type == 3){
          _path = obj.dep_path
          _target = obj.dep_target
          _attrName = obj.dep_attrName
          _spanName = obj.dep_spanName
        }
        $('body').on("input",_target,function(event){
          var _this = $(this)
          var obj_input = $.extend(true,{}, obj,{"_this":_this});
          cjqt.search_fuzzy.event_input(_this,_attrName,_spanName,contextPath,_path,obj_input)
        });
        $('body').on("focus",_target,function(event){
          var _this = $(this)
          var obj_focus = $.extend(true,{},obj,{"_this":_this});
          cjqt.search_fuzzy.event_focus(_this,_attrName,_spanName,contextPath,_path,obj_focus)
        });
        $('body').on('blur',_target,function(event) {
          var _this = $(this)
          var obj_blur = $.extend(true,{},obj,{"_this":_this});
          cjqt.search_fuzzy.event_blur(_this,_attrName,obj_blur)
        });
        $('body').on('click',_target+'~.select_wrap>.'+_spanName, function(event) {
          event.preventDefault();
          event.stopPropagation();
          /* Act on the event */
          var _this = $(this)
          var obj_click = $.extend(true,{},obj,{"_this":_this});
          cjqt.search_fuzzy.event_click(_this,_attrName,_target,obj_click)
        });

      }
      // 搜索联动
      eve(option_1,{type:1})
      // 新增、修改联动
      eve(option_2,{
        type:1,
        click_callback:function(){
          console.log('change')
          var orgId = $('.pop-select#orgId').attr('org__id')
          _this.getFuncList(orgId,function(data){
            let html = ''
            // for(let i=0; i<data.length; i++){
            //   html += "<div class='checkbox-wp'><span class='checkbox-input'><input type='checkbox' id='wx-"+i+"' class='check-item staple-food' data-id='"+data[i].id+
            //   "'/><span class='checkbox-inner'></span></span><label class='checkbox-con' for='wx-"+i+"'>"+data[i].name+"</label></div>"
            // }
            UpdateFuncApply(data);
          })
        }
      })
      eve(option_2,{type:2})
    },
    rendertable: function () {
      var _this = this;
      layui.use(['table', 'laydate', 'form'], function () {
        table = layui.table;
        var form = layui.form,
          layer = layui.layer,
          laydate = layui.laydate;
        //日期
        laydate.render({
          elem: '#date1'
        });
        //方法级渲染
        table.render({
          elem: '#LAY_table_user',
          url: $("#contextPath").val() + "/admin/virPerm/virPermList",
          method: "post",
          where: {
            orgId: $("#conditionform #orgId").attr('org__id'),
            permType: '1',
            virPermName: '',
            virId: $("#conditionform #companyId").attr('com__id')
          },
          skin: 'nob' //行边框风格
            ,
          even: true //开启隔行背景
            ,
          size: 'lg' //小尺寸的表格
            ,
          cols: [
            [{
              field: 'index',
              title: '序号',
              width: '80',
              templet: '#indexTpl'
            }, {
              field: 'orgName',
              title: '校区',
              width: 200
            }, {
              field: 'permName',
              title: '身份类型名称',
              minWidth: 200
            }, {
              field: 'funcListStr',
              title: '功能权限',
              minWidth: 200
            }, {
              field: 'userName',
              title: '创建人',
              minWidth: 120
            }, {
              field: 'createTime',
              title: '创建时间',
              width: 200
            }, {
              title: '操作',
              fixed: 'right',
              width: 120,
              align: 'center',
              templet: function (data) {
                var str = "<div class='operate'>";
                str += "<span class='op_edit_btn' lay-event='edit' data-id='"+data.id+"'><i class='edit'></i><i class='op_hover'>修改</i></span>";
                str += "<span class='op_del_btn' lay-event='del' data-id='"+data.id+"'><i class='delete'></i><i class='op_hover'>删除</i></span>";
                str += "</div>";
                return str;
              }
            }]
          ],
          id: 'testReload',
          page: true,
          response: {
            statusName: 'code' //数据状态的字段名称，默认：code
              ,
            statusCode: 200 //成功的状态码，默认：0
              ,
            countName: "count" //数据总数的字段名称，默认：count
              ,
            dataName: "data" //数据列表的字段名称，默认：data
          },
          request: {
            pageName: 'pageNo' //页码的参数名称，默认：page
              ,
            limitName: 'pageSize' //每页数据量的参数名，默认：limit
          },
          done: function (res, curr, count) {
            $(".edit,.delete").mouseover(function(){
              $(this).next().show();
            })
            $(".edit,.delete").mouseout(function(){
              $(this).next().hide();
            })
            //如果是异步请求数据方式，res即为你接口返回的信息。
            //删除
            $(".op_del_btn").on("click", function () {
              var id = $(this).data("id");
              _this.ajaxDelTemp(id, function () {
                _this.againRenderTable();
              })
            });
            //修改
            $(".op_edit_btn").on("click", function () {
              var id = $(this).data("id");
              _this.ajaxDetail(id, function (data) {
                $("body").append(template.render(tpl.modifyTpl)(data));
                $("#funcApply").on('click','.check-item',function(){
                  if(this.dataset.code==='1000'){
                    if(this.checked){
                      $(".checkRole").css('display','block');
                    }else {
                      $(".checkRole").css('display','none');
                      $.each($('.checkRole input:checkbox:checked'),function(){
                        this.checked=false;
                      });
                    }
                  }
                });
                $("#is_1000").val('0');
                $("#is_1000").attr('data-id','');
                data.funcChildList.forEach(function (val) {
                  if(val.code==="1000"){
                    $(".checkRole").css("display","block");
                    $("#is_1000").val('1000');
                    $("#is_1000").attr('data-id',val.id);
                    if(data.checkRole===1){
                      $("#checkRole").attr('checked', true);
                    }
                  }
                })
                //关闭弹窗
                $(".close-btn,.cancel-add-btn").on("click", function () {
                  $(".dialog-wp").remove();
                });
                //确认修改
                $(".sure-add-btn").on("click", function () {
                  let serviceId = '';
                  let serviceChildId = '';
                  let arr = [];
                  let arr2 = [];
                  let fathers = [];
                  let checkRole =0;

                  if (!$(".dialog-wp .companyType").val()) {
                    layer.msg("请输入身份类型名称");
                    return false;
                  }

                  $.each($('.level-1 input:checkbox:checked'),function(){
                    arr.push($(this).attr('data-id'))
                  });
                  $.each($('.level-2 input:checkbox:checked'),function(){
                    arr2.push($(this).attr('data-id'));
                    fathers.push($(this).attr('father-id'));
                  });

                  $.each($('.checkRole input:checkbox:checked'),function(){
                    checkRole=1;
                  });
                  let index=arr2.findIndex(function (item) {
                    return item===$("#is_1000").attr('data-id')
                  })
                  if(checkRole===1&& index===-1){
                    layer.msg("请选择审核权限");
                    return false;
                  }
                  if (arr.length == 0 && arr2.length == 0) {
                    layer.msg("请选择功能权限");
                    return false;
                  }
                  if (!CheckFather(arr, arr2, fathers)) {
                    layer.msg("请正确选择功能权限");
                    return false;
                  }
                  if($("#is_1000").val()==='1000'&&checkRole===1&&arr2.length===0){
                    layer.msg("请选择审核权限");
                    return false;
                  }
                  if(arr.length===0){
                    layer.msg("请选择权限");
                    return false;
                  }
                  serviceId = arr.join(';');
                  serviceChildId = arr2.join(';');

                  _this.submitAdd(function () {
                    $(".dialog-wp").remove();
                    layer.msg("修改成功！");
                    _this.againRenderTable();
                  }, serviceId, id,serviceChildId,checkRole);
                })
              });
            });
          }
        });
        //查询
        $('.search-btn').on('click', function () {
          _this.againRenderTable();
        });
      });
    },
    /**
     * 删除模板
     * @param id 模板id
     * @param callback
     */
    ajaxDelTemp: function (id, callback) {
      var str = "确认删除?";
      layer.confirm(str, {
        btn: ['确定', '取消']
      }, function (index, layero) {
        layer.close(index); //如果设定了yes回调，需进行手工关闭
        $.ajax({
          type: "post",
          url: $("#contextPath").val() + "/admin/virPerm/delVirPerm",
          data: {
            id: id
          },
          success: function (data) {
            if (data.code == 200) {
              callback();
            } else {
              layer.msg(data.msg)
            }
          },
          error: function () {
            // layer.msg('系统繁忙...')
          }
        });
      }, function (index) {

      });
    },

    /*重新渲染table*/
    againRenderTable: function (option) {
      var obj = $.extend(true, {}, option);
      var type =  obj.type || ''
      if(type == 1){
        if(virAccountInfo){
					table.reload('testReload', {
						where: {
              orgId: $("#conditionform #orgId").attr("org__id"),
              virId: $("#conditionform #companyId").attr("com__id"),
              virPermName: '',
              permType: '1'
						},
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				}else{
          table.reload('testReload', {
            where: {
              orgId: '',
              virPermName: '',
              permType: '1'
            },
            page: {
              curr: 1 //重新从第 1 页开始
            }
          });
        }
      }else{
        table.reload('testReload', {
          where: {
            orgId: $("#conditionform #orgId").attr("org__id"),
            virPermName: $("#conditionform #virPermName").val(),
            permType: '1',
            virId: $("#conditionform #companyId").attr("com__id")
          },
          page: {
            curr: 1 //重新从第 1 页开始
          }
        });
      }
    },
    /**
     * 请求详情
     * @param id
     * @param callback
     */
    ajaxDetail: function (id, callback) {
      var _this = this;
      $.ajax({
        type: "post",
        url: contextPath + "/admin/virPerm/virPermInfo",
        data: {
          virPermId: id
        },
        success: function (data) {
          if (data.code == ERROK) {
            callback(data.data)
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    },
    /**
     * 新增或修改
     * @param callback
     * @param id
     */
    submitAdd: function (callback, serviceId, id,serviceChildId,checkRole) {
      var _this = this;
      $.ajax({
        type: "post",
        url: $("#contextPath").val() + "/admin/virPerm/addUpdateVirPerm",
        data: {
          id: id,
          serviceId: serviceId,
          serviceChildId:serviceChildId,
          checkRole:checkRole,
          virPermName: $(".dialog-wp .companyType").val(),
          permType: '1',
          orgId: $(".dialog-wp #orgId").attr('org__id'),
          virId: $(".dialog-wp #companyId").attr('com__id'),
        },
        dataType: "json",
        success: function (data) {
          if (data.code == 200) {
            callback();
          } else {
            layer.msg(data.msg)
          }
        },
        error: function () {
          // layer.msg('系统繁忙.....')
        }
      });
    },
    /**
     * 获取校区开启的功能权限列表
     * @param callback
     * @param orgId
     */
    getFuncList: function (orgId,callback) {
      $.ajax({
        type: "post",
        url: contextPath + "/admin/virPerm/openedFunctionPermissionList",
        data: {
          orgId: orgId
        },
        success: function (data) {
          if (data.code == ERROK) {
            $(".checkRole").css('display','none');
            $("#is_1000").val('0');
            $("#is_1000").attr('data-id','');
            console.log(data.data,'功能权限')
            data.data.funcChildList.forEach(function (val) {
              if(val.code==="1000"){
                $(".checkRole").css('display','none');
                $("#is_1000").val('1000');
                $("#is_1000").attr('data-id',val.id);
              }
            })
            callback(data.data)
          } else {
            layer.msg(data.msg)
          }
        },
        error: function (error) {
          layer.msg('error')
        }
      });
    }
  };
  api.init();
})