//我是输入,替换 = 后面的就行
var str = [{"company":"两湖街道办","classes":"国家级"},{"company":"两湖街道办","classes":"处级"},{"company":"两湖街道办","classes":"省部级"},{"company":"两湖街道办","classes":"省部级"},{"company":"朱曲镇","classes":"县处级"},{"company":"朱曲镇","classes":"县处级"},{"company":"蔡庄镇","classes":"县处级"},{"company":"永兴镇","classes":"县处级"},{"company":"张市镇","classes":"市厅级"},{"company":"张市镇","classes":"县处级"},{"company":"张市镇","classes":"县处级"},{"company":"十八里镇","classes":"县处级"},{"company":"十八里镇","classes":"市厅级"},{"company":"十八里镇","classes":"县处级"},{"company":"水坡镇","classes":"县处级"},{"company":"水坡镇","classes":"市厅级"},{"company":"邢庄乡","classes":"县处级"},{"company":"邢庄乡","classes":"市厅级"},{"company":"庄头镇","classes":"市厅级"},{"company":"门楼任乡","classes":"县处级"},{"company":"门楼任乡","classes":"县处级"},{"company":"门楼任乡","classes":"县处级"},{"company":"门楼任乡","classes":"县处级"},{"company":"大桥乡","classes":"县处级"},{"company":"大桥乡","classes":"县处级"},{"company":"小陈乡","classes":"市厅级"},{"company":"小陈乡","classes":"县处级"},{"company":"先进制造业开发区","classes":"市厅级"},{"company":"先进制造业开发区","classes":"市厅级"},{"company":"先进制造业开发区","classes":"市厅级"},{"company":"检察院","classes":"县处级"},{"company":"宣传部","classes":"县处级"},{"company":"宣传部","classes":"市厅级"},{"company":"宣传部","classes":"市厅级"},{"company":"政法委","classes":"市厅级"},{"company":"总工会","classes":"县处级"},{"company":"总工会","classes":"县处级"},{"company":"政数局","classes":"县处级"},{"company":"县志办","classes":"县处级"},{"company":"农业农村局","classes":"市厅级"},{"company":"农业农村局","classes":"市厅级"},{"company":"水利局","classes":"县处级"},{"company":"水利局","classes":"县处级"},{"company":"农机中心","classes":"市厅级"},{"company":"科工信局","classes":"市厅级"},{"company":"公路局","classes":"县处级"},{"company":"发改委","classes":"市厅级"},{"company":"发改委","classes":"县处级"},{"company":"发改委","classes":"县处级"},{"company":"重点项目办","classes":"县处级"},{"company":"重点项目办","classes":"县处级"},{"company":"城管局","classes":"县处级"},{"company":"税务局","classes":"县处级"},{"company":"司法局","classes":"县处级"},{"company":"教体局","classes":"市厅级"},{"company":"卫健委","classes":"县处级"},{"company":"卫健委","classes":"县处级"},{"company":"卫健委","classes":"县处级"},{"company":"医保局","classes":"市厅级"},{"company":"社保中心","classes":"县处级"},{"company":"机关事务中心","classes":"县处级"},{"company":"交通运输局","classes":"县处级"},{"company":"生态环境局","classes":"县处级"},{"company":"生态环境局","classes":"市厅级"},{"company":"供电公司","classes":"县处级"},{"company":"供电公司","classes":"县处级"},{"company":"文广旅局","classes":"县处级"},{"company":"人武部","classes":"市厅级"},{"company":"人武部","classes":"市厅级"},{"company":"发改委","classes":"市厅级"},{"company":"市场监管局","classes":"县处级"},{"company":"市场监管局","classes":"县处级"},{"company":"市场监管局","classes":"县处级"},{"company":"市场监管局","classes":"国家级"}]
var AREA_MONEY = 3
ResultData = function (id, company, countryTimes,countryMoney,
proviceTimes, proviceMoney, cityTimes,
cityMoney, areaTimes, areaMoney) {
this.id = id;
this.company = company;
this.countryTimes = countryTimes;
this.countryMoney = countryMoney;
this.proviceTimes = proviceTimes;
this.proviceMoney = proviceMoney;
this.cityTimes = cityTimes;
this.cityMoney = cityMoney;
this.areaTimes = areaTimes;
this.areaMoney = areaMoney;
}
var resultDatas = new Array;
var admirDatas = str;
var itemId = 0, countryTime = 0,countryMoney = 0,provicetime = 0, citytime = 0, areatime = 0
, proviceMoney = 0, cityMoney = 0, areaMoney = 0;
for (var i = 0; i < admirDatas.length; i++) {
if (i == 0) {
itemId++;
if (admirDatas[i].classes == "国家级") {
countryTime++;
countryMoney = admirDatas[i].money;
} else if (admirDatas[i].classes == "省部级" || admirDatas[i].classes == "部级" ) {
provicetime++;
proviceMoney = admirDatas[i].money;
} else if (admirDatas[i].classes == "市厅级" || admirDatas[i].classes == "厅级" ) {
citytime++;
cityMoney = admirDatas[i].money;
} else if (admirDatas[i].classes == "县处级" || admirDatas[i].classes == "处级") {
areatime++;
areaMoney = AREA_MONEY;
}
var resultdata = {
id: itemId,
company: admirDatas[i].company,
countryTimes:countryTime,
countryMoney:countryMoney,
proviceTimes: provicetime,
proviceMoney: proviceMoney,
cityTimes: citytime,
cityMoney: cityMoney,
areaTimes: areatime,
areaMoney: areaMoney
};
resultDatas.push(resultdata)
countryTime = 0
provicetime = 0
citytime = 0
areatime = 0
countryMoney = 0
proviceMoney = 0
cityMoney = 0
areaMoney = 0
}
if (i > 0) {
if (admirDatas[i].company == admirDatas[i - 1].company) {
if (admirDatas[i].classes == "国家级") {
resultDatas[resultDatas.length - 1].countryTimes++;
resultDatas[resultDatas.length - 1].countryMoney = resultDatas[resultDatas.length - 1].countryMoney + admirDatas[i].money;
}else if (admirDatas[i].classes == "省部级" || admirDatas[i].classes == "部级" ) {
resultDatas[resultDatas.length - 1].proviceTimes++;
resultDatas[resultDatas.length - 1].proviceMoney = resultDatas[resultDatas.length - 1].proviceMoney + admirDatas[i].money;
} else if (admirDatas[i].classes == "市厅级" || admirDatas[i].classes == "厅级" ) {
resultDatas[resultDatas.length - 1].cityTimes++;
resultDatas[resultDatas.length - 1].cityMoney = resultDatas[resultDatas.length - 1].cityMoney + admirDatas[i].money;
} else if (admirDatas[i].classes == "县处级" || admirDatas[i].classes == "处级" ) {
resultDatas[resultDatas.length - 1].areaTimes++;
resultDatas[resultDatas.length - 1].areaMoney = resultDatas[resultDatas.length - 1].areaMoney + AREA_MONEY;
}
} else {
itemId++;
if (admirDatas[i].classes == "国家级") {
countryTime++;
countryMoney = admirDatas[i].money;
}else if (admirDatas[i].classes == "省部级" || admirDatas[i].classes == "部级" ) {
provicetime++;
proviceMoney = admirDatas[i].money;
} else if (admirDatas[i].classes == "市厅级" || admirDatas[i].classes == "厅级" ) {
citytime++;
cityMoney = admirDatas[i].money;
} else if (admirDatas[i].classes == "县处级" || admirDatas[i].classes == "处级" ) {
areatime++;
areaMoney = AREA_MONEY;
}
var resultdata = {
id: itemId,
company: admirDatas[i].company,
countryTimes:countryTime,
countryMoney:countryMoney,
proviceTimes: provicetime,
proviceMoney: proviceMoney,
cityTimes: citytime,
cityMoney: cityMoney,
areaTimes: areatime,
areaMoney: areaMoney
};
resultDatas.push(resultdata)
countryTime = 0
provicetime = 0
citytime = 0
areatime = 0
countryMoney = 0
proviceMoney = 0
cityMoney = 0
areaMoney = 0
}
}
}
document.write(
JSON.stringify(resultDatas))
console