// 合计
const getSummaries = (param)=> {
const { columns, data } = param
const sums = []
const re = /(\d{1,3})(?=(\d{3})+(?:\.))/g;
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = `${data.length}条记录`
return
}
if(column.property == 'current_weight' || column.property == 'gross_weight' || column.property == 'tare_weight' || column.property == 'net_weight' ){
const values = data.map((item) => parseFloat(delcommafy(item[column.property])))
sums[index] = `${values.reduce((prev, curr) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)}`
//转换为千分位
sums[index] = parseFloat(sums[index]).toLocaleString('en-US')
}
})
return sums
}
// 千分位字符串转数字
const delcommafy = (num)=>{
//确保num是字符串
num = num.toString()
if(num.indexOf(",") != -1){
num=num.replace(/,/gi,'');
return num;
}else{
return num;
}
}