/** * 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){ let me = this; 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 (treeNode.changed) { me.saveAndCalcParents(treeNode); delete treeNode.changed; }; }; saveAndCalcParents(treeNode) { 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]); }; initFees(treeNode){ if (!treeNode.data.fees) { treeNode.data.fees = []; treeNode.data.feesIndex = {}; treeNode.changed = true; }; }; checkFee(treeNode, ftObj){ if (!treeNode.data.feesIndex[ftObj.type]){ let fee = { 'fieldName': ftObj.type, 'unitFee': ftObj.unitFee, 'totalFee': ftObj.totalFee, 'tenderUnitFee': 0, 'tenderTotalFee': 0 }; treeNode.data.fees.push(fee); treeNode.data.feesIndex[ftObj.type] = fee; treeNode.changed = true; } else{ if (treeNode.data.feesIndex[ftObj.type].unitFee != ftObj.unitFee){ treeNode.data.feesIndex[ftObj.type].unitFee = ftObj.unitFee; treeNode.changed = true; }; if (treeNode.data.feesIndex[ftObj.type].totalFee != ftObj.totalFee){ treeNode.data.feesIndex[ftObj.type].totalFee = ftObj.totalFee; treeNode.changed = true; }; }; }; gatherFeeTypes(treeNode, gatherType){ let me = this; let rst = []; if (treeNode.sourceType === this.project.Bills.getSourceType()) { me.initFees(treeNode); let objsArr = []; if (gatherType == CP_GatherType.rations){ objsArr = this.project.Ration.getRationsByNode(treeNode); }else if (gatherType == CP_GatherType.bills){ objsArr = treeNode.children; }; 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 item of objsArr) { let data = {}; if (gatherType == CP_GatherType.rations){ data = item; }else if (gatherType == CP_GatherType.bills){ data = item.data; }; if (data.feesIndex && data.feesIndex[ft.type]) { uf = (uf + parseFloat(data.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault); tf = (tf + parseFloat(data.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault); tuf = (tuf + parseFloat(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault); ttf = (ttf + parseFloat(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault); }; }; ftObj.unitFee = uf.toDecimal(me.digit); ftObj.totalFee = tf.toDecimal(me.digit); ftObj.tenderUnitFee = tuf.toDecimal(me.digit); ftObj.tenderTotalFee = ttf.toDecimal(me.digit); me.checkFee(treeNode, ftObj); rst.push(ftObj); }; if (treeNode.changed) { me.saveAndCalcParents(treeNode); delete treeNode.changed; }; }; return rst; }; }