layui table
//JavaScript代码区域
var basepath='<%=basePath%>';
$(function(){
pageQuery(1);
});
layui.use('element', function(){
var element = layui.element;
});
//时间日期选择开始//
layui.use('laydate', function(){
var laydate = layui.laydate;
//双控件
laydate.render({
elem: '#test1' //指定元素
,type: 'datetime'
,trigger: 'click'
,lang: 'en'
//,lang: 'en'
,range: true //开启日期范围,默认使用“_”分割
,done: function(value, date, endDate){
console.log(value, date, endDate);
}
,change: function(value, date, endDate){
console.log(value, date, endDate);
}
});
//<strong>同时绑定多个</strong>
lay('.test-item').each(function(){
laydate.render({
elem: this
,trigger: 'click'
});
});
});
//时间日期选择结束//
//分页开始//
//分页器
var dataObj = {
page_enterprise : 1,
//选择每页显示的数据条数
limit_enterprise: 10,
};
function pageQuery(pageno,unitNameOrPhone) {
var unitNameOrPhone=$("input[name='unitNameOrPhone']").val();
var startTime=$("input[name='startTime']").val();
var endTime=$("input[name='endTime']").val();
var checkList = [];
layui.use('table', function(){
var table = layui.table;
table.render({
elem: '#layui-table'
,method:'POST'
,contentType: 'application/json; charset=UTF-8'
,url: basepath+'info/queryParameter.do?unitNameOrPhone='+unitNameOrPhone+'&startTime='+startTime+'&endTime='+endTime
,cols: [[
{checkbox : true, width: 40,}
,{field:'regTime', width: 110, title: '登记时间'}
,{field:'unitName', width:147, title: '单位名称'}
,{field:'addr', width: 80, title: '地区'}
,{field:'dueTime', title: '到期时间', width: 110}
,{field:'webCount', width:80, title: '网站数'}
,{field:'phone', width:120, title: '联系电话'}
,{field:'email', width:120, title: '邮箱'}
,{field:'linkMan', width:80, title: '联系人'}
,{field:'lastreqtime', width:100, title: '最近推送'}
,{field:'state', width:80, title: '状态'}
]]
,page: true
});
//监听表格复选框选择
table.on('checkbox(demo)', function(obj){
if (obj.type == 'all') {
checkList.push('all');
} else {
if(obj.checked) {
checkList.push(obj.data);
} else {
var _index = checkList.indexOf(obj.data);
checkList.splice(_index, 1);
}
}
});
var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
//触发事件
var active = {
test5: function(){
layer.open({
title:'新增服务单位信息',
type: 2,
skin: 'layui-layer-rim',
area: ['700px', '420px'],
content: 'info/newadd.do'
});
},
test6: function(){ //修改
if(checkList.length==1 && checkList[0]!='all' ){
layer.open({
title : '修改单位信息',
type : 2,
skin : 'layui-layer-rim',
area : [ '700px', '420px' ],
content : 'info/newupdate.do?id='+checkList[0].id
});
} else {
layer.alert('请勾选一条数据');
}
},
test7 : function() { //删除
if(checkList.length==1 && checkList[0]!='all' ){
layer.confirm('确定要删除'+checkList.length+'条数据?', {
btn: ['确定','取消'], //按钮
}, function(){
layer.alert('删除成功');
ajaxDelete(checkList[0].id);
});
}else{
layer.alert('请勾选一条数据');
}
}
};
$('.demo').on('click', function() {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
});
}
function ajaxDelete(id){
$.ajax({
url :basepath+'info/deleteUnitInfo.do?id='+id,
type : "post",
dataType : 'json',
success : function(result){
if (result.msg) {
layer.msg("删除成功");
window.parent.location.reload();
}else {
layer.msg("删除失败");
}
}
});
}
layui默认get请求,后台必须进行编码转换:
String unitName =new String(request.getParameter("unitName").getBytes("ISO-8859-1"), "utf-8");