SOURCE

var unitList=dataOper.Root.Cabinets;
var res=[];
function setPartPrdId(part,tag){
    var partNumber=part.PartNumber;
    var prdt=helper.getPrdInfoBySupSpc(partNumber);
    if(prdt==null){
	   var msg=tag+" 对应的产品编码["+partNumber+"]在MIS系统中未对应设置!";
	   throw msg;
	}
    part.clsId=prdt.clsId;
    part.prdId=prdt.prdId;
    part.prdType=prdt.prdType;
    part.ut=prdt.prdUt;
    part.upType=prdt.upType;
    part.qtyType=prdt.qtyType;
}
function addNewDtl(roomName,part,dtls){
    var dtl={
        roomName:roomName,
	    clsId:part.clsId,
	    prdId:part.prdId,
	    prdName:part.Name,
	    prdSpc:part.PartNumber,
	    wth:Number(part.Width),
	    hgt:Number(part.Height),
	    thk:Number(part.Length),
	    dtls:dtls,
	    qty_q:part.Num==null ?1:Number(part.Num),
	    prdType:part.prdType,
	    upType:part.upType,
	    qtyType:part.qtyType,

	};
    res.push(dtl);
    return dtl;
}
function getMat(clsId,matName,thk){
    
    var mat=helper.getFMatInfo(clsId,matName);
    if(mat==null){
        var fmatName=thk+"mm"+matName;
        mat=helper.getFMatInfo(clsId,fmatName);
        if(mat==null){
            throw "材质["+matName+"]或材质["+fmatName+"]在系统中没有建档案"
        }
    }
    return mat;
}
//设置分解计价的单价
function setSubDtlMatUp(clsId,subDtl){
    var mat=null;
	try{
	   mat=getMat(clsId,subDtl.matName,subDtl.thk);
	}catch(f){
	   var msg= subDtl.prdName+",编号:["+subDtl.ID+"]的材料["+subDtl.matName+"]在MIS系统中不存在";
       throw msg;
    }
    subDtl.matId=mat.matId;
    subDtl.up=Number(mat.matUp);
    subDtl.amt=subDtl.qty_a*subDtl.up;
    subDtl.amt=Math.round(subDtl.amt*10000)/10000;
}
function setDtlMatUp(dtl){

}
//对应其他板件的处理
function dealWithOtherPanel(subDtl,panel,parDtl){
    
}
//处理门板的部分
function dealWithMbPanel(subDtl,panel,parDtl){
    if(subDtl.partNumber==null){
        throw subDtl.prdName+"的partNumber未设定"
    }
    if(subDtl.partNumber.indexOf("-")==-1){
        throw subDtl.prdName+"的partNumber:"+subDtl.partNumber+"设定方式必须为[基础型号-门型型号]";
    }
    var f=subDtl.partNumber.split("-");
    var supSpc=f[0];
    var mpSpc=f[1];
    var prdt=helper.getFPrdInfoBySupSpc(0,supSpc);
    if(prdt==null){
        var msg= subDtl.prdName+"的partNumber["+subDtl.partNumber+"]对应的基础型号["+
        supSpc+"]在MIS系统中不存在";
        throw msg;
    }
    var mp=helper.getFMpInfoBySupSpc(prdt.clsId,mpSpc);
    if(mp==null){
        var msg= subDtl.prdName+"的partNumber["+subDtl.partNumber+"]对应的门片型号["+
        mpSpc+"]在MIS系统中不存在";
        throw msg;
    }
    var mat=null;
    try{
        mat=getMat(prdt.clsId,subDtl.matName);
    }catch(ef){
        var msg= subDtl.prdName+",编号:["+subDtl.ID+"]的材料["+subDtl.matName+"]在MIS系统中不存在";
         throw msg;
    }
    
    subDtl.prdId=prdt.prdId;
    subDtl.mpId=mp.mpId;
    subDtl.matId=mat.matId;
    subDtl.prdType=prdt.prdType;
    subDtl.upType=prdt.upType;
    subDtl.qtyType=prdt.qtyType;
    subDtl.roomName=parDtl.roomName;
    subDtl.clsId=prdt.clsId;
    setDtlMatUp(subDtl);
    res.push(subDtl);
}

function dealWithPanel(panel,parDtl){
     //柜体板写入到柜体主键
     var subDtl={
         itm:parDtl.dtls.length+1,
         prdName:panel.Name,
         matName:panel.BasicMaterial,
         clr:panel.Material,
         wth:Number(panel.Width),
         hgt:Number(panel.Length),
         thk:Number(panel.Thickness),
         partNumber:panel.PartNumber,
         qty_q:1,
         ut:"平方"
     }
     subDtl.qty_a=subDtl.wth*subDtl.hgt*0.001*0.001;
     subDtl.qty_a=Math.round(subDtl.qty_a*10000)/10000;

     if(panel.PartNumber=="gtb"){
        if(parDtl.upType==5){
            setSubDtlMatUp(parDtl.clsId,subDtl);
            parDtl.amt=parDtl.amt==null?subDtl.amt:(parDtl.amt+subDtl.amt);
        }
        parDtl.dtls.push(subDtl);
     }else if(panel.CabinetType=="swingDoorLeafEntity"){
         dealWithMbPanel(subDtl,panel,parDtl);
         //
     }else{
         dealWithOtherPanel(subDtl,panel,parDtl);
     }
}
//循环unit
for(var i=0;i<unitList.length;i++){
    var unit=unitList[i];
    setPartPrdId(unit,unit.Name);
    if(unit.CabinetType=="unit"){
	    var dtl= addNewDtl(unit.roomName,unit,[]);
	    for(var j=0;j<unit.Panels.length;j++){
	        dealWithPanel(unit.Panels[j],dtl);
	    }
        if(dtl.upType==5){
            dtl.amt=Math.round(dtl.amt*100)/100
        }
	}
    //处理子集
}
res;
console 命令行工具 X clear

                    
>
console