calc_program.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Created by CSL on 2017-07-19.
  3. * dispExpr: F8*(L-1); expression: "@('8') * (L-1)";
  4. * 说明:F后跟行号,L替换人工系数值,@后跟ID。用到L的规则必须有labourCoeID属性(反过来不要求),
  5. * 用到费率的规则必须有feeRateID属性,当有该属性时,会自动显示费率值。
  6. */
  7. class CalcProgram {
  8. constructor(project){
  9. this.project = project;
  10. this.datas = [];
  11. this.calc = new Calculation();
  12. project.registerModule(ModuleNames.calc_program, this);
  13. };
  14. getSourceType () {
  15. return ModuleNames.calc_program;
  16. };
  17. loadData (datas) {
  18. this.datas = datas;
  19. };
  20. doAfterUpdate (err, data) {
  21. if(!err){
  22. // do
  23. }
  24. };
  25. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  26. compileAllTemps(){
  27. let calcFeeRates = this.project.FeeRate.datas.rates;
  28. let calcLabourCoes = this.project.labourCoe.datas.coes;
  29. let calcTemplates = this.project.calcProgram.datas.templates;
  30. this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase);
  31. for (let ct of calcTemplates){
  32. this.calc.compileTemplate(ct);
  33. };
  34. // 存储费率临时数据,报表用。
  35. if (this.calc.saveForReports.length > 0){
  36. let saveDatas = {};
  37. saveDatas.projectID = projectInfoObj.projectInfo.ID;
  38. saveDatas.calcItems = this.calc.saveForReports;
  39. CommonAjax.post('/calcProgram/saveCalcItems', saveDatas, function (data) {
  40. this.calc.saveForReports = [];
  41. });
  42. };
  43. };
  44. calculate(treeNode){
  45. if (treeNode.sourceType === this.project.Ration.getSourceType()) {
  46. treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
  47. }
  48. else if (treeNode.sourceType === this.project.Bills.getSourceType()) {
  49. let rations = this.project.Ration.getBillsSortRation(treeNode.source.getID());
  50. treeNode.data.gljList = this.project.ration_glj.getGatherGljArrByRations(rations);
  51. };
  52. this.calc.calculate(treeNode);
  53. // 存储、刷新本结点、所有父结点
  54. if (this.calc.changed){
  55. let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
  56. let newDta = {'updateType': 'ut_update', 'updateData': data};
  57. let newDataArr = [];
  58. newDataArr.push(newDta);
  59. projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
  60. projectObj.mainController.refreshTreeNode([treeNode]);
  61. if (treeNode.parent) {
  62. projectObj.converseCalculateBills(treeNode.parent);
  63. }
  64. this.calc.changed = false;
  65. };
  66. }
  67. }