编辑代码

var ALIGN_LEFT = "left", ALIGN_CENTER = "center", ALIGN_RIGHT = "right", CAMEL_YES = true, CAMEL_NO = false, COL_CAMEL_FLAG = "^C", SORT_YES = true, SORT_NO = false
,ONLY_EXPORT_YES = true,ONLY_EXPORT_NO = false;
var ColInfo = function (title, colName, width, sortFlag, cellAlign, onlyForExport, camelFlag, groupName, dropdownItems) {
  width = new String(width);
  if (width.indexOf("%") == -1) {
    if (width.indexOf("px") == -1) {
      this.width = width + "px";
    }
    else {
      this.width = width;
    }
  }
  else {
    this.width = width;
  }
}

this.colList = 
[
  
];

        let total = 0;
        this.colList.forEach((item) => {
            total += parseInt(item.width.replace("%", ''));
        });
        console.log(total);


// 
let colObj = {};
        //按客户分组
        colObj["基础信息"] = [
            {
                title: "合同<br/>客户简称",
                id: "contractCustomerAbbreviation",
                width: "12%",
                cellAlign: "text-left",
                sort: true,
            }
        ];
        colObj["实际"] = [
            {
                title: "合计",
                id: "receivableNetAmount",
                cellAlign: "text-right",
                width: "auto",
                sort: true,
                showWan: true,
            }, {
                title: "ITO",
                id: "itoReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "职能<br/>HRO",
                id: "shroReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "HRO",
                id: "hroReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "DT",
                id: "dtReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "RPO",
                id: "rpoReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "BPO",
                id: "bpoReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "其他",
                id: "qtReceivableNetAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            },
        ];
        colObj["预测"] = [
            {
                title: "合计",
                id: "receivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "ITO",
                id: "itoReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "职能<br/>HRO",
                id: "shroReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "HRO",
                id: "hroReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "DT",
                id: "dtReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "RPO",
                id: "rpoReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "BPO",
                id: "bpoReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            }, {
                title: "其他",
                id: "qtReceivableNetPredictionAmount",
                cellAlign: "text-right",
                width: "5.5%",
                sort: true,
                showWan: true,
            },
        ];
let total2 = 0;
Object.keys(colObj).forEach(key=>{
    if(Array.isArray(colObj[key])) {
        colObj[key].forEach(item=>{
            if(item.width) {
                let width = parseFloat(item.width.replace('%', ''))
                total2 += width;
            }
        })
    }
});
console.log('==========================')


function roundToHalfStep(num) {
    return Math.round(num * 2) / 2;
}

console.log(roundToHalfStep(2.0)); // 输出 2.5
console.log(roundToHalfStep(2.1)); // 输出 2.5
console.log(roundToHalfStep(2.6)); // 输出 2.5
console.log(roundToHalfStep(3.7)); // 输出 3.5
console.log(roundToHalfStep(3.8)); // 输出 4
console.log(roundToHalfStep(0.3)); // 输出 0.5


 function getDiffMin (startDate, endDate) {
        //获取两个时间差值(毫秒)
        let differentTime = endDate.getTime() - startDate.getTime();
        return this.toFixed(differentTime / 1000 / 60 / 60 / 24);
    }