layui前端框架table表自定义打印事件

      发布在:前端技术      评论:0 条评论
ea.table.render({
toolbar: ['refresh'],
init: init, limit: Number.MAX_VALUE,page: false,
defaultToolbar:['filter',{
title: '自定义打印',
layEvent: 'DIY_PRINT',
icon: 'layui-icon-print',
}],
cols: [[
{search:'<div class="layui-form-item layui-inline"><label class="layui-form-label">月份</label><div class="layui-input-inline"><input id="c-month" name="month" data-date data-date-type="month" class="layui-input" data-search-op="=" value="'+year+'-'+month+'" /></div>',hide:true},
{field: 'username', title: '业务员',search:true},

{field: 'mubiao', title: '月目标()'},
{field: 'money_month', title: '已成交()',templet: function (res,option){
if(res.money_month){
return res.money_month;
}
return 0;
}},
{field: 'freight_month', title: '运费(元)',templet: function (res,option){
if(res.freight_month){
return res.freight_month;
}
return 0;
}},
{field: 'wanchenglv', title: '完成率(%',templet: function (res,option){
if(res.money_month){
wclv=res.money_month/res.mubiao*100;
return wclv.toFixed(2);
}
return 0;
}},
{field: 'number_month', title: '已成交(单)',templet: function (res,option){
if(res.number_month){
return res.number_month;
}
return 0;
}},
{field: 'ticheng', title: '提成点(%',templet: function (res,option){
if(res.ticheng){
return res.ticheng+'%';
}
return '';
}}
]],

done: function(res, curr, count){
if(res.cur_date){
cur_date=res.cur_date;
}
if(count===undefined && res.msg && res.url){
ea.msg.tips(res.msg,1,function (){
window.top.location.href=res.url;
})
}
}
});

ea.listen();
table.on('toolbar(currentTableRenderId_LayFilter)', function (obj) {
// 搜索表单的显示
   switch (obj.event) {
case 'DIY_PRINT':
           //自定义打印处理
           var f = ["<style>", "body{font-size: 12px; color: #666;}", "table{width: 100%; border-collapse: collapse; border-spacing: 0;}", "th,td{line-height: 20px; padding: 9px 15px; border: 1px solid #ccc; text-align: left; font-size: 12px; color: #666;text-align: center;}", "a{color: #666; text-decoration:none;}", "*.layui-hide{display: none}", "</style>"].join("");
v=$($(".layui-table-header").html());
v.append($(".layui-table-main table").html());
v.find("th.layui-table-patch").remove(), v.find(".layui-table-col-special").remove();
var h = window.open("Print_window", "_blank");
h.document.write(f +'<h1 style="text-align: center;">'+cur_date+'员工业绩表<h1>'+ $(v).prop("outerHTML"));
h.document.close();
var allimg = $("img");    //所有的图片
var img_len = allimg.length;
allimg.on('load', function() {
if (!--img_len) {
// 所有图片加载完成则触发打印 解决部分图片不展示问题
h.print();
h.close();
}
});

}
});


相关文章
热门推荐