//隱藏掉code列
hideHeaderCol();
//存放需要計算合計的彙總行集合
var area = [];
$("#yourMind").find("tbody tr").each(function (i) {
var _tr = $(this);
//通過指定標識,查找需要求和的彙總列數據
if (_tr.children('td').eq(0).text().indexOf("_") > 0) {
//樣式設置
_tr.children('td').css("font-weight", "bold");
_tr.children('td').eq(1).css("text-align", "left");
//獲取彙總行的tr
area.push(_tr);
}
});
//遍歷需要計算合計的彙總行數據tr
for (let i = 0; i < area.length; i++) {
//通過彙總行的標識,獲取其下的子客戶的tr
var areaName = area[i].children('td').eq(0).text().split("_")[0];
//當前合計行的td
var tds = area[i].children('td');
var total = 0;
//當前合併行下的子行,通過name屬性
var trArr = $(".children_" + areaName);
//遍歷彙總行的所有td列
//防止數組下標越界
for (let j = 0; j < tds.length - 2; j++) {
//從第二列開始,
var index = j + 2;
//遍歷到當前列的時候,累計其下客戶的當前列的值,做累加和
for (let k = 0; k < trArr.length; k++) {
var tr = trArr[k].children;
//此處獲取值得方式,或許在某種場景下不可用
total += Number(tr[index].textContent != "" ? tr[index].textContent : 0);
}
//將累加結果賦值到當前彙總行的對應的td中
tds.eq(index).text(total * 1 == 0 ? "" : total.toFixed(2));
total = 0;
}
}
function hideHeaderCol() {
$(".trSs th:nth-child(1)").hide();
$(".trTSs th:nth-child(1)").hide();
$("#tMain tbody tr td:nth-child(1)").hide();
}