1、想要的理想行数据:
{
"info": [
{
"ydccId": "c68491ba2e4f4187b35cfdc2db58bf40",
"carId": "09d160b6e03343d2bafefcbb0be94e89",
"costInfo": [
{
"id": "13f532f978214523a2855245a1310709",
"amount": 300
},
{
"id": "953dd3dbba5d4cb79947d67829a55e2f",
"amount": 200
}
]
}
]
}
2、原始的数据:
{
"code": 200,
"data": {
"data": [
{
"profitTime": "1593532800000",
"niaosuData": [],
"recProvinceName": "天津",
"goumaihaocai": 0,
"QingGuanData": [],
"zhuangxiexiaofei": 0,
"goumaihaocaiData": [],
"zhengjianfuyinfeiData": [],
"carNo": "陕FAV866",
"kaikafei": 0,
"id": "3effafbd10ae4792938661e560cd7653",
"QingGuan": 0,
"goodsName": "环己烷",
"baoyangfeiData": [],
"QianFengData": [],
"SiJiTiChengData": [],
"ZheJieData": [],
"GongZi": 0,
"WeixiuData": [
{
"amount": 200,
"id": "7b43dc3b298f48dca1dd868463972f14",
"status": 3
}
],
"kaipiaofeiData": [],
"dachefei": 0,
"carId": "09d160b6e03343d2bafefcbb0be94e89",
"xianchangfakuan": 0,
"zhuangxiexiaofeiData": [],
"GuoBangData": [],
"BaoXianData": [],
"kaikafeiData": [],
"sendProvinceName": "北京",
"Weixiu": 200,
"zhusu": 0,
"costSum": 761.89,
"GuoBang": 0,
"TingChe": 0,
"recCityCode": "120112",
"LuQiao": 0,
"BaoXian": 0,
"sendCityCode": "110114",
"loadGoodsTime": "1594894310825",
"shenghuofeiData": [
{
"amount": 400,
"id": "a7cd2d87d2b84cb087348cdd62ce09d1",
"status": 3
}
],
"ydccNum": 10,
"SiJiTiCheng": 0,
"unloadGoodsTime": "1594894322295",
"xichefei": 40,
"RanYouData": [
{
"amount": 121.89,
"id": "85b77fc57a71465cbf8bbdd3b181b836",
"status": 3
}
],
"ZheJie": 0,
"RanYou": 121.89,
"JiaoTongFaKuan": 0,
"LuQiaoData": [],
"baoyangfei": 0,
"QianFeng": 0,
"zhengjianfuyinfei": 0,
"isClose": 0,
"shenghuofei": 400,
"niaosu": 0,
"dachefeiData": [],
"QiTa": 0,
"ydccNo": "CC200716165201519",
"JiaoTongFaKuanData": [],
"zhusuData": [],
"TingCheData": [],
"butaiData": [],
"maigongjufeiData": [],
"butai": 0,
"GongZiData": [],
"QiTaData": [],
"maigongjufei": 0,
"kaipiaofei": 0,
"xianchangfakuanData": [],
"xichefeiData": [
{
"amount": 40,
"id": "c58e50d4e8014872926a8b4de8520102",
"status": 3
}
]
}
],
"pageNo": 1,
"totalPage": 1,
"pageSize": 10,
"totalCount": 1
},
"dtl": "",
"ext": {
"costItemData": [
{
"itemName": "工资",
"itemKey": "GongZi"
},
{
"itemName": "蒸、洗罐",
"itemKey": "QingGuan"
},
{
"itemName": "司机提成",
"itemKey": "SiJiTiCheng"
},
{
"itemName": "现场罚款",
"itemKey": "xianchangfakuan"
},
{
"itemName": "打车费",
"itemKey": "dachefei"
},
{
"itemName": "过磅",
"itemKey": "GuoBang"
},
{
"itemName": "购买耗材",
"itemKey": "goumaihaocai"
},
{
"itemName": "折旧",
"itemKey": "ZheJie"
},
{
"itemName": "铅封",
"itemKey": "QianFeng"
},
{
"itemName": "开卡费",
"itemKey": "kaikafei"
},
{
"itemName": "开票费",
"itemKey": "kaipiaofei"
},
{
"itemName": "装卸小费",
"itemKey": "zhuangxiexiaofei"
},
{
"itemName": "交通罚款",
"itemKey": "JiaoTongFaKuan"
},
{
"itemName": "证件复印费",
"itemKey": "zhengjianfuyinfei"
},
{
"itemName": "保险",
"itemKey": "BaoXian"
},
{
"itemName": "过路、桥费",
"itemKey": "LuQiao"
},
{
"itemName": "买工具费",
"itemKey": "maigongjufei"
},
{
"itemName": "燃油",
"itemKey": "RanYou"
},
{
"itemName": "其他",
"itemKey": "QiTa"
},
{
"itemName": "停车费",
"itemKey": "TingChe"
},
{
"itemName": "住宿",
"itemKey": "zhusu"
},
{
"itemName": "洗车费(外观)",
"itemKey": "xichefei"
},
{
"itemName": "保养费",
"itemKey": "baoyangfei"
},
{
"itemName": "补胎",
"itemKey": "butai"
},
{
"itemName": "尿素",
"itemKey": "niaosu"
},
{
"itemName": "生活费",
"itemKey": "shenghuofei"
},
{
"itemName": "维修费",
"itemKey": "Weixiu"
}
]
},
"msg": ""
}
3、方法如下:
const data = []
const dataList = this.selectedRows //选中的数据
let costData = []
let costItemData = res.data.ext.costItemData
costItemData.map(o => {
costData.push({
itemKey: o.itemKey + 'Data'
})
})
for (let i = 0; i < dataList.length; i++) {
let dataObj = dataList[i]
let dataArr = []
for (let j = 0; j < costData.length; j++) {
if (dataObj[costData[j].itemKey].length != 0) {
dataObj[costData[j].itemKey].map(o => {
if (o.status == 3) {
dataArr.push({
id: o.id,
amount: o.amount
})
}
})
}
}
data.push({
ydccId: dataList[i].id,
carId: dataList[i].carId,
costInfo: dataArr
})
}
console.log(data)
4、来了就点个赞👍呗。。。