js Map的使用
阅读原文时间:2023年07月10日阅读:1

setExpenseAndAmountSum: function() {

            var detailList = vehicleVueObj.vehicleData;  
            var expenseAmountSum = "";//报销金额  
            var expenseAmountMap = new Map();//存放key为币种符号,value为报销某一币种的合计  
            var invoiceCountSum = 0;  

// var expenseAmountTotalMap = new Map();
if (detailList != undefined && detailList.length > 0){
for (var i = 0;i < detailList.length;i++) {
if(detailList[i]!=null){
//报销金额总和
var currencyNo = detailList[i]["currencySymbol"];//币别符号
var expenseAmount = detailList[i]["expenseAmount"];//报销金额
if(!detailList[i]["ifSettlement"]){ //去掉 统一结算的情况
var travelExpenseAmountTotal = Supp.Util.add(Number(expenseAmountMap.get(currencyNo) || 0) , Number(expenseAmount));
if(currencyNo!=null){
expenseAmountMap.set(currencyNo,travelExpenseAmountTotal);
}
}

                        //票据的总数量  
                        var invoiceCount = detailList\[i\]\["invoiceCount"\];  
                        if(!isNaN(invoiceCount) && invoiceCount != "") {  
                            invoiceCountSum = Supp.Util.add(invoiceCountSum,invoiceCount);  
                        }  
                        vehicleVueObj.titleSumData\["invoiceCountSum"\] = invoiceCountSum;  
                    }  
                }  
            }

            //报销金额总和  
            if (expenseAmountMap != undefined && expenseAmountMap.size > 0) {  
                var varEntries = expenseAmountMap.entries();  
                var keyPairList = \[\];  
                for (var k = 0;k < 50;k++) {  
                    keyPairList.push(varEntries.next().value);  
                }

                for (var indexPair = 0;indexPair < keyPairList.length; indexPair++) {  
                    if(keyPairList\[indexPair\] != undefined){  
                        var keyPair =  keyPairList\[indexPair\];  
                        var bibie = keyPair\[0\];  
                        var money = keyPair\[1\];  
                        expenseAmountSum += bibie + money + " ";  
                    }

                }

                vehicleVueObj.titleSumData\["expenseAmountSum"\] = expenseAmountSum;  
            }  
        }