Index: ssts-web/src/main/webapp/disinfectsystem/config/zsszyy/print/printConfig.js =================================================================== diff -u -r13379 -r13581 --- ssts-web/src/main/webapp/disinfectsystem/config/zsszyy/print/printConfig.js (.../printConfig.js) (revision 13379) +++ ssts-web/src/main/webapp/disinfectsystem/config/zsszyy/print/printConfig.js (.../printConfig.js) (revision 13581) @@ -763,6 +763,63 @@ } ] } +/** + * 获取大标签中材料的字体大小。需要根据记录数计算大小,同时要考虑材料的名称,如果当前字体下,名称太长导致换行,则认为行数增加 + * @param materials 所有需要打印的材料 + * @param cols 材料的列数 如:名称 数量 名称 数量,这种情况下,cols为2,指一行的记录数 + */ +function getMaterialsFontSize_largeLabel(materials,cols){ + /** + * 计算材料名称列的行数(包括名称和规格) + */ + var nameRows = function(material){ + var temp = material.name; + // 不打印材料 + if (material.specification != null && material.specification != ""){ + temp += "[" + material.specification + "]"; + } + + var nameMaxLenthPerLine = 5; + return Math.ceil(temp.length / nameMaxLenthPerLine) ; // 向上取整 + } + + var materialsAmount = materials.length; + var fontSize = 10; + var rows = Math.ceil(materialsAmount / cols) ; // 向上取整 + var addTotalRow = 0; + for(var row = 0; row < rows;++row){ + var addRow = 0; + var index = cols * row; + while(index < cols){ + if(index < materialsAmount){ + var addRow2 = nameRows(materials[index]); + addRow = (addRow > addRow2)?addRow:addRow2; + } + ++index; + } + addRow = addRow < 1?1:addRow; //至少有一行 + addTotalRow += (addRow - 1); + } + rows += addTotalRow; + if ( rows >= 23){ + fontSize = 6; + }else if(rows >= 18){ + fontSize = 8; + } + else if (rows >= 12){ + fontSize = 9; + } + else if (rows >= 10){ + fontSize = 10; + }else if (rows >= 8){ + fontSize = 11; + }else if (rows >= 6){ + fontSize = 12; + }else if (rows >= 4){ + fontSize = 13; + } + return fontSize; +} //构造表格 function getMaterialsTabHtml_largeLabel(tousse){ //绘制材料明细表格 @@ -779,25 +836,7 @@ var materialsAmount = materials.length; if(materials != null && materialsAmount > 0){ var materialStr = ""; - var fontSize = 10; - var rows = Math.ceil(materialsAmount / 2) ; // 向上取整 - if ( rows >= 23){ - fontSize = 6; - }else if(rows >= 18){ - fontSize = 8; - } - else if (rows >= 12){ - fontSize = 9; - } - else if (rows >= 10){ - fontSize = 10; - }else if (rows >= 8){ - fontSize = 11; - }else if (rows >= 6){ - fontSize = 12; - }else if (rows >= 4){ - fontSize = 13; - } + var fontSize = getMaterialsFontSize_largeLabel(materials,2); // alert(fontSize) materialStr += "