/** * Created by zhang on 2018/6/7. */ let gljUtil = { calcProjectGLJQuantity: function (projectGLJDatas, rationGLJDatas, rationDatas, billsDatas, q_decimal, _, scMathUtil, isReport) { let project_gljs = projectGLJDatas.gljList, mixRatioMap = projectGLJDatas.mixRatioMap, com_electrovalence = projectGLJDatas.com_electrovalence; let rations = rationDatas; let rationMap = _.indexBy(rations, 'ID'); let quantityMap = {}; let rationGljGroup = _.groupBy(rationGLJDatas, 'projectGLJID'); let IDarray = this.getSubdivisionAndTechBillsLeavesID(billsDatas); //分别取分部分项和技术措施项目的所有叶子清单ID let billIDs = IDarray[0], tech_billIDS = IDarray[1]; let materialCalcMap = {}; //养护没有分部分项消耗量这一说的所以不用管 let qField = "quantity"; let mField = "materialQuantity"; //材料计算的工料机消耗量 let elecIndex = ""; //记住电的标识 for (let pglj of project_gljs) { let pg_index = this.getIndex(pglj, this.gljKeyArray); pglj[qField] = 0; pglj[mField] = 0; let gljGroup = rationGljGroup[pglj.id] ? rationGljGroup[pglj.id] : []; //定额工料机没有,有可能是定额类型的工料机 let result = this.getQuantityPerGLJ(gljGroup, rations, rationMap, pglj, billIDs, tech_billIDS, q_decimal, _, scMathUtil); pglj[qField] = result.quantity; pglj.tenderQuantity = result.tenderQuantity; quantityMap[pg_index] = pglj; if (pglj.code == gljUtil.getElecCode() && pglj.name == '电' && pglj.unit == "kW·h") elecIndex = pg_index; if (pglj.unit_price.calcMaterial == 1) materialCalcMap[pg_index] = true; } //计算做为组成物的消耗量 for (let pkey in mixRatioMap) { let mixRatioList = mixRatioMap[pkey]; for (let m of mixRatioList) { let m_index = this.getIndex(m, this.gljKeyArray); let m_glj = quantityMap[m_index]; let p_glj = quantityMap[pkey]; if (m_glj && p_glj && !gljUtil.isConcreteType(p_glj.type)) { //混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去 let quantity = scMathUtil.roundForObj(parseFloat(p_glj[qField]) * parseFloat(m.consumption), q_decimal); let tenderQuantity = scMathUtil.roundForObj(parseFloat(p_glj.tenderQuantity) * parseFloat(m.consumption), q_decimal); m_glj[qField] = scMathUtil.roundForObj(parseFloat(m_glj[qField]) + quantity, q_decimal); m_glj.tenderQuantity = scMathUtil.roundForObj(parseFloat(m_glj.tenderQuantity) + tenderQuantity, q_decimal); } } } //计算经过场外运输损耗后的总消耗量 for (let pglj of project_gljs) { let offSiteTransportLossRate = this.getOffSiteTransportLossRate(pglj); pglj.offSiteTransportLossRate = parseFloat(offSiteTransportLossRate); //scMathUtil.roundForObj(offSiteTransportLossRate,getDecimal("glj.unitPrice")) ;这里再取小数位数太麻烦了,暂时用保存的吧 offSiteTransportLossRate = offSiteTransportLossRate / 100; pglj.transportLossQuantity = scMathUtil.roundForObj(pglj.quantity * offSiteTransportLossRate, q_decimal); pglj.quantity = scMathUtil.roundForObj(pglj.quantity + pglj.transportLossQuantity, q_decimal); pglj.tenderTransportLossQuantity = scMathUtil.roundForObj(pglj.tenderQuantity * offSiteTransportLossRate, q_decimal); pglj.tenderQuantity = scMathUtil.roundForObj(pglj.tenderQuantity + pglj.tenderTransportLossQuantity, q_decimal); if (isReport) pglj.quantity = pglj.tenderQuantity; } //材料计算中,工料机的消耗量 //材料计算中,有可能A包含B,B包含C。。。。。等情况,为避免循环计算,只多计算一次,不做再深的嵌套处理 // 1.先计算做为父工料机的材料计算消耗量 if (projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, true, projectGLJDatas.freightList, q_decimal, _, scMathUtil); //运费计算中工料机的消耗量 if (projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, true, projectGLJDatas.originalList, q_decimal, _, scMathUtil); //原价计算中工料机的消耗量 // 2.再计算做为子工料机的材料计算消耗量 if (projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, false, projectGLJDatas.freightList, q_decimal, _, scMathUtil); //运费计算中工料机的消耗量 if (projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap, materialCalcMap, false, projectGLJDatas.originalList, q_decimal, _, scMathUtil); //原价计算中工料机的消耗量 //因为材料计算里自采材料产生的消耗量和进行材料计算的父工料机的消耗量有关,所以材料计算中的组成物的消耗量要在上一步的组成物计算完后,再计算自采材料里组成物的消耗量,所认两个组成物计算不能合并,而且乘的值也不同 for (let pkey in mixRatioMap) { let mixRatioList = mixRatioMap[pkey]; for (let m of mixRatioList) { let m_index = this.getIndex(m, this.gljKeyArray); let m_glj = quantityMap[m_index]; let p_glj = quantityMap[pkey]; if (m_glj && p_glj && !gljUtil.isConcreteType(p_glj.type) && p_glj[mField] > 0) { //混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去 let materialQuantity = scMathUtil.roundForObj(parseFloat(p_glj[mField]) * parseFloat(m.consumption), q_decimal); m_glj[qField] = scMathUtil.roundForObj(parseFloat(m_glj[qField]) + materialQuantity, q_decimal); m_glj[mField] = scMathUtil.roundForObj(parseFloat(m_glj[mField]) + materialQuantity, q_decimal); } } } //计算综合电价中,电网电和机械台班的消耗量 - 电有可能做为组成物存在,计算综合电价的各消耗量时,要以电的总消耗量为基础,所以这步要放在最后,即电都计算完成以后 if (com_electrovalence && com_electrovalence.gljList && quantityMap[elecIndex]) { for (let cg of com_electrovalence.gljList) { //网电的消耗量=电的总消耗量×加权系数 let eq = scMathUtil.roundForObj(quantityMap[elecIndex][qField] * parseFloat(cg.coe), q_decimal); if (cg.name == '电网电') { quantityMap[this.getIndex(cg)][qField] = eq; } else { let tquantity = 0; let w = parseInt(cg.name); if (w) tquantity = scMathUtil.roundForObj(eq / w, 6); tquantity = scMathUtil.roundForObj(tquantity * this.getElecCoe(), q_decimal); let ekey = this.getIndex(cg); quantityMap[ekey][qField] = tquantity; //计算机械台班下的组成物的消耗量 if (mixRatioMap[ekey]) { for (let m of mixRatioMap[ekey]) { let cmkey = this.getIndex(m); if (quantityMap[cmkey] && tquantity > 0) { //混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去 let c_m_quantity = scMathUtil.roundForObj(tquantity * parseFloat(m.consumption), 6); quantityMap[cmkey][qField] = scMathUtil.roundForObj(parseFloat(quantityMap[cmkey][qField]) + c_m_quantity, q_decimal); } } } } } } }, setMaterialCalcQuantity: function (quantityMap, materialCalcMap, isParent, calcList, q_decimal, _, scMathUtil) { let qField = "quantity"; let p_decimal = 6; //自采定额这里计算结果都看成是中间过程,取6位小数 for (let t of calcList) { if (quantityMap[t.connect_key] && quantityMap[t.connect_key][qField] > 0) { let rationIDMap = _.indexBy(t.rations, "ID"); if (t.ration_gljs) { for (let rg of t.ration_gljs) { let rIndex = this.getIndex(rg); let pglj = quantityMap[rIndex]; let ration = rationIDMap[rg.rationID]; if (isParent == true) { //当计算做为材料计算父消耗量时,忽略子消耗量 if (!materialCalcMap[rIndex]) continue } else { //当计算做为材料计算子消耗量时,忽略父消耗量 if (materialCalcMap[rIndex]) continue } if (pglj && ration) { let rg_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal); let r_quantity = scMathUtil.roundForObj(ration.quantity, q_decimal); let result = scMathUtil.roundForObj(rg_quantity * r_quantity, p_decimal); result = scMathUtil.roundForObj(quantityMap[t.connect_key][qField] * result, p_decimal); pglj.quantity = scMathUtil.roundForObj(pglj.quantity + result, q_decimal); pglj.materialQuantity = scMathUtil.roundForObj(pglj.materialQuantity + result, q_decimal); } } } } } }, getOffSiteTransportLossRate: function (pglj) { let offSiteTransportLossRate; //场外运输损耗率 let handlingLossRate; //每增加一次装卸损耗率 let totalLoadingTimes = 1; //没有材料计算,获取不到装卸总次数,则按1计算 //场外总损耗率=场外运输损耗率%+(装卸总次数-1)*每增加一次装卸损耗率%。 if (pglj.unit_price) { if (pglj.unit_price.calcMaterial == 1) { //如果是材料计算,则用修改过的新值 offSiteTransportLossRate = pglj.unit_price.offSiteTransportLossRate_n; handlingLossRate = pglj.unit_price.handlingLossRate_n; if (pglj.unit_price.totalLoadingTimes && pglj.unit_price.totalLoadingTimes > 1) totalLoadingTimes = parseFloat(pglj.unit_price.totalLoadingTimes) } else { offSiteTransportLossRate = pglj.unit_price.offSiteTransportLossRate; handlingLossRate = pglj.unit_price.handlingLossRate; } } offSiteTransportLossRate = offSiteTransportLossRate ? parseFloat(offSiteTransportLossRate) : 0; handlingLossRate = handlingLossRate ? parseFloat(handlingLossRate) : 0; // 场外运输损耗率%+(装卸总次数-1)*每增加一次装卸损耗率% return (offSiteTransportLossRate + (totalLoadingTimes - 1) * handlingLossRate); }, getQuantityPerGLJ: function (ration_glj_list, rations, rationMap, pglj, billIDs, tech_billIDS, q_decimal, _, scMathUtil) { let result = {}; let quantity_sum = 0; //工料机汇总消耗量 let tender_qantity_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); let tender_r_quantity = r_quantity; let tender_glj_quantity = glj_quantity; if (!r_quantity) { continue; } if (!pglj.is_adjust_price) { tender_glj_quantity = this.getRationGLJTenderQuantity(rg, tem_ration, q_decimal, scMathUtil, pglj); tender_r_quantity = this.getRationTenderQuantity(tem_ration, q_decimal, scMathUtil); } let total = scMathUtil.roundForObj(glj_quantity * r_quantity, q_decimal); let tender_total = scMathUtil.roundForObj(tender_glj_quantity * tender_r_quantity, q_decimal); quantity_sum = scMathUtil.roundForObj(quantity_sum + total, q_decimal); tender_qantity_sum = scMathUtil.roundForObj(tender_qantity_sum + tender_total, q_decimal); } for (let ra of rations) { //计算定额类型工料机的消耗量 if (ra.type == this.rationType.gljRation && ra.projectGLJID === pglj.id) { let r_quantity = scMathUtil.roundForObj(ra.quantity, q_decimal); r_quantity = r_quantity ? r_quantity : 0; let tender_r_quantity = r_quantity; if (!pglj.is_adjust_price) { tender_r_quantity = this.getRationTenderQuantity(ra, q_decimal, scMathUtil); } quantity_sum = scMathUtil.roundForObj(quantity_sum + r_quantity, q_decimal); tender_qantity_sum = scMathUtil.roundForObj(tender_qantity_sum + tender_r_quantity, q_decimal); } } result.quantity = quantity_sum; result.tenderQuantity = tender_qantity_sum; return result; }, getRationGLJTenderQuantity: function (ration_glj, ration, q_decimal, scMathUtil, projectGLJ) { let coeMap = { 1: 'labour', //人工 2: 'material', //材料 3: 'machine', //机械 4: 'main', //主材 5: 'equipment' //设备 }; let typeString = ration_glj.type + ""; let coeField = ""; for (let key in coeMap) { if (typeString.indexOf(key) == 0) { coeField = coeMap[key]; break; } } let coe = 1; if (projectGLJ && projectGLJ.is_adjust_price == 0) { coe = ration.quantityCoe && this.isNotEmpty(ration.quantityCoe[coeField]) ? ration.quantityCoe[coeField] : 1; coe = parseFloat(coe); } else { coe = 1; } if (coe == 0) coe = 1; let glj_quantity = scMathUtil.roundForObj(ration_glj.quantity, q_decimal); return scMathUtil.roundForObj(glj_quantity * coe, q_decimal); }, getRationTenderQuantity: function (ration, q_decimal, scMathUtil) { let rationQuantityCoe = this.isNotEmpty(ration.rationQuantityCoe) ? ration.rationQuantityCoe : 1; rationQuantityCoe = parseFloat(rationQuantityCoe); if (rationQuantityCoe == 0) rationQuantityCoe = 1; let r_quantity = ration ? scMathUtil.roundForObj(ration.quantity, q_decimal) : 0; return scMathUtil.roundForObj(r_quantity * rationQuantityCoe, q_decimal); }, isNotEmpty: function (str) { return this.isDef(str) && str != ""; }, getSubdivisionAndTechBillsLeavesID: function (billsDatas) { //分别取分部分项和技术措施项目的所有叶子清单ID if (typeof (projectObj) !== 'undefined') { //存在,说明在前端调用 return [projectObj.project.Bills.getSubdivisionProjectLeavesID(), projectObj.project.Bills.getTechLeavesID()]; } let parentMap = {}; let subdivisionBillID = null, techBillID = null, sIDs = [], tIDS = []; for (let b of billsDatas) { if (parentMap[b.ParentID]) { parentMap[b.ParentID].push(b); } else { parentMap[b.ParentID] = [b]; } let flag = this.getFlag(b); if (this.isDef(flag) && flag.flag == this.fixedFlag.SUB_ENGINERRING) { subdivisionBillID = b.ID; } if (this.isDef(flag) && flag.flag == this.fixedFlag.CONSTRUCTION_TECH) { techBillID = b.ID; } } getLeaveIDs(subdivisionBillID, parentMap, sIDs); getLeaveIDs(techBillID, parentMap, tIDS); return [sIDs, tIDS]; function getLeaveIDs(ID, parentM, leaveIDs) { if (parentM[ID] && parentM[ID].length > 0) { let children = parentM[ID]; for (let c of children) { if (parentM[c.ID]) { getLeaveIDs(c.ID, parentM, leaveIDs); } else { leaveIDs.push(c.ID); } } } } }, getFlag: function (b) { let lo_sh = typeof _ !== 'undefined' ? _ : this._; return lo_sh.find(b.flags, { "fieldName": "fixed" }); }, getGLJPrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, ext, tenderCoe, isReport) { let result = {}; if (isReport) { result.marketPrice = this.getMarketPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, tenderCoe, ext); } else { result.marketPrice = this.getMarketPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil); result.tenderPrice = this.getMarketPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, tenderCoe); } if (this.calcPriceDiff(glj, calcOptions) == true) { //计取价差 result.basePrice = this.getBasePrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil); result.adjustPrice = this.getAdjustPrice(glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil); } else { //不计价差 result.basePrice = result.marketPrice; result.adjustPrice = result.marketPrice; } return result; }, getMarketPrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil, tenderCoe, ext) { let price_decimal = decimalObj.glj.unitPrice; let price_hasM_decimal = decimalObj.glj.unitPriceHasMix ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice; let quantity_decimal = decimalObj.glj.quantity; let process_decimal = this.isDef(decimalObj.marketPriceProcess) ? decimalObj.marketPriceProcess : decimalObj.process; //20200722 旧的项目还是默认6位,新的用两位 let priceCoe = this.isDef(tenderCoe) ? tenderCoe : 1; if (priceCoe == '0' || priceCoe == 0) priceCoe = 1; // 这里加个保护 if (['GLF', 'LR', 'FXF'].includes(glj.code)) priceCoe = 1; // 类型是“企业管理费”、“利润”、“一般风险费”的,不应调整单价。 if (!this.isConcreteType(glj.unit_price.type) && this.notEditType.indexOf(glj.unit_price.type) != -1 && glj.ratio_data.length > 0) { //对于机械台班等有组成物的材料,价格需根据组成物计算得出(排除混凝土、配合比、砂浆这几个类型直接为0)。 let p = 0; for (let ratio of glj.ratio_data) { let rIndex = gljUtil.getIndex(ratio); let tem = _.find(projectGLJDatas.gljList, function (item) { return rIndex == gljUtil.getIndex(item); }); if (tem) { let tem_marketPrice = this.getMarketPrice(tem, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, true, _, scMathUtil); if (ext && ext[tem.id] && this.isDef(ext[tem.id].marketPrice)) { //在修改组成物的价格或消耗量时,影响了父工料机的价格,这时以父工料机的价格应当用组成物的新值来记算 tem_marketPrice = ext[tem.id].marketPrice; }; let temP = scMathUtil.roundForObj( scMathUtil.roundForObj(tem_marketPrice * priceCoe, price_decimal) * scMathUtil.roundForObj(ratio.consumption, quantity_decimal), process_decimal); p = scMathUtil.roundForObj(temP + p, process_decimal); } } return scMathUtil.roundForObj(p, price_hasM_decimal); } else { let tem_decimal = price_decimal; //isRadio==true?process_decimal:price_decimal; let tem_price = scMathUtil.roundForObj(glj.unit_price.market_price, price_decimal); return scMathUtil.roundForObj(tem_price * priceCoe, tem_decimal); } }, getBasePrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil) { let price_decimal = decimalObj.glj.unitPrice; let price_hasM_decimal = decimalObj.glj.unitPriceHasMix ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice; let quantity_decimal = decimalObj.glj.quantity; let process_decimal = decimalObj.process; if (this.notEditType.indexOf(glj.unit_price.type) != -1 && glj.ratio_data.length > 0) { //对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。 //2018-09-07 需求修改,定额价不按组成物的量和价实时计算出来,直接取单价文件中的定额价 /* let p =0; for(let ratio of glj.ratio_data){ let tem = _.find( projectGLJDatas.gljList,{ 'code': ratio.code, 'name': ratio.name, 'specs':ratio.specs, 'type': ratio.type, 'unit': ratio.unit }); if(tem){ let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil); let temP = scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal); p = scMathUtil.roundForObj(temP + p,process_decimal); } } return scMathUtil.roundForObj(p,price_hasM_decimal);*/ return scMathUtil.roundForObj(glj.unit_price.base_price, price_hasM_decimal); } else { let tem_decimal = price_decimal; //isRadio==true?process_decimal:price_decimal; return scMathUtil.roundForObj(glj.unit_price.base_price, tem_decimal); } }, getAdjustPrice: function (glj, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, isRadio, _, scMathUtil) { let decimal = decimalObj.glj.unitPrice; let price_hasM_decimal = decimalObj.glj.unitPriceHasMix ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice; let quantity_decimal = decimalObj.glj.quantity; let process_decimal = this.isDef(decimalObj.marketPriceProcess) ? decimalObj.marketPriceProcess : decimalObj.process; let tem_decimal = isRadio == true ? process_decimal : decimal; if (glj.unit_price.type == this.gljType.LABOUR || glj.unit_price.type == this.gljType.MACHINE_LABOUR) { //人工、机上人工,调整价根据定额价*调整系数计算得出。 let labour = _.find(labourCoeDatas.coes, { 'ID': glj.adjCoe }); let coe = labour && labour.coe ? labour.coe : 1; return scMathUtil.roundTo(parseFloat(coe * scMathUtil.roundForObj(glj.unit_price.base_price, decimal)), -decimal); } else if (this.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(projectGLJDatas.gljList, { 'code': ratio.code, 'name': ratio.name, 'specs': ratio.specs, 'type': ratio.type, 'unit': ratio.unit }) if (tem) { let priceData = this.getGLJPrice(tem, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, true, _, scMathUtil); let temP = scMathUtil.roundForObj(priceData.adjustPrice * scMathUtil.roundForObj(ratio.consumption, quantity_decimal), process_decimal); p = scMathUtil.roundForObj(temP + p, process_decimal); } } return scMathUtil.roundForObj(p, price_hasM_decimal); } else { //对于其他普通材料等,无调整系数,调整价=定额价。 return scMathUtil.roundForObj(glj.unit_price.base_price, decimal) } }, calcPriceDiff: function (glj, calcOptions) { if (glj.is_evaluate == 1) { //先按是否暂估判断 return calcOptions.calc_est; } if (glj.type == this.gljType.MAIN_MATERIAL || glj.type == this.gljType.EQUIPMENT) { //再判断是否是主材和设备 return calcOptions.calc_main; } if (glj.unit_price.is_add == 1) { //再判断是否新增 return calcOptions.calc_add; } return true; }, isFlag: function (v) { return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed) && this.isDef(v.flagsIndex.fixed.flag); }, isDef: function (v) { return v !== undefined && v !== null; }, getIndex(obj, pops) { let t_index = ''; let k_arr = []; if (!this.isDef(pops)) pops = this.gljKeyArray; for (let p of pops) { let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p]; k_arr.push(tmpK); } t_index = k_arr.join("|-|"); return t_index; }, getMainType: function (type) { let str = type + ""; return parseInt(str.substr(0, 1)); }, sortRationGLJ: function (list, std) { const field = std ? 'gljType' : 'type'; let lo_sh = typeof _ !== 'undefined' ? _ : this._; list = lo_sh.sortByAll(list, [function (item) { return gljUtil.getMainType(item[field]); }, gljUtil.getCodeSortMath()]); return list; }, sortMixRatio: function (list) { let lo_sh = typeof _ !== 'undefined' ? _ : this._; return lo_sh.sortByAll(list, ["code"]); }, //项目工料机 混凝土、砂浆、配合比排序与定额工料机不一样,同时,type取值的地方不一样 sortProjectGLJ: function (list, lodash) { let lo = lodash ? lodash : _; let specialMap = { 1: -1, 303: 0, 202: 9, 203: 10, 204: 11 }; //,人工、机械工排在最前,混凝土、砂浆、配合比 排到最后 list = lo.sortByAll(list, [function (item) { let unit_price = item.unit_price ? item.unit_price : item; if (specialMap[unit_price.type] != undefined) return specialMap[unit_price.type]; return gljUtil.getMainType(unit_price.type); }, gljUtil.getCodeSortMath()]); return list; }, getCodeSortMath: function () { return "code" }, isConcreteType: function (type) { let concreteType = [gljUtil.gljType.CONCRETE, gljUtil.gljType.MORTAR, gljUtil.gljType.MIX_RATIO]; //混凝土大类:混凝土、砂浆,配合比 return concreteType.indexOf(type) != -1 }, isCommercialConcreteType: function (type) { let commercialType = [gljUtil.gljType.COMMERCIAL_CONCRETE, gljUtil.gljType.COMMERCIAL_MORTAR]; //商品混凝土、商品砂浆 return commercialType.indexOf(type) != -1 }, //是否从混凝土改成商品混凝土,并且混凝土的定额消耗量不为空,则原混凝土的自定义消耗改成0,插入一条新的商品混凝土自定义消耗量为原自定义或定额消耗 isAddCommercialForReplace: function (oldType, newType, rationItemQuantity) { return this.isConcreteToCommercialConcrete(oldType, newType) && rationItemQuantity && rationItemQuantity != '0'; }, isMaterialType: function (type) { let materialType = [gljType.GENERAL_MATERIAL, gljType.GREEN_SEEDLING, gljType.PURCHASE_COMPONENT, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]; //可以添加材料计算的类型普通材料”、“绿化苗木”、“外购砼构件”、“商品混凝土”、“商品砂浆” return materialType.indexOf(type) != -1 }, isConcreteToCommercialConcrete: function (oldType, newType) { return gljUtil.isConcreteType(oldType) && gljUtil.isCommercialConcreteType(newType) }, hasComposition: function (ration_glj, isRationType) { //判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。 let type = isRationType == true ? ration_glj.subType : ration_glj.type; if (this.notEditType.indexOf(type) != -1 || type == gljType.MAIN_MATERIAL) { let keyArray = isRationType == true ? rationKeyArray : gljKeyArray; let con_key = this.getIndex(ration_glj, keyArray); var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap; if (mixRatioMap[con_key] && mixRatioMap[con_key].length > 0) { return true; } } return false; }, getCCSProjectGLJ: function (unitFileID, project_id) { return { "ratio_data": [], "unit_price": { "base_price": "1", "market_price": "1", "code": "80CCS", "name": "车船税", "unit_price_file_id": unitFileID, "type": 302, "short_name": "机", "glj_id": -99, "unit": "元", "original_code": "80CCS", "id": -99, "is_add": 0, "specs": "" }, "glj_id": -99, "project_id": project_id, "code": "80CCS", "unit": "元", "type": 302, "original_code": "80CCS", "id": -99, "from": "std", "is_main_material": 1, "specs": "", "is_adjust_price": 0, "delivery_address": "", "delivery": "", "supply_quantity": 0, "supply": 0, "is_evaluate": 0, "name": "车船税" } }, getBaseCCSMixRatio: function (unitFileID, consumption, connect_key) { return { glj_id: -99, unit_price_file_id: unitFileID, connect_key: connect_key, consumption: consumption, code: '80CCS', name: '车船税', unit: '元', type: 302, specs: '', from: "cpt" } }, updateProperty: function (obj, doc) { let lo_sh = typeof _ !== 'undefined' ? _ : this._; lo_sh.forEach(doc, function (n, key) { obj[key] = n; }); }, getTotalQuantity: function (glj, ration, rd, gd) { if (ration) { let quantity = ration.quantity; quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity; quantity = scMathUtil.roundForObj(quantity, rd); //计算前进行4舍5入 glj.quantity = scMathUtil.roundForObj(glj.quantity, gd); let pglj = calcTools.getProjectGLJ(glj); glj.tenderQuantity = this.getRationGLJTenderQuantity(glj, ration, gd, scMathUtil, pglj); return scMathUtil.roundToString(quantity * glj.quantity, gd); } }, setMaterialCalcRationFee: function (ration, ration_gljs, projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, _, scMathUtil) { let pMap = _.indexBy(projectGLJDatas.gljList, 'id'); let process_decimal = decimalObj.process; let ration_quantity_decimal = decimalObj.ration.quantity; let glj_quantity_decimal = decimalObj.glj.quantity; let glj_unitPrice_decimal = decimalObj.glj.unitPrice; let assFeeRate = scMathUtil.roundForObj(projectGLJDatas.constData.assistProductionFeeRate, decimalObj.feeRate) * 0.01; //辅助生产间接费费率 let rationLaberFee = 0; //定额人工费(市场价) let rationMachineFee = 0; //定额施工机械使用费(市场价) let rationLaberFee_b = 0; //定额人工费(定额价) let rationMachineFee_b = 0; //定额施工机械使用费(定额价) let directFee = 0; //直接费 let rationQuantity = scMathUtil.roundForObj(ration.quantity, ration_quantity_decimal); for (let g of ration_gljs) { let result = this.getGLJPrice(pMap[g.projectGLJID], projectGLJDatas, calcOptions, labourCoeDatas, decimalObj, false, _, scMathUtil); g.marketPrice = result.marketPrice; g.basePrice = result.basePrice; let quantity = scMathUtil.roundForObj(g.quantity, glj_quantity_decimal); let t = scMathUtil.roundForObj(quantity * g.marketPrice * rationQuantity, process_decimal); //市场价 let rt = scMathUtil.roundForObj(quantity * g.basePrice * rationQuantity, process_decimal); //定额价 if (g.type == this.gljType.LABOUR) { rationLaberFee = scMathUtil.roundForObj(rationLaberFee + t, process_decimal); rationLaberFee_b = scMathUtil.roundForObj(rationLaberFee_b + rt, process_decimal); } else if (this.getMainType(g.type) == 3) { rationMachineFee = scMathUtil.roundForObj(rationMachineFee + t, process_decimal); rationMachineFee_b = scMathUtil.roundForObj(rationMachineFee_b + rt, process_decimal); } directFee = scMathUtil.roundForObj(directFee + t, process_decimal); } ration.assistProductionFee = scMathUtil.roundForObj(rationLaberFee_b * assFeeRate, glj_unitPrice_decimal); //辅助生产间接费 ration.rationLaberFee = scMathUtil.roundForObj(rationLaberFee, glj_unitPrice_decimal); //定额人工费(市场价) ration.rationMachineFee = scMathUtil.roundForObj(rationMachineFee, glj_unitPrice_decimal); //定额施工机械使用费(市场价) ration.directFee = scMathUtil.roundForObj(directFee, glj_unitPrice_decimal); //直接费 //to do 高原取费类别的情况待确认 //let hs = scMathUtil.roundForObj(tt*hightFeeRate,process_decimal);//(人工定额消耗量*定额价*定额工程量+机械定额消耗量*定额价*定额工程量)*高原取费类别费率 }, getAssUsedPrice: function (g) { return g.basePrice; }, getElecCoe: function () { return 0.15; }, getElecCode: function () { return '3005002'; }, getTenderPriceCoe: function (glj, tproperty) { let tenderCoe = 1; let property = tproperty ? tproperty : projectObj.project.property; if (!glj.is_adjust_price && property.tenderSetting && isDef(property.tenderSetting.gljPriceTenderCoe)) { tenderCoe = parseFloat(property.tenderSetting.gljPriceTenderCoe); if (tenderCoe == 0) tenderCoe = 1; } return tenderCoe; function isDef(v) { return v !== undefined && v !== null; } }, setProperty: function (Obj, updateData) { let lo_sh = typeof _ !== 'undefined' ? _ : this._; for (let ukey in updateData) { if (lo_sh.isObject(updateData[ukey]) && lo_sh.isObject(Obj[ukey]) && !lo_sh.isArray(updateData[ukey])) { setProperty(Obj[ukey], updateData[ukey]); } else { Obj[ukey] = updateData[ukey]; } } }, isKGtoT: function (bills_unit, ration_unit) { //是否由KG转成T,b_unit清单单位,t_unit定额单位 let t_unit = ration_unit ? ration_unit : ""; let b_unit = bills_unit ? bills_unit : ""; return (/.*kg$/i).test(b_unit) && (/.*t$/i).test(t_unit); }, fixedFlag: { // 分部分项工程 SUB_ENGINERRING: 1, // 措施项目 MEASURE: 2, // 施工技术措施项目 CONSTRUCTION_TECH: 3 }, gljType: { LABOUR: 1, // 人工 // ==============材料类型 ↓================= GENERAL_MATERIAL: 201, // 普通材料 CONCRETE: 202, // 混凝土 MORTAR: 203, // 砂浆 MIX_RATIO: 204, // 配合比 COMMERCIAL_CONCRETE: 205, // 商品混凝土 COMMERCIAL_MORTAR: 206, // 商品砂浆 OTHER_MATERIAL: 207, // 其它材料 PURCHASE_COMPONENT: 208, // 外购砼构件 GREEN_SEEDLING: 209, // 绿化苗木 // ==============材料类型 ↑================= // ==============机械类型 ↓================= GENERAL_MACHINE: 301, // 机械台班 MACHINE_COMPOSITION: 302, // 机械组成物 MACHINE_LABOUR: 303, // 机上人工 INSTRUMENT: 304, // 仪器仪表 FUEL_POWER_FEE: 305, // 燃料动力费 DEPRECIATION_FEE: 306, // 折旧费 INSPECTION_FEE: 307, // 检修费 MAINTENANCE: 308, // 维护费 DISMANTLING_FREIGHT_FEE: 309, // 安拆费及场外运费 VERIFICATION_FEE: 310, // 校验费 OTHER_FEE: 311, // 其他费用 OTHER_MACHINE_USED: 312, // 其他施工机具使用费 // ==============机械类型 ↑================= MAIN_MATERIAL: 4, // 主材 EQUIPMENT: 5, // 设备 MANAGEMENT_FEE: 6, // 企业管理费 PROFIT: 7, // 利润 GENERAL_RISK_FEE: 8 // 一般风险费 }, extraType: [6, 7, 8], //一些其它的工料机类型 notEditType: [202, 203, 204, 301, 304, 4], gljKeyArray: ['code', 'name', 'specs', 'unit', 'type'], rationType: { ration: 1, volumePrice: 2, gljRation: 3, install: 4 }, hasCompMaterial: [202, 203, 204], //有组成物的材料 hasCompMachine: [301], //有组成物的机械 machineComposition: [201, 302, 303] //可以做为机械组成物的类型 } if (typeof module !== 'undefined') { gljUtil._ = require("lodash"); module.exports = gljUtil; }