/** * 工料机汇总相关数据 * * @author CaiAoLin * @date 2017/9/14 * @version */ function ProjectGLJ() { this.datas = null; this.isLoading = false; this.quantityChangeMap=null; this.getRatioId = null; } /** * 加载数据 * * @param {function} callback * @return {boolean} */ ProjectGLJ.prototype.loadData = function (callback = null) { let self = this; if (self.isLoading) { return false; } // 加载工料机数据 $.ajax({ url: '/glj/getData', type: 'post', dataType: 'json', data: {project_id: scUrlUtil.GetQueryString('project')}, error: function () { // alert('数据传输错误'); }, beforeSend: function () { self.isLoading = true; }, success: function (response) { self.isLoading = false; if (response.err === 1) { let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!'; alert(msg); return false; } self.datas = response.data; self.calcQuantity(); // 回调函数 if (callback !== null) { callback(response.data); } // 存入缓存 projectObj.project.projectGLJ = self; } }); }; ProjectGLJ.prototype.loadToCache = function (data) { this.datas = data; projectObj.project.projectGLJ = this; } /** * 获取对应工料机数据 * * @param {String} code * @return {Object} */ ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息 return _.find(this.datas.gljList, {'id': ID}); }; // CSL, 2018-02-08 甲供、甲定。 ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) { // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。 // 所以这里要合并处理。 let mixSupply = []; for (let s of supplyTypeArr){ switch (s) { case 1: mixSupply.push('部分甲供'); break; case 2: mixSupply.push('完全甲供'); break; case 3: mixSupply.push('甲定乙供'); break; default: mixSupply.push('自行采购'); } }; mixSupply = mixSupply.concat(supplyTypeArr); return _.filter(this.datas.gljList, function (glj) { return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type); }); }; ProjectGLJ.prototype.testGLJs = function () { let gljs = []; for (let glj of this.datas.gljList){ let o = new Object(); o.name = glj.name; o.supply = glj.supply; o.quantity = glj.quantity; o.supply_quantity = glj.supply_quantity; gljs.push(o); }; return gljs; }; /** * 修改工料机数据 * * @param {Number} id * @param {Object} data * @return {boolean} */ ProjectGLJ.prototype.updateData = function (id, data) { let result = false; if (this.datas === null) { return result; } let gljList = this.datas.gljList; if (gljList === undefined) { return result; } // 查找对应的index let index = -1; for (let tmp in gljList) { if (gljList[tmp].id === id) { index = tmp; break; } } if (index < 0) { return result; } // 修改数据 for (let tmpIndex in data) { if (tmpIndex.indexOf('_price') >= 0) { // 修改unit_price中的对象 this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex]; } else { this.datas.gljList[index][tmpIndex] = data[tmpIndex]; } } }; /** * 加载缓存数据到spread * * @return {void} */ ProjectGLJ.prototype.loadCacheData = function (resort) { // 加载工料机数据 let data = this.datas === null ? null : this.datas; if (data === null) { return; } jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : []; console.log("filter start"); jsonData = filterProjectGLJ(jsonData); console.log("filter end"); jsonData = sortProjectGLJ(jsonData); console.log("sort end"); if(projectGLJSheet&&projectGLJSpread){ setTimeout(spreadInit, 1); /*projectGLJSheet.setData(jsonData); projectGLJSpread.specialColumn(jsonData);*/ } }; ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval) { if (updateField == 'marketPrice') { this.updatePrice(recode, "market_price", newval,"rg"); } if (updateField == 'basePrice') { this.updatePrice(recode, "base_price", newval,"rg"); } }; ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval) { if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑 projectObj.project.Ration.updateContain(newval,node); }if(updateField == "quantity"){ projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField); } else { this.updateGLJProperty(node, updateField, newval); } }; ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) { let rationTypeGLJ = node.data; let postData = {}; if (rationTypeGLJ[updateField] == newval) { return; } let data = { glj_id: rationTypeGLJ.GLJID, project_id: rationTypeGLJ.projectID, code: rationTypeGLJ.code, original_code: rationTypeGLJ.original_code, name: rationTypeGLJ.name, shortName: rationTypeGLJ.shortName, specs: rationTypeGLJ.specs, unit: rationTypeGLJ.unit, type: rationTypeGLJ.subType, type_of_work: rationTypeGLJ.subType, base_price: rationTypeGLJ.basePrice, market_price: rationTypeGLJ.basePrice, repositoryId: rationTypeGLJ.repositoryId, adjCoe: rationTypeGLJ.adjCoe, from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库 }; if (updateField == 'subType') { data.type = newval; data.type_of_work = newval; data.shortName = this.getShortNameByID(newval); } else { data[updateField] = newval; } postData.ration = { ID: rationTypeGLJ.ID, projectID: rationTypeGLJ.projectID }; postData.updateData = data; $.bootstrapLoading.start(); CommonAjax.post("/glj/modifyKeyValue", postData, function (result) { console.log(result); //更新节点信息 rationTypeGLJ[updateField] = newval; rationTypeGLJ.projectGLJID = result.id; rationTypeGLJ.code = result.code; rationTypeGLJ.basePrice = result.unit_price.base_price; rationTypeGLJ.marketUnitFee = result.unit_price.market_price; rationTypeGLJ.isAdd = result.unit_price.is_add; rationTypeGLJ.isEstimate = result.is_evaluate; rationTypeGLJ.shortName = result.unit_price.short_name; //触发计算并更新节点信息 node.changed = true; projectObj.project.projectGLJ.loadData(function () { projectObj.project.calcProgram.calcAndSave(node); $.bootstrapLoading.end(); });//重新加载项目工料机数据 //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的 }, function (err) { $.bootstrapLoading.end(); }); } ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,cb) { let me = this; let projectGljs = this.datas.gljList; let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样 let glj = _.find(projectGljs, {'id': pgljID}); if (glj) { if(glj.unit_price[updateField] == newval){ return; } let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id}; let callback = function (data) { if (updateField == 'base_price') { glj.unit_price.base_price = newval; me.setAdjustPrice(glj); } else { glj.unit_price.market_price = newval; } //更新回传的父节点项目工料机价格 let gljs = me.getProjectGLJs(data); // me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录 projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示 gljOprObj.showRationGLJSheetData(); me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机; gljs.push(glj); let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额 projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序 socket.emit('unitFileChangeNotify', JSON.stringify(data)); projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile"); if(cb){ cb(gljs); } $.bootstrapLoading.end(); } $.bootstrapLoading.start(); CommonAjax.post("/glj/updatePrice", data, callback, function (err) { $.bootstrapLoading.end(); }); } else { gljOprObj.showRationGLJSheetData(); } }; ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,callback) { let me = this; let projectGljs = me.datas.gljList; let decimal = getDecimal('glj.unitPrice'); let updateData = []; let newValueMap = {}; let gljs=[]; for(let ci of changeInfo){ let dataCode = projectGljObject.projectGljSetting.header[ci.col].dataCode; let recode = projectGljObject.projectGljSheetData[ci.row]; if(dataCode=='basePrice'||dataCode=='marketPrice'){ let editField = dataCode === 'basePrice'?"base_price":"market_price"; let newValue= scMathUtil.roundForObj(ci.value,decimal); let glj = _.find(projectGljs, {'id': recode.id}); if(glj&&glj.unit_price[editField]!=newValue){ updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id}); newValueMap[glj.id]={field:editField,value:newValue}; gljs.push(glj); } } } console.log(updateData); if(updateData.length > 0){ $.bootstrapLoading.start(); CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) { let parentData = []; //更新缓存 for(let g of gljs){ g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value; me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机; } //更新父工料机价格 for(let r of result){ let pdata = r.updateOne.filter; let set = r.updateOne.update.$set; for(let skey in set){ pdata[skey] = set[skey]; } parentData.push(pdata); } let pgljs = me.getProjectGLJs(parentData); gljs = gljs.concat(pgljs); let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额 projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序 gljOprObj.showRationGLJSheetData(); socket.emit('unitFileChangeNotify', JSON.stringify(gljs)); projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile"); if(callback){ callback(gljs); } $.bootstrapLoading.end(); }, function (err) { $.bootstrapLoading.end(); }); } }; ProjectGLJ.prototype.pGljUpdate= function (data,callback) { let me = this; $.bootstrapLoading.start(); CommonAjax.specialPost( '/glj/update',data,function (result) { let glj = me.getByID(data.id);//更新缓存 let impactList = []; glj[data.field] = data.value; if(data.extend&&data.extend!=""){ let extend = JSON.parse(data.extend); for (let key in extend) { glj[key] = extend[key]; } } if(data.field == 'is_evaluate'){ impactList = me.changeIsEvaluate(data.id); } if(callback){ callback(impactList); } $.bootstrapLoading.end(); }); }; ProjectGLJ.prototype.getRatioData=function(id,callback){ this.getRatioId = id; if(id){ CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) { let ratios = JSON.parse(response.data); if(callback){ callback(ratios); } },function () {//取不到组成物的情况 callback([]); }) }else { if(callback){ callback([]); } } }; ProjectGLJ.prototype.changeFile = function (changeData,callback) { $.bootstrapLoading.start(); CommonAjax.specialPost('/glj/change-file',changeData,function (response) { projectObj.project.projectGLJ.loadData(function () { if(callback){ callback(); } $.bootstrapLoading.end(); }); }); }; ProjectGLJ.prototype.saveAs = function (saveData,callback) { $.bootstrapLoading.start(); CommonAjax.specialPost('/glj/save-as',saveData,function () { projectObj.project.projectGLJ.loadData(function () { if(callback){ callback(); } $.bootstrapLoading.end(); }); },function (response) { let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!'; $("#save-as-tips").text(msg).show(); $.bootstrapLoading.end(); }); }; //更新是否暂估 ProjectGLJ.prototype.changeIsEvaluate=function (id){ let projectGLJ = projectObj.project.projectGLJ; let datas = projectGLJ.datas; let gljList = datas.gljList; let glj = _.find(gljList, {'id': id}); if(glj){ let con_key = gljOprObj.getIndex(glj,gljKeyArray); let pratioM =datas.mixRatioConnectData[con_key];//找到父key let conditions = []; if(pratioM&&pratioM.length>0){ for(let p_key of pratioM ){ conditions.push(gljOprObj.getConditionByKey(p_key)); } } let gljs = projectGLJ.getProjectGLJs(conditions,false); gljs.push(glj); let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额 //更新对应的工料机类型的定额 let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id}); let ration_nodes = []; for(r of rations){ if(r){ r.isEstimate =glj.is_evaluate?1:0; let ration_node = projectObj.project.mainTree.getNodeByID(r.ID); ration_node?ration_nodes.push(ration_node):''; } } let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点 for(rg of ration_glj_nodes){ rg.data.isEstimate =glj.is_evaluate?1:0; ration_nodes.push(rg); } ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):""; projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序 return gljs; } } ProjectGLJ.prototype.getByID = function (ID) { return _.find(this.datas.gljList,{'id':ID}); }; ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机 return _.find(this.datas.gljList,function (item) { let tem_key = gljOprObj.getIndex(item,gljKeyArray); return tem_key == conkey }) }; ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) { if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) { var nodes = _.filter(projectObj.project.mainTree.items, function (tem) { if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) { tem.data.marketUnitFee = data.unit_price.market_price; return true; } }) projectObj.mainController.refreshTreeNode(nodes); } } ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点 let nodes = []; if(projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true){ nodes = _.filter(projectObj.project.mainTree.items, function (tem) { return tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == id }) } return nodes; }; //根据工料机,取得所有受影响的定额节点 ProjectGLJ.prototype.getImpactRationNodes = function (gljs) { let nodes = []; let rationMap = {}; let idArray = _.map(gljs,'id'); let priceArray = _.map(gljs,'unit_price'); //先根据项目工料机ID,找到受影响定额的ID let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据 for (let rg of ration_glj_list) { if (_.indexOf(idArray,rg.projectGLJID)!=-1) { rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重 } } for (let item of projectObj.project.mainTree.items) { if (item.sourceType == ModuleNames.ration) { if (item.data.type == rationType.gljRation) {//取定额类型的工料机 let idx = _.indexOf(idArray,item.data.projectGLJID); if (idx != -1) { item.data.marketUnitFee = priceArray[idx].market_price; //更新市场单价 nodes.push(item); } } else if (rationMap[item.data.ID] == true) { //受影响的定额 nodes.push(item) } } } return nodes; }; ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) { for (let ration_glj of gljOprObj.sheetData) { if (ration_glj.projectGLJID == glj.id) { ration_glj.basePrice = glj.unit_price.base_price; ration_glj.marketPrice = glj.unit_price.market_price; ration_glj.adjustPrice = this.getAdjustPrice(glj); } } } ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) { } ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) { let parentGlj = []; // let projectGljs = this.datas.gljList; let indexList = gljKeyArray; for (let d of data) { if (d) { let condition = {}; for (let index of indexList) { if (d[index] != null && d[index] != undefined && d[index] != '') { condition[index] = d[index] } } let glj = _.find(projectGljs, condition); if (glj) { if(refreshPrice==true){ d.base_price?glj.unit_price.base_price = d.base_price:''; d.market_price?glj.unit_price.market_price = d.market_price:''; this.setAdjustPrice(glj); this.refreshRationGLJPrice(glj); this.refreshTreeNodePriceIfNeed(glj); } parentGlj.push(glj); } } } return parentGlj; } ProjectGLJ.prototype.setAdjustPrice = function (glj) { switch (glj.unit_price.type + '') { // 人工: 调整基价=基价单价*调整系数 case GLJTypeConst.LABOUR: case GLJTypeConst.MACHINE_LABOUR: glj.adjust_price = this.getAdjustPrice(glj); break; // 机械类型的算法 case GLJTypeConst.MACHINE: console.log('机械'); break; // 材料、主材、设备 default: glj.adjust_price = glj.unit_price.base_price; } } ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) { GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst; let decimal = getDecimal("glj.unitPrice"); let quantity_decimal = getDecimal("glj.quantity"); let process_decimal = getDecimal("process"); let tem_decimal = isRadio==true?process_decimal:decimal; if (glj.unit_price.type == GLJTypeConst.LABOUR || glj.unit_price.type == GLJTypeConst.MACHINE_LABOUR) {//人工、机上人工,调整价根据定额价*调整系数计算得出。 let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe]; //let labour=1; let coe = labour && labour.coe ? labour.coe : 1; return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price,tem_decimal)), -tem_decimal); } else if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。 let p =0; for(let ratio of glj.ratio_data){ let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{ 'code': ratio.code, 'name': ratio.name, 'specs':ratio.specs, 'type': ratio.type, 'unit': ratio.unit }) if(tem){ let priceData={}; gljOprObj.setGLJPrice(priceData,tem,true); p+=scMathUtil.roundForObj(priceData.adjustPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal); } } return scMathUtil.roundForObj(p,decimal); } else {//对于其他普通材料等,无调整系数,调整价=定额价。 return glj.unit_price.base_price } }; ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){ let price_decimal = getDecimal("glj.unitPrice"); let quantity_decimal = getDecimal("glj.quantity"); let process_decimal = getDecimal("process"); if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。 let p =0; for(let ratio of glj.ratio_data){ let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{ 'code': ratio.code, 'name': ratio.name, 'specs':ratio.specs, 'type': ratio.type, 'unit': ratio.unit }); if(tem){ let priceData={}; gljOprObj.setGLJPrice(priceData,tem,true); p+=scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal); } } return scMathUtil.roundForObj(p,price_decimal); }else { let tem_decimal = isRadio==true?process_decimal:price_decimal; return scMathUtil.roundForObj(glj.unit_price.base_price,tem_decimal); } }; ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) { let price_decimal = getDecimal("glj.unitPrice"); let quantity_decimal = getDecimal("glj.quantity"); let process_decimal = getDecimal("process"); if (notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。 let p =0; for(let ratio of glj.ratio_data){ let tem = _.find( projectObj.project.projectGLJ.datas.gljList,{ 'code': ratio.code, 'name': ratio.name, 'specs':ratio.specs, 'type': ratio.type, 'unit': ratio.unit }); if(tem){ let priceData={}; gljOprObj.setGLJPrice(priceData,tem,true); p+=scMathUtil.roundForObj(priceData.marketPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal); } } return scMathUtil.roundForObj(p,price_decimal); }else { let tem_decimal = isRadio==true?process_decimal:price_decimal; return scMathUtil.roundForObj(glj.unit_price.market_price,tem_decimal); } } ProjectGLJ.prototype.isEstimateType = function(type){ let typeString = type + ""; if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估 return type; } return false; }; ProjectGLJ.prototype.getShortNameByID = function (ID) { let gljTypeMap = this.datas.constData.gljTypeMap; return gljTypeMap["typeId" + ID].shortName; }; ProjectGLJ.prototype.calcQuantity = function (init=false){ let project_gljs = this.datas.gljList; let mixRatioConnectData = this.datas.mixRatioConnectData; let mixRatioMap = this.datas.mixRatioMap; let rations = projectObj.project.Ration.datas; let rationMap = _.indexBy(rations,'ID'); let quantityMap={},changeArray=[]; let rationGljGroup = _.groupBy(projectObj.project.ration_glj.datas,'projectGLJID') let q_decimal = getDecimal("glj.quantity"); console.log(init); for(let pglj of project_gljs ){ let pg_index = gljOprObj.getIndex(pglj,gljKeyArray); pglj.subdivisionQuantity = 0; pglj.techQuantity = 0; pglj.quantity = 0; let gljGroup = rationGljGroup[pglj.id]?rationGljGroup[pglj.id]:[];//定额工料机没有,有可能是定额类型的工料机 let result = this.getQuantityPerGLJ(gljGroup,rations,rationMap,pglj,quantityMap); pglj.subdivisionQuantity = result.subdivisionQuantity; pglj.techQuantity = result.techQuantity; pglj.quantity = result.quantity; quantityMap[pg_index] = pglj; } //计算做为组成物的消耗量 for(let pkey in mixRatioMap){ let mixRatioList = mixRatioMap[pkey]; for(let m of mixRatioList){ let m_index = gljOprObj.getIndex(m,gljKeyArray); let m_glj = quantityMap[m_index]; let p_glj = quantityMap[pkey]; if(m_glj&&p_glj){ let quantity = scMathUtil.roundForObj(p_glj.quantity*parseFloat(m.consumption),q_decimal); let techQuantity = scMathUtil.roundForObj(p_glj.techQuantity*parseFloat(m.consumption),q_decimal); let subdivisionQuantity = scMathUtil.roundForObj(p_glj.subdivisionQuantity*parseFloat(m.consumption),q_decimal); m_glj.quantity = scMathUtil.roundForObj(m_glj.quantity+quantity,q_decimal); m_glj.techQuantity = scMathUtil.roundForObj(m_glj.techQuantity+techQuantity,q_decimal); m_glj.subdivisionQuantity = scMathUtil.roundForObj(m_glj.subdivisionQuantity+subdivisionQuantity,q_decimal); } } } if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表 this.quantityChangeMap = {}; for(let pglj of project_gljs){ this.quantityChangeMap[pglj.id] = pglj.quantity; } }else if(this.quantityChangeMap != null){ for(let pglj of project_gljs){ if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){ if(this.quantityChangeMap[pglj.id] != pglj.quantity){ changeArray.push(pglj); this.quantityChangeMap[pglj.id] = pglj.quantity; } }else { //映射表没有,说明是新添加的项目工料机 changeArray.push(pglj); this.quantityChangeMap[pglj.id] = pglj.quantity; } } } changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):''; }; ProjectGLJ.prototype.getQuantityPerGLJ = function (ration_glj_list,rations,rationMap,pglj) { let billIDs = projectObj.project.Bills.getSubdivisionProjectLeavesID();//取分部分项上的所有叶子清单ID let tech_billIDS = projectObj.project.Bills.getTechLeavesID();//取所有技术措施项目叶子清单IDs let mixRatioMap = this.datas.mixRatioMap; let q_decimal = getDecimal("glj.quantity"); let result={}; let quantity_sum=0;//工料机汇总消耗量 let sum = 0;//分部分项总消耗量 let tech_sum = 0;//技术措施总消耗量 for(let rg of ration_glj_list){ let tem_ration = rationMap[rg.rationID]; let r_quantity = tem_ration?scMathUtil.roundForObj(tem_ration.quantity,q_decimal):0; let glj_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal); if(!r_quantity){ continue; } let total = scMathUtil.roundForObj(glj_quantity*r_quantity, q_decimal); quantity_sum = scMathUtil.roundForObj(quantity_sum+total,q_decimal); if(_.includes(billIDs,rg.billsItemID)){//计算分部分项 sum = scMathUtil.roundForObj(sum+total,q_decimal); } if(_.includes(tech_billIDS,rg.billsItemID)){//计算技术措施项目消耗量 tech_sum = scMathUtil.roundForObj(tech_sum+total,q_decimal); } } for(let ra of rations){//计算定额类型工料机的消耗量 if(ra.type == rationType.gljRation&&ra.projectGLJID===pglj.id){ let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal); r_quantity = r_quantity?r_quantity:0; quantity_sum = scMathUtil.roundForObj(quantity_sum+r_quantity,q_decimal); if(_.includes(billIDs,ra.billsItemID)){//计算分部分项 sum = scMathUtil.roundForObj(sum+r_quantity,q_decimal); } if(_.includes(tech_billIDS,ra.billsItemID)){//计算技术措施项目消耗量 tech_sum = scMathUtil.roundForObj(tech_sum+r_quantity,q_decimal); } } } result.subdivisionQuantity = sum; result.techQuantity = tech_sum; result.quantity = quantity_sum; return result; }