 <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>

    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;
        table.render({
            elem: '#currentTableId',
            toolbar: '#toolbarDemo',
            method: 'post',
            <? if (MOD=="monthsalary" or ACT=="hhrsalary"){?>
            where:{ title:$("#title1").val() },
            <? }?>
            <? if (MOD=="income"){?>
            totalRow: true,
            <? }?>
            defaultToolbar: [],
            url: '<?=u("app","list",array("table"=>MOD))?>',
            cols: cols,
            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;
        });

         // 监听搜索操作
        form.on('submit(import_xls)', function (data) {
           //  layer.load(2);
            data.field.xls=1;
            $.post("index.php?mod=<?=MOD?>&act=list",
              data.field
            , function(res) {
                   layer.closeAll('loading');  
                   if (res.code==0)
                       window.location.href=res.data
                     else
                       miniAdmin.error(res.msg)
            },"json");

          
        });
       
        /**
         * toolbar事件监听
         */
          // 监听搜索操作
     


        table.on('toolbar(currentTableFilter)', function (obj) {

            if (obj.event === 'add') {   // 监听添加操作
                
                addedi("添加<?=$edit[MOD]?>");
            } else if (obj.event === 'delete') {  // 监听删除操作
             
                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());

                 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('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                addedi("修改<?=$name?>",data.id)
                return false;
            }else if (obj.event === 'hphhr') {
                 addedi("分配合伙人","","index.php?mod=income&act=hphhr&id="+data.id);
            }else if (obj.event === 'hpyg') {
                 addedi("分配员工","","index.php?mod=income&act=hpyg&id="+data.id);
            } 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){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
           if(isNaN(obj.value)){
               miniAdmin.error("输入值须为数字");return;
          }
             
               
            $.post("<?=u("app","index",array("act1"=>"changefield"))?>",{
                id:obj.data.id,
                value:obj.value,
                table:"<?=MOD?>",
                field:obj.field
            }, function(data) {
                 layer.closeAll('loading');
                 <? if (MOD=="order" or MOD=="monthsalary"){?>
                    table.reload("currentTableId")
                 <? }?>          
                                   
          },"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){
                      layer.close(index);
                    }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:"status",
                value:status
             }, function(data) {
                  layer.closeAll('loading');         
                  if (data.code==0){
                      layer.close(index);
                    }else{
                          miniAdmin.error(data.msg);     
                    }
                                   
            },"json");
            
        });
     function addedi(title,id,url=""){
           if (url!="")
               openurl=url
             else
            openurl='index.php?mod=<?=MOD?>&act=addedi&id='+id;
           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(){
                       <? if (MOD=="order"){?>
                        setCookie("sdata", "", -1);
                       <? }?> 
                    },
                    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);
                });
    }

    });
</script>