//表格-查询
function search(field) {
var where;
if(field==null){
where={
"reportsType": "matchByUnitAndMonth",
"checkStartTime": $('#everyItemOrMatchOrMonthStatistics-form').find('#startTimeEvery').val(),
"checkEndTime": $('#everyItemOrMatchOrMonthStatistics-form').find('#endTimeEvery').val(),
}
}else{
where={
"checkStartTime": field.startTimeEvery,
"checkEndTime": field.endTimeEvery,
"entrustTypeId": field.entrustUnitOut,
"reportsType":field.reportsType
}
}
tableUtils.render({
elem: '#everyItemOrMatchOrMonthStatistics-table',
url: '/statistics/doSearchEveryItemOrMatchOrMonthStatistics', //数据接口
page: false,
totalRow: true,
where:where,
cellMinWidth: 90,
cols: cols(field),
done: function (res, curr, count) {
var arr=new Array();
// 总计格式化
var tableView = this.elem.next();
var totalRow = tableView.find('.layui-table-total');
layui.each(totalRow.find('td'), function (index, tdElem) {
tdElem = $(tdElem);
var text = tdElem.text();
if (text && !isNaN(text)) {
text = parseFloat(text).toFixed(0);
tdElem.find('div.layui-table-cell').html(text);
arr.push(text);
}
});
//合计
var type=$("#reportsType").val();
tableSum(res,arr,tableView,type);
}
});
}
//合计(尿检+血检)
function tableSum(datas,arr,tableView,type){
// var s=datas==null?0:datas.data[0].titleSize;
var tp=0;
if(type=="totalByUnitAndMonth" ||type=="totalByItemAndMonth"){ tp=1; }
var newArr=new Array();
var str="";
if(arr.length>0){
for(var i=0;i<arr.length;i+=2){
if(arr.length>=i+1){
var a=arr[i];
var b=arr[i+1] ;
var c=(a==undefined?0:parseInt(a))+(b==undefined?0:parseInt(b));
newArr.push(c);
console.log(newArr.toString())
}
}
}
//计算宽度
var celSize=arr.length+1;
var hjwidth=1540/celSize;//合计宽度
var celWidth=2*hjwidth;//元素合并宽度
if(newArr.length>0){
for(var j=0;j<newArr.length-1;j++){
str+='<td style="width:'+celWidth+'px;" colspan="2" rowspan="1" data-field="0" data-key="2-0-0" align="center" class="layui-table-col-special">' +
'<div class="layui-table-cell laytable-cell-2-0-0 laytable-cell-numbers">'+newArr[j]+'</div></td>'
}
str+='<td style="width:'+(tp==0?hjwidth:celWidth)+'px;"data-field="0" data-key="2-0-0" align="center" class="layui-table-col-special">' +
'<div class="layui-table-cell laytable-cell-2-0-0 laytable-cell-numbers">'+newArr[j]+'</div></td>'
}
//$("#LAY-advanced-everyItemOrMatchOrMonthStatistics.layui-table-total")
tableView.find('.layui-table-total').append(
'<div class="layui-table-total"><table class="layui-table"><tbody>' +
'<tr>' +
'<td style="width:40px;"data-field="0" data-key="2-0-0" align="center" class="layui-table-col-special">' +
'<div class="layui-table-cell laytable-cell-2-0-0 laytable-cell-numbers"></div></td>' +
'<td style="width:'+hjwidth+'px;"data-field="registerName" data-key="2-0-1" align="center" data-minwidth="160" class="">' +
'<div class="layui-table-cell laytable-cell-2-0-1">合计(尿+血):</div></td>' +
str+
'</tr></tbody></table></div>'
)
}
function cols(field) {
var cols = [];
var reportsType=(field==null?'matchByUnitAndMonth':field.reportsType);
var url= '/statistics/getTitle?reportsType=' +reportsType+
'&checkStartTime='+$('#everyItemOrMatchOrMonthStatistics-form').find('#startTimeEvery').val()+
'&checkEndTime='+$('#everyItemOrMatchOrMonthStatistics-form').find('#endTimeEvery').val()+
'&entrustTypeId='+ $('#everyItemOrMatchOrMonthStatistics-form').find('select[name=entrustUnitOut]').val();
http.get({
url:url,
async: false,
callBack: function (d) {
if (d.status == 0) {
var title = d.entity.title;
cols =[];
var temp1=[]; var temp2=[]; var temp3=[];
if(reportsType=="matchByUnitAndMonth"||reportsType=="outByUnitAndMonth"
||reportsType=="matchByItemAndMonth"||reportsType=="outByItemAndMonth"){
temp1.push({title: '序号', type: 'numbers',align:'center',colspan: 1, rowspan: 2});
if(reportsType=="matchByUnitAndMonth"||reportsType=="outByUnitAndMonth"||reportsType=="totalByUnitAndMonth"){
temp1.push({field: 'registerName', title: '注册单位',align:'center', colspan: 1,rowspan: 2,minWidth:160, totalRowText:'合计:'});
}else if(reportsType=="matchByItemAndMonth"||reportsType=="outByItemAndMonth"||reportsType=="totalByItemAndMonth"){
temp1.push({field: 'twoItemName',title: '项目',align:'center',colspan: 1,rowspan: 2,minWidth:160, totalRowText:'合计:'});
}
if(title.length>0){
title.forEach(function (item) {
temp1.push({title: item+"月", colspan: 2,rowspan: 1,align:'center', totalRow: true});
temp2.push({field: "nj_" + item, colspan: 1, rowspan: 1,title: '尿检', align:'center',totalRow: true});
temp2.push({field: "xj_" + item, colspan: 1,rowspan: 1, title: '血检', align:'center',totalRow: true});
})
}
temp1.push({title: "小计", colspan: 3,rowspan: 1,align:'center', totalRow: true});
temp2.push({field: "allnj", colspan: 1, rowspan: 1,title: '尿检',align:'center', totalRow: true});
temp2.push({field: "allxj", colspan: 1, rowspan: 1,title: '血检',align:'center', totalRow: true});
temp2.push({field: "total" , colspan: 1, rowspan: 1,title: '尿检+血检',align:'center', totalRow: true});
cols.push(temp1)
cols.push(temp2)
}else if(reportsType=="totalByUnitAndMonth"||reportsType=="totalByItemAndMonth"){
temp1.push({title: '序号',type: 'numbers',align:'center',colspan: 1, rowspan: 3});
if(reportsType=="matchByUnitAndMonth"||reportsType=="outByUnitAndMonth"||reportsType=="totalByUnitAndMonth"){
temp1.push({field: 'registerName',title: '注册单位',align:'center', colspan: 1,rowspan: 3,minWidth:160, totalRowText:'合计:'});
}else if(reportsType=="matchByItemAndMonth"||reportsType=="outByItemAndMonth"||reportsType=="totalByItemAndMonth"){
temp1.push({field: 'twoItemName',title: '项目', align:'center',colspan: 1,rowspan:3,minWidth:160, totalRowText:'合计:'});
}
if(title.length>0){
title.forEach(function (item) {
temp1.push({title: item+"月", colspan: 4,rowspan: 1,align:'center', totalRow: true});
temp2.push({ colspan: 2, rowspan: 1,title: '塞内', align:'center',totalRow: true});
temp2.push({ colspan: 2,rowspan: 1, title: '赛外', align:'center',totalRow: true});
temp3.push({field: "in_nj_"+item , colspan: 1, rowspan: 1,title: '尿检', align:'center',totalRow: true});
temp3.push({field: "in_xj_"+item , colspan: 1,rowspan: 1, title: '血检',align:'center', totalRow: true});
temp3.push({field: "out_nj_"+item , colspan: 1, rowspan: 1,title: '尿检',align:'center', totalRow: true});
temp3.push({field: "out_xj_"+item , colspan: 1,rowspan: 1, title: '血检',align:'center', totalRow: true});
})
}
temp1.push({title: "小计", colspan: 6,rowspan: 1,align:'center', totalRow: true});
temp2.push({colspan: 2, rowspan: 1,title: '赛内',align:'center', totalRow: true});
temp2.push({colspan: 2, rowspan: 1,title: '赛外',align:'center', totalRow: true});
temp2.push({colspan: 2, rowspan: 1,title: '赛内+赛外',align:'center', totalRow: true});
temp3.push({field: "innj" ,colspan: 1, rowspan: 1,title: '尿检', align:'center',totalRow: true});
temp3.push({field: "inxj" ,colspan: 1, rowspan: 1,title: '血检', align:'center',totalRow: true});
temp3.push({field: "outnj" ,colspan: 1, rowspan: 1,title: '尿检', align:'center',totalRow: true});
temp3.push({field: "outxj" ,colspan: 1, rowspan: 1,title: '血检', align:'center',totalRow: true});
temp3.push({field: "allnj" ,colspan: 1, rowspan: 1,title: '尿检', align:'center',totalRow: true});
temp3.push({field: "allxj" ,colspan: 1, rowspan: 1,title: '血检', align:'center',totalRow: true});
cols.push(temp1)
cols.push(temp2)
cols.push(temp3)
}
} else {
layer.msg('获取检查类型失败');
}
}
})
return cols
}
//导出测试
form.on('submit(everyItemOrMatchOrMonthStatistics-test2)', function (data) {
var name=getTitleName();//获取标题头
var box=document.getElementsByClassName("layui-table-box")[1].outerHTML;
var total=document.getElementsByClassName("layui-table-total")[1].outerHTML
var html = "<html><head><meta charset='utf-8' /></head><style>table{border:1px;}</style><body> <div align='center'><caption>"+name+"</caption></div>" +box+total + "</body></html>";
var reg1 = new RegExp('border="0" ' ,'g' );//正则替换
var html2=html.replace(reg1,'border="1" ');//全局替换replace不是全局替换,仅仅是单个替换
//console.log("html222222---"+html2)
var blob = new Blob([html2], { type: "application/vnd.ms-excel" });
document.getElementById('id').download=name+".xls"
document.getElementById('id').href= URL.createObjectURL(blob);
});