/** * Created by CSL on 2017-07-19. * dispExpr: F8*(L-1); expression: "@('8') * (L-1)"; * 说明:F后跟行号,L替换人工系数值,@后跟ID。用到L的规则必须有labourCoeID属性(反过来不要求), * 用到费率的规则必须有feeRateID属性,当有该属性时,会自动显示费率值。 */ let defaultBillTemplate = { ID: 15, name: "清单缺省", calcItems: [ { ID: 1, code: "1", name: "定额直接费", dispExpr: "F2+F3+F4", expression: "@('2')+@('3')+@('4')", statement: "人工费+材料费+机械费", feeRate: null, memo: '' }, { ID: 2, code: "1.1", name: "人工费", dispExpr: "HJ", expression: "HJ", statement: "合计", feeRate: 50, fieldName: 'labour', memo: '' }, { ID: 3, code: "1.2", name: "材料费", dispExpr: "HJ", expression: "HJ", statement: "合计", feeRate: 30, fieldName: 'material', memo: '' }, { ID: 4, code: "1.3", name: "机械费", dispExpr: "HJ", expression: "HJ", statement: "合计", feeRate: 20, fieldName: 'machine', memo: '' }, { ID: 5, code: "2", name: "企业管理费", dispExpr: "F1", expression: "@('1')", statement: "定额直接费", feeRate: null, fieldName: 'manage', memo: '' }, { ID: 6, code: "3", name: "利润", dispExpr: "F1", expression: "@('1')", statement: "定额直接费", feeRate: null, fieldName: 'profit', memo: '' }, { ID: 7, code: "4", name: "风险费用", dispExpr: "F1", expression: "@('1')", statement: "定额直接费", feeRate: null, fieldName: 'risk', memo: '' }, { ID: 8, code: "5", name: "综合单价", dispExpr: "F1+F5+F6+F7", expression: "@('1')+@('5')+@('6')+@('7')", statement: "定额直接费+企业管理费+利润+风险费用", feeRate: null, fieldName: 'common', memo: '' } ] }; class CalcProgram { constructor(project){ this.project = project; this.datas = []; this.calc = new Calculation(); project.registerModule(ModuleNames.calc_program, this); }; getSourceType () { return ModuleNames.calc_program; }; loadData (datas) { this.datas = datas; }; doAfterUpdate (err, data) { if(!err){ // do } }; // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。 compileAllTemps(){ let calcFeeRates = this.project.FeeRate.datas.rates; let calcLabourCoes = this.project.labourCoe.datas.coes; let calcTemplates = this.project.calcProgram.datas.templates; calcTemplates.push(defaultBillTemplate); this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase); for (let ct of calcTemplates){ this.calc.compileTemplate(ct); }; // 存储费率临时数据,报表用。 if (this.calc.saveForReports.length > 0){ let saveDatas = {}; saveDatas.projectID = projectInfoObj.projectInfo.ID; saveDatas.calcItems = this.calc.saveForReports; CommonAjax.post('/calcProgram/saveCalcItems', saveDatas, function (data) { this.calc.saveForReports = []; }); }; }; // 计算本节点(默认同时递归计算所有父节点,可选) calculate(treeNode, calcParents = true){ let me = this; let isRation = treeNode.sourceType === me.project.Ration.getSourceType(); let isBill = treeNode.sourceType === me.project.Bills.getSourceType(); let isLeafBill = isBill && treeNode.source.children && treeNode.source.children.length === 0; let isBillPriceCalc = me.project.projSetting.billsCalcMode === billsPrice; if (isRation) treeNode.calcType = treeNodeCalcType.ctRationCalcProgram else if (isLeafBill) { if (treeNode.children && treeNode.children.length > 0){ if (treeNode.children[0].sourceType == me.project.Ration.getSourceType()){ if (isBillPriceCalc) // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算 treeNode.calcType = treeNodeCalcType.ctBillCalcProgram; else // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别 treeNode.calcType = treeNodeCalcType.ctGatherRations; } else if (treeNode.children[0].sourceType == me.project.VolumePrice.getSourceType()){ let value = 20000; // if (treeNode.data.feesIndex && treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.unitFee != 0) // value = treeNode.data.feesIndex.common.unitFee; treeNode.calcType = treeNodeCalcType.ctCalcBaseValue; treeNode.calcBaseValue = value; }; } else{ // 公式计算 let value = 20000; // if (treeNode.data.feesIndex && treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.unitFee != 0) // value = treeNode.data.feesIndex.common.unitFee; treeNode.calcType = treeNodeCalcType.ctCalcBaseValue; treeNode.calcBaseValue = value; }; } else if (isBill) // 父清单:汇总子清单的费用类别 treeNode.calcType = treeNodeCalcType.ctGatherBills; me.calc.calculate(treeNode); // 计算所有父结点 if (treeNode.changed && calcParents && treeNode.parent) { me.calculate(treeNode.parent); }; }; // 存储、刷新本节点(默认存储刷新所有父节点,可选) saveNode(treeNode, saveParent = true) { if (!treeNode.changed) return; let newDataArr = [], nodesArr = []; let project = projectObj.project; project.beginUpdate(''); let curNode = treeNode; while (curNode) { if (curNode.changed){ let data = { ID: curNode.data.ID, projectID: projectObj.project.ID(), quantity: curNode.data.quantity, fees: curNode.data.fees }; let newDta = {'updateType': 'ut_update', 'updateData': data}; newDataArr.push(newDta); nodesArr.push(curNode); project.push(curNode.sourceType, newDataArr); }; if (saveParent) curNode = curNode.parent else break; }; project.endUpdate(); for (let node of nodesArr){delete node.changed;}; projectObj.mainController.refreshTreeNode(nodesArr); }; }