let arguments = [{ "address": null, "purCompanyName": "广州市盈信纸业有限公司", "companyName": "测试委外", "paymentBz": null, "openAccountBank": null, "taxRate": null, "companyId": "1592456225243058177", "createBy": "administrator", "planNum": "1100036", "creditCode": null, "createTime": "2022-11-23 16:41:40", "companyPhone": null, "phone": "02084305189", "subtotal": 500.0000000, "companyAddress": null, "bz": "", "faxNumber": null, "purAddress": "广东省广州市白云区钟落潭镇马新路140号301", "deliveryDate": null, "squareNum": 500.00000000000000, "contacts": null, "bankCardCode": null, "DetailsList": [{ "companyName": "测试委外", "unit2": "kg", "productCount": 1.0000000, "warehouseName": null, "number": null, "sizeOther1": null, "price": 1.0000000, "bz": "gg:23*1090,pm:哑膜,这是其他备注", "planId": "1595336767026274305", "id": "1595336767147909122", "planBz": "", "sizeLength": null, "sizeWidth": null, "productId": "1550054692723695617", "sendTime": null, "companyId": "1592456225243058177", "createBy": "administrator", "unit": "张", "sizeWeight": 100.0000000, "warehousefullName": null, "createTime": "2022-11-23 16:41:40", "warehouseId": "1401863398664880129", "totalNum": 1E+2, "subtotal": 100.0000000, "name": "达摩克利斯之剑" }, { "companyName": "测试委外", "unit2": "平方", "productCount": 1.0000000, "warehouseName": null, "number": "A001", "sizeOther1": null, "price": 1.0000000, "bz": "是其他备注", "planId": "1595336767026274305", "id": "1595336767152103425", "planBz": "", "sizeLength": 400.0000000, "sizeWidth": 100.0000000, "productId": "1353272245520003074", "sendTime": null, "companyId": "1592456225243058177", "createBy": "administrator", "unit": "卷", "sizeWeight": null, "warehousefullName": null, "createTime": "2022-11-23 16:41:40", "warehouseId": "1353275487322730497", "totalNum": 4E+2, "subtotal": 400.0000000, "name": "上光膜" }], "purchaseNumber": "1595336767026274305" }]
let data = arguments[0]; //获取传入的原始数据
//你的代码,推荐在线编辑器https://jsrun.net/
// 截取中间的字符的方法
function getNum(str, firstStr, secondStr) {
if (str == "" || str == null || str == undefined) { // "",null,undefined
return "";
}
if (str.indexOf(firstStr) < 0) {
return "";
}
var subFirstStr = str.substring(str.indexOf(firstStr) + firstStr.length, str.length);
var subSecondStr = subFirstStr.substring(0, subFirstStr.indexOf(secondStr));
return subSecondStr;
}
let dataList = data['DetailsList']
for (let index = 0; index < dataList.length; index++) {
let element = dataList[index];
// 备注的判断
let a = element['bz'];
// console.log(a);
if (a) {
let pause = ',';
// 母卷的输入与转化
inputOut('gg', 'spe');
// 客户订单编号的输入与转化
inputOut('pm', 'pmname');
// 输入与转化的方法 start
// 输入与转化的方法 start
// 输入与转化的方法 start
function inputOut(key, name, qz, hz) {
// 定义可选参数,前缀和后缀,有填则取值,没有则为空
this.qz = qz || '';
this.hz = hz || '';
// 在data里面定义一个值
data['DetailsList'][index][name] = "";
if (a.indexOf(key) != '-1') {
let req = getNum(a, key, pause);
data['DetailsList'][index][name] = this.qz + req + this.hz;
a = a.replace(key + req + pause, '');
data['DetailsList'][index]['bz'] = a;
}
}
console.log('this',data['DetailsList'][0]['spe'])
// 输入与转化的方法 end
// 输入与转化的方法 end
// 输入与转化的方法 end
}
}
// console.log(data['DetailsList'][0]);
// return data; //返回处理完的数据
console