<script type="text/html" id="toolbar">
  <span class="data-attr-{{ $dataId }}" style="display:none" @verbatim{{#  layui.each(d, function(index, item){ }}data-{{ index }}="{{ item }}"{{#  }); }}@endverbatim ></span>
 @if($dataToolBar!=-1)
  @foreach ($dataToolBar as $tool)
    <a class="layui-btn layui-btn-sm {{ $tool }}"  lay-event="detail"  pid="{{ $primaryKey }}"  uri="/{{S('MODULE')}}/{{S('CONTROLLER')}}/{{$tool}}/?{{$primaryKey}}=" href="/{{S('MODULE')}}/{{S('CONTROLLER')}}/{{$tool}}/?{{$primaryKey}}=@verbatim{{ d.@endverbatim {{$primaryKey}} @verbatim}}@endverbatim">@if (trans($dataTableLang.'.'.$tool)==$dataTableLang.'.'.$tool) {{ trans('common.'.$tool) }}  @else {{ trans($dataTableLang.'.'.$tool) }}   @endif</a>

  @endforeach
 @endif

</script>
<table class="layui-hide" id="{{ $dataId }}" lay-filter="{{ $dataId }}"></table>

<style>
.layui-table-view .layui-table {
    position: relative;
    width: 100%;
    margin: 0px;
}
  .layui-form{
    height: auto !important;
  }
  .layui-table-cell{
    padding: 0px 12px;
  }
</style>
<script>

function loadCols()
{
  var cols= @json($dataCols);
  try{
    cols=optCols($cols);
  }catch(ex){
  }
  return cols;
}
function loadData(){
  return ;
}

/**
* 初始化where条件
**/
function initLoadWhere(){
  var list={};
  $('*[eventType=event-query]').each(function(index,item){
    var field=$(this).attr('name');
    var value=$(this).val();
    try{
      list[field]=filterWhere(field,value);
    }catch(ex){
      list[field]=value;
    }
    list[field]=value;
  });
  return list;
}
var tab;
var pid='{{ $primaryKey }}';
layui.use(['table','form','tree','laydate'], function(){
      table = layui.table ,
      form = layui.form,
      laydate = layui.laydate //日期;

  //展示已知数据
  var tableIns=table.render({
    elem: '#{{ $dataId }} '
   // ,height: 'full-150'
    // ,cellMinWidth: 100
    ,cellMinWidth: 50
    ,url:'{!! $dataUri !!}'
    ,where:initLoadWhere()
    ,cols:loadCols()
    ,cellMinWidth: 80
    //,skin: 'line' //表格风格
    ,even: true
    ,id:'{{ $dataId }}'
    ,page: true //是否显示分页
    ,limits: [5, 7, 10,20,30,50,100,200,500,1000,2000]
    ,limit: 50 //每页默认显示的数量
    ,done: function(res, curr, count){
        
//          var width = $('.layui-table').find('th .layui-table-cell').width();
//
//          width = parseFloat(width);
//          $('.layui-table').find('.layui-table-cell').width(width-3)
      try{
        dataTableLoadFinished(res,curr,count);
      }catch(ex){}
      tab=tableIns;
    }
  });
table.on('sort({{ $dataId }})', function(obj){
  table.reload('{{ $dataId }}', {
     page: {
          curr: 1 //重新从第 1 页开始
        }
    ,initSort: obj
    ,where: {
      field: obj.field
      ,order: obj.type
    }
  });
});
 table.on('edit({{ $dataId }})', function(obj){
    var value = obj.value //得到修改后的值
    ,data = obj.data //得到所在行所有键值
    ,field = obj.field; //得到字段
    try{
      editlineOpt(data.id,field,value);
    }catch(ex){
      editLine('/{{S('MODULE')}}/{{S('CONTROLLER')}}/editCols?id='+data.id+'&field='+field+'&value='+value,'{{ trans("common.editline") }}');
    }
  });
  form.on('switch({{ $dataId }})', function(obj){
    try{
      switchOpt(obj);
    }catch(ex){}
  });
  form.on('checkbox({{ $dataId }})', function(obj){
    try{
      checkboxOpt(obj);
    }catch(ex){}
  });

  table.on('checkbox({{ $dataId }})', function(obj){
    if(g.currentDataTableIdArray==undefined){
      g.currentDataTableIdArray=[];
    }
    if(obj.checked){
      if(obj.type=='all'){
        var checkStatus = table.checkStatus('{{ $dataId }}'),data = checkStatus.data;
        for (x in data)
        {
          g.currentDataTableIdArray.push(data[x][pid]);
        }

      }else{
         g.currentDataTableIdArray.push(obj.data[pid]);
      }

    }else{
      var id=obj.data[pid];
      var index=$.inArray(id,g.currentDataTableIdArray);
      if(index!=-1){
        g.currentDataTableIdArray.splice(index,1);
      }
    }
    g.currentDataTableIds=g.currentDataTableIdArray.join(',');
    console.log(g.currentDataTableIds);
  });

    //获取今日号
    var data=new Date();
    var m=data.getMonth();
    m=m+1;
    var d=data.getDate();
    var y=data.getFullYear();
    var now=y+'-'+m+'-'+d;
    var obj='{"'+now+'":"今天"}';
    var obj=JSON.parse(obj);
    //同时绑定多个
    lay('.test-item').each(function(){
        laydate.render({
            elem: this
            ,type: 'date'
            ,trigger: 'click'
            ,btns:['now']
            ,mark:obj
            ,done: function(value, date){
                $('.lay-btn-diy').click();
            }
        });
    });

  @stack('dataTableJS')
  g.currentDataTable=table;

  var _dataTableReload = {
      reload: function(){
        //执行重载
        table.reload('{{ $dataId }}', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: initLoadWhere()
        });
      }
    };
  g.currentDataTableReload=_dataTableReload;
  $('*[eventType=event-query-submit]').on('click', function(){
     $('*[eventType=eventForm]').submit();
      // _dataTableReload['reload'] ? _dataTableReload['reload'].call(this) : '';
   }); 
  function tableReload(obj){
    _dataTableReload['reload'] ? _dataTableReload['reload'].call(null) : '';
  }

});


</script>
