8.7w+
社区成员
let colArry = [];
let ts_cost = '321##深圳市代理有限公司##{"RMB":"175.00"}||321##深圳市代理有限公司##{"RMB":"175.00"}||321##深圳市代理有限公司##{"RMB":"175.00"}||321##深圳市代理有限公司##{"RMB":"175.00"}';
if(ts_cost && ts_cost !== '') {
const ts_cost_arry = ts_cost.split('||');
let json = {"belong_custom":"", "belong_corp":"", "collection":""};
for(let i=0;i<ts_cost_arry.length;i++){
const [a,b,c] = ts_cost_arry[i].split('##'); //{"RMB":"1111.72","HK":"62.03"}
if(a) {
json.belong_custom = a;
json.belong_corp = b;
json.collection = c;
let find = -1;
console.log(colArry,i);
for (let k = 0,max = colArry.length; k < max; k++) {
if (colArry[k].belong_custom === a && colArry[k].belong_corp === b) {
let oldCol = JSON.parse(colArry[k].collection);
let newCol = JSON.parse(c);
for(let key in newCol){
if(parseFloat(newCol[key])!==0 && newCol.hasOwnProperty(key)){
if(oldCol[key]) {
oldCol[key] = parseFloat(oldCol[key]) + parseFloat(newCol[key]);
}else {
oldCol[key] = newCol[key];
}
}
}
json.collection = JSON.stringify(oldCol);
find = k;
break;
}
}
if(find>=0) colArry.splice(find,1,json);
else colArry.push(json);
colArry[0].title = i;
console.log(colArry,'end');
}
}
}