var TQTDRB = "TQTDRB"; //台区停电日报 var TQTDZB = "TQTDZB"; //台区停电周报 // 拼接报表格式 function reportTable(excelList, typeId, isEdit,isType) { var html = ''; if(isType){ html = ''+excelList[0]+''; } var editHtml; for (var i = 0; i < excelList.length; i ++) { if(isType){ if(i == 0){ continue; } } html += ''; var excelChildList = excelList[i]; for (var j = 0; j < excelChildList.length; j ++) { if (isEdit) { editHtml = ''; } else { editHtml = ''; } html += editHtml + excelChildList[j] + ''; } html += ''; } $("#reportTable").html(html); } /** * 报表变动公共方法 * @param t * @param typeId * @param rowIndex * @param colIndex * @returns */ function reportChange(t, typeId, rowIndex, colIndex) { if (typeId == "TQTDRB") { tableCountTQTDRB(t, typeId, rowIndex, colIndex); } else if (typeId == "TQTDZB") { tableCountTQTDZB(t, typeId, rowIndex, colIndex); } } /** * 台区停电日报表编辑 * @param t * @param typeId * @param rowIndex * @param colIndex */ function tableCountTQTDRB(t, typeId, rowIndex, colIndex) { var tableDom = $(t).parent().parent(); var trsDom = $(tableDom).find("tr"); // 台区数量行 var editNumTds = $($(trsDom)[1]).find("td"); // 停电次数行 var editCountTds = $($(trsDom)[2]).find("td"); // 停电率数行 var editlvTds = $($(trsDom)[3]).find("td"); // 停电三次以上 var sanciTds = $($(trsDom)[4]).find("td"); if ((rowIndex == 1 || rowIndex == 2 || rowIndex == 4) && (colIndex != 0 && colIndex != 9)) { // 修改台区数量 if (rowIndex == 1) { var editNum = $(t).html(); // 对应停电次数 var editCount = $(editCountTds[colIndex]).html(); // 对应停电率 $(editlvTds[colIndex]).html(accMul(accDivFun(editCount, editNum, 4), 100, 2) + "%"); // 台区总数 var totalNum = "0"; for (var i = 1; i < (editNumTds.length - 1); i ++) { totalNum = accAdd($(editNumTds[i]).html(), totalNum); } $(editNumTds[editNumTds.length - 1]).html(totalNum); // 停电总次数 var totalCount = $(editCountTds[editCountTds.length - 1]).html(); $(editlvTds[editlvTds.length - 1]).html(accMul(accDivFun(totalCount, totalNum, 4), 100, 2) + "%"); // 修改台区停电次数 } else if (rowIndex == 2) { var editCount = $(t).html(); // 对应台区数量 var editNum = $(editNumTds[colIndex]).html(); // 对应停电率 $(editlvTds[colIndex]).html(accMul(accDivFun(editCount, editNum, 4), 100, 2)); // 台区总数 var totalNum = $(editNumTds[editNumTds.length - 1]).html(); // 停电总次数 var totalCount = "0"; for (var i = 1; i < (editCountTds.length - 1); i ++) { totalCount = accAdd($(editCountTds[i]).html(), totalCount); } $(editlvTds[editlvTds.length - 1]).html(accMul(accDivFun(totalCount, totalNum, 4), 100, 2) + "%"); } else if (rowIndex == 4) { var sanciCount = "0"; for (var i = 1; i < (sanciTds.length - 1); i ++) { sanciCount = accAdd($(sanciTds[i]).html(), sanciCount); } $(sanciTds[sanciTds.length - 1]).html(sanciCount); } } } /** * 台区停电周报表编辑 * @param t * @param typeId * @param rowIndex * @param colIndex */ function tableCountTQTDZB(t, typeId, rowIndex, colIndex) { var tableDom = $(t).parent().parent(); var trsDom = $(tableDom).find("tr"); // 管理台区总数 、1个月内累计停电台次 、上月累计停电台次、去年同期累计停电台次 合计为相加值 if (colIndex == 1 || colIndex == 2 || colIndex == 3 || colIndex == 4) { // 不是表头也不是合计,需要重新计算合计数 if (rowIndex != 0 && rowIndex != (trsDom.length - 1)) { var heji = "0"; for (var i = 1; i < (trsDom.length - 1); i ++) { var tdsDom = $(trsDom[i]).find("td"); var val = $(tdsDom[colIndex]).html(); heji = accAdd(heji, val, 2); } $($(trsDom[trsDom.length - 1]).find("td")[colIndex]).html(heji); } // 管理台区总数 、1个月内累计停电台次 改变会改变频次 if (colIndex == 1 || colIndex == 2) { // 本身频次改变 var zongtaishu = $($(trsDom[rowIndex]).find("td")[1]).html(); var tingdiantaici = $($(trsDom[rowIndex]).find("td")[2]).html(); var pinci = accDivFun(tingdiantaici, zongtaishu, 2); $($(trsDom[rowIndex]).find("td")[5]).html(pinci); // 合计频次改变 var zongtaishu = $($(trsDom[trsDom.length - 1]).find("td")[1]).html(); var tingdiantaici = $($(trsDom[trsDom.length - 1]).find("td")[2]).html(); var pinci = accDivFun(tingdiantaici, zongtaishu, 2); $($(trsDom[trsDom.length - 1]).find("td")[5]).html(pinci); } } } // excel数据拼接table function initExcelData(excelList, tableId, isEdit,isType) { var html = ''; if(isType){ html = ''+excelList[0]+''; } var tdHtml = ''; if (isEdit) { tdHtml = ''; } for (var i = 0; i < excelList.length; i ++) { if(isType){ if(i == 0){ continue; } } html += ''; var excelChildList = excelList[i]; for (var j = 0; j < excelChildList.length; j ++) { html += tdHtml + excelChildList[j] + ''; } html += ''; } $("#" + tableId).html(html); } /** * 表格数据转成JSON数据 * @param tableId * @returns {Array} */ function getTableToArray(tableId) { var excelList = new Array(); var tableDom = $("#" + tableId); var trsDom = $(tableDom).find("tr"); for (var i = 0; i < trsDom.length; i ++) { var excelChildList = new Array(); var tdsDom = $(trsDom[i]).find("td"); for (var j = 0; j < tdsDom.length; j ++) { excelChildList.push($(tdsDom[j]).html()); } excelList.push(excelChildList); } return excelList; }