let arguments =[{"address":"中国","purCompanyName":"广东楷诚纸业有限公司","weightPrintVoList":[{"num":1,"product":"1*3","name":"木卡板-规格1165*935mm","unit2":"kg","width":null},{"num":1,"product":"1*3","name":"木卡板-规格1250*1000mm","unit2":"kg","width":null},{"num":1,"product":"1*2","name":"木卡板-规格1250*1680mm","unit2":"kg","width":null},{"num":1,"product":"1*1","name":"木卡板-规格1250*1830mm","unit2":"kg","width":null}],"companyName":"东莞市横沥彬森木制品经营部","relationId":"1558382786045153281","sendTime":"2022-08-20","countSum":4,"totalSum":9.00,"companyId":null,"createBy":"彭叶强","createTime":"2022-08-20 00:00:00","phone":"0769-38841601","bz":"","purAddress":"广东省东莞市洪梅镇望沙路红梅段66号","id":"1560881650379763714","DetailsList":[{"sizeLength":null,"sizeWidth":null,"purpose":null,"weight":"1*3+","productBz":null,"unit2":"kg","productCount":1,"productName":"木卡板-规格1165*935mm","sendTime":"2022-08-20 00:00:00","number":null,"unit":"池","createBy":"彭叶强","sizeWeight":3.0000000,"sizeOther1":null,"warehousefullName":"辅料仓","totalNum":3.00,"price":32.0000000,"subtotal":"96","bz":"","planId":"1560881650379763714","day":"2022-08-20","squareNum":3.0},{"sizeLength":null,"sizeWidth":null,"purpose":null,"weight":"1*3+","productBz":null,"unit2":"kg","productCount":1,"productName":"木卡板-规格1250*1000mm","sendTime":"2022-08-20 00:00:00","number":null,"unit":"池","createBy":"彭叶强","sizeWeight":3.0000000,"sizeOther1":null,"warehousefullName":"辅料仓","totalNum":3.00,"price":36.0000000,"subtotal":"108","bz":"","planId":"1560881650379763714","day":"2022-08-20","squareNum":3.0},{"sizeLength":null,"sizeWidth":null,"purpose":null,"weight":"1*2+","productBz":null,"unit2":"kg","productCount":1,"productName":"木卡板-规格1250*1680mm","sendTime":"2022-08-20 00:00:00","number":null,"unit":"池","createBy":"彭叶强","sizeWeight":2.0000000,"sizeOther1":null,"warehousefullName":"辅料仓","totalNum":2.00,"price":83.0000000,"subtotal":"166","bz":"","planId":"1560881650379763714","day":"2022-08-20","squareNum":2.0},{"sizeLength":null,"sizeWidth":null,"purpose":null,"weight":"1*1+","productBz":null,"unit2":"kg","productCount":1,"productName":"木卡板-规格1250*1830mm","sendTime":"2022-08-20 00:00:00","number":null,"unit":"池","createBy":"彭叶强","sizeWeight":1.0000000,"sizeOther1":null,"warehousefullName":"辅料仓","totalNum":1.00,"price":103.0000000,"subtotal":"103","bz":"","planId":"1560881650379763714","day":"2022-08-20","squareNum":1.0}]}]
let data = arguments[0]; //获取传入的原始数据
//你的代码,推荐在线编辑器https://jsrun.net/
// 获取当前时间的方法
let t=new Date();
// 组合日期 YYYY - MM - DD
let yeah = t.getFullYear();
let shortYeah = yeah - 2000;
// 因为js中月份的获取是0~11,所以要加一个1
let month = t.getMonth()+1;
let day = t.getDay();
let time = shortYeah + '-' + checkTime(month) + '-' + checkTime(day);
// 把时间加到data中返回
data['time'] = time;
console.log(data['time']);
// 时间处理方法:在小于10的数字前加一个‘0’
function checkTime(i){
if (i<10){
i="0" + i;
}
return i;
}
// 把创建人字段拿出来
let createBy = data["createBy"];
// 把规格详细数据拿出来并组合
let detail = data["DetailsList"];
// 定义分隔符
let pause = '-';
// 解决汇总数据错误问题,更新后可删除1
let totelSquareNum = 0;
for(let i = 0;i < detail.length;i++){
let d = detail[i];
let specification = '';
// 根据宽度、长度、重量组合成规格
// 宽度
if(d['sizeWidth']){
specification = d['sizeWidth'] + 'mm';
};
// 长度
if(d['sizeLength']){
specification = specification + ' * ' + d['sizeLength'] + 'm';
};
// 重量
if(d['sizeWeight']){
specification = specification + ' * ' + d['sizeWeight'] + 'kg';
};
// 解决汇总数据错误问题,更新后可删除2
totelSquareNum = totelSquareNum + d.squareNum;
// 把首个产物的库位拿到外层里
// 只在第一次循环的时候触发
if(i === 0){
data["warehousefullName"] = d['warehousefullName'];
}
data["DetailsList"][i]['specification'] = specification;
// 把创建人字段塞到明细里面去
data["DetailsList"][i]['createBy'] = createBy;
let a = detail[i]['productName'];
if(a.indexOf(pause)!= '-1'){
// 根据分隔符分开字段,并把数组存到m中
m = a.split(pause);
// 把名称里第一部分作为产品名
detail[i]['productName'] = m[0];
// 名称里的其余部分塞到规格数组里面去
for (let index=1;index<m.length;index++)
{
detail[index]['format'+index] = m[index];
}
}
}
// 把汇总字段塞到明细里面去(解决汇总数据错误问题,更新后可删除)
data["totelSquareNum"] = totelSquareNum;
// console.log(data);
console