layui框架的动态tab切换

时间:2025-05-12 09:34:49
  • layui.use(['table','layer','element'], function(){
  • var table = layui.table;
  • var layer=;
  • var element=;
  • if(("status")==null){
  • ("status", '1');
  • }
  • getList('#fourFile_not',("status"));
  • //tab点击选择不同项时带过来的值,docDemoTabBrief是div中lay-filter的值
  • element.on('tab(docDemoTabBrief)', function(data){
  • var status = $(this).attr('application_status');
  • ("status", status);
  • var position = '#fourFile_not'
  • switch (("status")) {
  • case '1': position = '#fourFile_not'; break;
  • case '2': position = '#fourFile_have'; break;
  • case '3': position = '#fourFile_all'; break;
  • default: position = '#fourFile_not';
  • }
  • getList(position, ("status"));
  • });
  • function getList(position,status){//table数据来源
  • $(".layui-tab-title li").eq(Number(("status"))-1).addClass("layui-this").siblings().removeClass("layui-this");
  • table.render({
  • elem: position,
  • url: '', //路径写自己后台的
  • //method: 'get',
  • id: 'datareload',
  • cellMinWidth: 95,
  • page: {theme: '#009688', hash: 'page',curr: location.hash.replace('#!page=', '')},
  • //height: 'full-125',
  • limit: 20,
  • limits: [20,20,100,200],
  • //where: {state: 0},
  • request: {
  • pageName: 'pageNo' ,//页码的参数名称,默认:page
  • limitName: 'pageSize' //每页数据量的参数名,默认:limit
  • }
  • ,parseData: function(res){ //res 即为原始返回的数据
  • }
  • ,cols: [[ //表头
  • {title: '序号',templet: '#indexTpl',width: 50}
  • ,{field: 'name', title: '姓名', width: 220, sort: true}
  • ,{field: 'phone', title: '电话', width: 100,sort: true}
  • ,{field: 'age', title: '年龄', width: 200,sort: true}
  • ,{field: 'id', title: '操作', width: 300,sort: true,templet:function(d){
  • return "<button class='layui-btn' style='height:28px;line-height:28px;' onclick=look(\""++"\")>详情</button>";
  • }}
  • ]]
  • });
  • //搜索
  • var active = {
  • reload: function () {
  • //执行重载
  • table.reload('datareload', {
  • page: {
  • curr: 1 //重新从第 1 页开始
  • }
  • , where: {
  • name:$("#name").val() //搜索时传的参和值
  • }
  • });
  • }
  • };
  • $('#search').on('click', function () {
  • var type = $(this).data('type');
  • active[type] ? active[type].call(this) : '';
  • });
  • }
  • });