 <script type="text/html" id="status">
    
   <input type="checkbox" name="status"  {{#  if(d.status==1){ }}checked{{#  } }} lay-skin="switch" lay-text="正常|禁用" lay-filter="status" value="{{d.id}}" ><div class="layui-unselect layui-form-switch"   lay-skin="_switch">
</script>
<script>
   var jiantable=null
    layui.use(['form', 'table','miniPage','element','miniAdmin','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            miniPage = layui.miniPage;
            miniAdmin = layui.miniAdmin;
        jiantable=table.render({
            elem: '#currentTableId',

             <? if (MOD<>"glog" and MOD<>"stock" and MOD<>"goods" and MOD<>"cost" and MOD<>"gong" and MOD<>"fxgong" and MOD<>"ys" and $dduser['role']<>CW){?>
                 toolbar: '#toolbarDemo',
            <? }?>
         
            method: 'post',
            <? if (MOD=="visit"){?>
                where:{guide:<?=$_GET['guide']?$_GET['guide']:0?>,
                      intention:<?=$_GET['intention']?$_GET['intention']:0?>
                },
            <? }?>
            <? if (MOD=="cost"){?>
                where:{type:<?=$_GET['type']?$_GET['type']:1?>     
                },
            <? }?>

        
           
      
            defaultToolbar: [],
            url: '<?=u("app","list",array("table"=>MOD))?>',
            cols: col,
            done:function(res){
               <? if (MOD=="income"){?>
                   this.elem.next().find('.layui-table-total td[data-field="price"] .layui-table-cell').text(res.other.price);  
               <? }?>

               

            },
            limits: [10, 20, 50, 100, 200, 500],
            limit: 10,
            page: true,
            skin: 'line'
        });
        form.render();
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
        
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });
       
        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
             if (obj.event != 'add' && obj.event != 'addline') { 
                  var checkStatus = table.checkStatus('currentTableId')
                  data = checkStatus.data;
                  if (data.length==0){
                      layer.alert("请先选择");
                      return;
                  }
                  var ids=[];
                  for (var i=0;i<data.length;i++)
                      { 
                          ids.push(data[i].id)
                      }
                   var ids_str=(ids.toString());
              }
            if (obj.event === 'add') {   // 监听添加操作
                addedi("添加<?=$edit[MOD]?>");
            } else if (obj.event === 'addline') {
                  $.post("<?=u("app","index",array("act1"=>"addline"))?>",{}, function(data) {
                    console.log(2222)
                      table.reload("currentTableId")            
                     },"json");
            }else if (obj.event === 'batch_visit') {
                     layer.load(2);
                      $.post("<?=u("app","index",array("act1"=>"batch_visit"))?>",{ids:ids_str}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
                           table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
            }else if (obj.event === 'throwsea') {
                     layer.load(2);
                      $.post("<?=u("app","index",array("act1"=>"throwsea"))?>",{ids:ids_str}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
                           table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
            }else if (obj.event === 'upsea') {
                     layer.load(2);
                      $.post("<?=u("app","index",array("act1"=>"upsea"))?>",{ids:ids_str}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
                           table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
            }else if (obj.event === 'batchupseaother') {
                      layer.load(2);
                      $.post("<?=u("app","index",array("act1"=>"batchupseaother"))?>",{ids:ids_str}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
                           table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
            }  else if (obj.event === 'delete') {  // 监听删除操作

                 layer.confirm('真的批量删除吗', function (index) {
                       layer.load(2);
                      $.post("<?=u(MOD,"del",array("table"=>MOD))?>",{ids:ids_str}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
                           layer.close(index);
                           table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
                });
               
            }
        });

     //监听行双击事件
       
         table.on('rowDouble(currentTableFilter)', function(obj){
               data=obj.data
         
               <? if (MOD=="diao"){?>
                if (data.id>0)
                    addedi("吊卡记录详情",'index.php?mod=diao&act=addedi&id='+data.id)
              <? }?>

               <? if (MOD=="goods"){?>
                if (data.id>0)
                    addedi(data.title+"库存记录",0,'index.php?mod=glog&act=list&goods_id='+data.id)
              <? }?>
             
             


               
          });
     



        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                addedi("修改<?=$name?>",data.id)
                return false;
            }else if (obj.event === 'gl4') {

                 if (data.status==1 || data.status==2 || data.status==6){
                    miniAdmin.error("当前状态你无权限操作");
                    return
                 }
                 addedi("审核费用","","index.php?mod=cost&act=gl4&id="+data.id);
            }else if (obj.event === 'gl5') {
                if (data.status==1 || data.status==2 || data.status==6){
                    miniAdmin.error("当前状态你无权限操作");
                       return
                 }
                 addedi("审核费用","","index.php?mod=cost&act=gl5&id="+data.id);
            }else if (obj.event === 'tb_cw4') {
                 addedi("审核情况","","index.php?mod=taiban&act=cw4&id="+data.id);
            }else if (obj.event === 'tb_cw5') {
                 addedi("审核情况","","index.php?mod=taiban&act=cw5&id="+data.id);
            }else if (obj.event === 'ys_cw6') {
                 addedi("审核情况","","index.php?mod=ys&act=cw6&id="+data.id);
            }else if (obj.event === 'ys_cw7') {
                 addedi("审核情况","","index.php?mod=ys&act=cw7&id="+data.id);
            }else if (obj.event === 'cost_cw6') {
                 addedi("审核情况","","index.php?mod=cost&act=cw6&id="+data.id);
            }else if (obj.event === 'cw6') {
                 addedi("审核情况","","index.php?mod=diao&act=cw6&id="+data.id);
            }else if (obj.event === 'cw7') {
                 addedi("审核情况","","index.php?mod=diao&act=cw7&id="+data.id);
            }else if (obj.event === 'hpyg') {
                 addedi("分配员工","","index.php?mod=income&act=hpyg&id="+data.id);
            }else if (obj.event === 'zpshow') {
                 addedi("应聘详情","","index.php?mod=zp&act=show&id="+data.id);
            }else if (obj.event === 'upseaother') {
                  
                      layer.load(2);
                      $.post("<?=u("app","index",array("act1"=>"upseaother"))?>",{id:data.id}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
    
                            table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
               
            } else if (obj.event === 'delete') {
                  layer.confirm('真的删除么', function (index) {
                    layer.load(2);
                      $.post("<?=u(MOD,"del",array("table"=>MOD))?>",{ids:data.id}, function(data) {
                             layer.closeAll('loading');         
                         if (data.code==0){
                            layer.close(index);
                            table.reload("currentTableId")
                         }else{
                          miniAdmin.error(data.msg);     
                        }
                                   
                     },"json");
                });
            }
        });
       table.on('edit(currentTableFilter)', function(obj){ //
             

               $.post("<?=u("app","index",array("act1"=>"changefield"))?>",{
                id:obj.data.id,
                value:obj.value,
                table:"<?=MOD?>",
                field:obj.field
            }, function(data) {
                 layer.closeAll('loading'); 
                                   
          },"json");
                 
             
          });
     
           


     form.on('switch(showxcx)', function(data){
            
             var id = data.value;
             var status = this.checked ? '2' : '1';       
              $.post("<?=u("app","index",array("act1"=>"changefield"))?>",{
                id:id,
                table:"<?=MOD?>",
                field:"showxcx",
                value:status
             }, function(data) {
                  layer.closeAll('loading');         
                  if (data.code==0){
                      
                    }else{
                          miniAdmin.error(data.msg);     
                    }
                                   
            },"json");
            
        });


    form.on('switch(status)', function(data){
            
             var id = data.value;
             var status = this.checked ? '1' : '2';       
              $.post("<?=u("app","index",array("act1"=>"changefield"))?>",{
                id:id,
                table:"<?=MOD?>",
                field:"status",
                value:status
             }, function(data) {
                  layer.closeAll('loading');         
                  if (data.code==0){
                      
                    }else{
                          miniAdmin.error(data.msg);     
                    }
                                   
            },"json");
            
        });

      form.on('switch(status1)', function(data){
             
             var id = data.value;
             var status = this.checked ? '2' : '1';       
              $.post("<?=u("app","index",array("act1"=>"changefield"))?>",{
                id:id,
                table:"<?=MOD?>",
                field:$(this).attr("field") || "status",
                value:status
             }, function(data) {
                  layer.closeAll('loading');         
                  if (data.code==0){
                    
                    }else{
                          miniAdmin.error(data.msg);     
                    }
                                   
            },"json");
            
        });


     function addedi(title,id,url="",mod=""){
           if (url!="")
               openurl=url
             else
            openurl='index.php?mod=<?=MOD?>&act=addedi&id='+id;

           if (mod=="")
               mod="<?=MOD?>"

          <? if (MOD=="item"){?>
               openurl=openurl+"&categroy=<?=$_GET['categroy']?>"
          <? }?>

           var content = miniPage.getHrefContent(openurl);
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: title,
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] / 2 + 'px', openWH[3] / 2 + 'px'],
                    content: content,
                    end:function(){
                       
                    },
                    success:function(layreo,index){
                        form.on('submit(saveBtn)', function (data) {
                               data.field.table=mod;
                             $.post("<?=u(app,"edit")?>",data.field, function(res) {
                                    layer.closeAll('loading');
                                    if (res.code==0){
                                       layer.close(index);
                                       miniAdmin.success(res.msg)
                                       table.reload("currentTableId")
                                    }else{
                              
                                        miniAdmin.error(res.msg)
                                    }
                          },"json");
            
                       })
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
    }

  <? if (MOD=="company"){?>

       form.on('select(area)', function(data){
              pid=data.value;
             $("#uid").empty();
    
        if (pid==0){
        
         $("#uid").append(' <option value="0">请选择</option>  ');  
         form.render('select');    
         return false
      }
      if (ygs[pid]=="")
           $("#uid").append(' <option value="0">全部</option>  ');
      else{
        $("#uid").append(' <option value="0">全部</option>  ');
        $("#uid").append(ygs[pid]);
      }
     
      //从新刷新了一下下拉框
      form.render('select');      //重新渲染
     });
  
    
  
  
  <?
$sglys=$duoduo->select_all("user","*","role=".AREA);
?>

ygs=Array();
<?
foreach ($sglys as $row){ 

        $ztypes=$duoduo->select_all("user","*","pid=".$row['id']);
    array_unshift( $ztypes,array("id"=>$row['id'],"realname"=>$row['realname']));
      $str="";
  
   foreach ($ztypes as $row1){
     $id=$row1['id'];
     $title=$row1['realname'];
    
     $str.="<option value='$id'>$title</option>";
     } 
?>
ygs[<?=$row['id']?>]="<?=$str?>";

<? }}?>

 
    });
</script>