/** * Created by CSL on 2017-07-19. * dispExpr: F8*(L-1); expression: "@('8') * (L-1)"; * 说明:F后跟行号,L替换人工系数值,@后跟ID。用到L的规则必须有labourCoeID属性(反过来不要求), * 用到费率的规则必须有feeRateID属性,当有该属性时,会自动显示费率值。 */ class CalcProgram { constructor(project){ this.project = project; this.datas = []; this.digit = 2; this.digitDefault = 6; 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; 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){ if (treeNode.sourceType === this.project.Ration.getSourceType()) { treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID); } else if (treeNode.sourceType === this.project.Bills.getSourceType()) { let rations = this.project.Ration.getBillsSortRation(treeNode.source.getID()); treeNode.data.gljList = this.project.ration_glj.getGatherGljArrByRations(rations); }; this.calc.calculate(treeNode); // 存储、刷新本结点、所有父结点 if (this.calc.changed){ if (treeNode.parent) { projectObj.converseCalculateBills(treeNode.parent); }; let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees}; let newDta = {'updateType': 'ut_update', 'updateData': data}; let newDataArr = []; newDataArr.push(newDta); projectObj.project.pushNow('', treeNode.sourceType, newDataArr); projectObj.mainController.refreshTreeNode([treeNode]); this.calc.changed = false; }; }; gatherCalcItems(treeNode){ let me = this; let rst = []; if (treeNode.sourceType === this.project.Bills.getSourceType()) { let rations = this.project.Ration.getRationsByNode(treeNode); for (let ft of feeType) { let ftObj = {}; ftObj.type = ft.type; ftObj.name = ft.name; let uf = 0, tf = 0, tuf = 0, ttf = 0; for (let ration of rations) { if (ration.feesIndex && ration.feesIndex[ft.type]) { uf = (uf + parseFloat(ration.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault); tf = (tf + parseFloat(ration.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault); tuf = (tuf + parseFloat(ration.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault); ttf = (ttf + parseFloat(ration.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault); }; }; ftObj.unitFee = uf; ftObj.totalFee = tf; ftObj.tenderUnitFee = tuf; ftObj.tenderTotalFee = ttf; rst.push(ftObj); }; }; return rst; } }