<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>我的推荐列表</title>
<script type="text/javascript" src="__STATIC__/lib/layui/layui.js"></script>
<link rel="stylesheet" href="__STATIC__/lib/layui/css/layui.css">
<link rel="stylesheet" href="__STATIC__/member/css/recomList.css">
<script type="text/javascript" src="__STATIC__/lib/jquery-1.10.2.js"></script>
</head>
<body>
<div class="big">
<div class="header-container">
<b>用户名:</b>
<input type="text" placeholder="请输入关键字">
<b>邀请码:</b>
<input type="text" placeholder="请输入关键字">
<button>搜索</button>
</div>
</div>
<table id="recomDemo" lay-filter="test" ></table>
<{include file="public/member_footer" /}>
</body>
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit">财务报表</a>
</script>
<script>
//一般直接写在一个js文件中
layui.use(['table','laypage'], function(){
var table = layui.table
,laypage = layui.laypage //分页
//第一个实例
table.render({
elem: '#recomDemo'
,totalRow: true
,url: '<{:url('media/getlist')}>' //数据接口
,page: true //开启分页
,totalRow: true //开启合计行
,method:'post'
,cols: [[ //表头
{type: 'checkbox', fixed: 'left'}
,{field: 'username', title: '用户名', minWidth:120,width:120,align:'center'}
,{field: 'sex', title: '手机号', minWidth:120,align:'center'}
,{field: 'city', title: 'QQ号', minWidth:120,align:'center'}
,{field: 'sign', title: '注册时间', minWidth:200,align:'center'}
,{field: 'experience', title: '账户余额', minWidth:120,align:'center'}//field为对应的数据字段
,{field: 'score', title: '状态', minWidth:80,align:'center'}
,{field: 'classify', title: '会员等级', minWidth:120,align:'center'}
,{field: 'wealth', title: '会员价格', width: 135,align:'center'}
,{field: 'wealth', title: '邀请码', width: 135,align:'center'}
,{fixed: 'right', minWidth:80, align:'center', toolbar: '#barDemo',title: '操作',align:'center'}
]],
parseData: function(res){ //res 即为原始返回的数据 ,当后端返回的数据格式不是layui指定的那种时
return {
"code": 0, //解析接口状态,必须为0
"count": parseInt(res.count), //解析数据长度
"data": res.list //解析数据列表
};
}
});
table.on('tool(test)', function(obj){ //注:tool 是工具条事件名,test 是 table 原始容器的属性 lay-filter="对应的值"
var data = obj.data //获得当前行数据
,layEvent = obj.event; //获得 lay-event 对应的值
if(layEvent === 'edit'){
layer.msg('编辑操作');
}
});
})
</script>
</html>
layui传参到后台
elem: '#table',
height: 450,
url: '/index.php/mill/audit.html' //数据接口
,
where:{page:'1'},
page: true, //开启分页
method: 'post',