calc_program.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.digit = 2;
  12. this.digitDefault = 6;
  13. this.calc = new Calculation();
  14. project.registerModule(ModuleNames.calc_program, this);
  15. };
  16. getSourceType () {
  17. return ModuleNames.calc_program;
  18. };
  19. loadData (datas) {
  20. this.datas = datas;
  21. };
  22. doAfterUpdate (err, data) {
  23. if(!err){
  24. // do
  25. }
  26. };
  27. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  28. compileAllTemps(){
  29. let calcFeeRates = this.project.FeeRate.datas.rates;
  30. let calcLabourCoes = this.project.labourCoe.datas.coes;
  31. let calcTemplates = this.project.calcProgram.datas.templates;
  32. this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase);
  33. for (let ct of calcTemplates){
  34. this.calc.compileTemplate(ct);
  35. };
  36. // 存储费率临时数据,报表用。
  37. if (this.calc.saveForReports.length > 0){
  38. let saveDatas = {};
  39. saveDatas.projectID = projectInfoObj.projectInfo.ID;
  40. saveDatas.calcItems = this.calc.saveForReports;
  41. CommonAjax.post('/calcProgram/saveCalcItems', saveDatas, function (data) {
  42. this.calc.saveForReports = [];
  43. });
  44. };
  45. };
  46. calculate(treeNode){
  47. if (treeNode.sourceType === this.project.Ration.getSourceType()) {
  48. treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
  49. }
  50. else if (treeNode.sourceType === this.project.Bills.getSourceType()) {
  51. let rations = this.project.Ration.getBillsSortRation(treeNode.source.getID());
  52. treeNode.data.gljList = this.project.ration_glj.getGatherGljArrByRations(rations);
  53. };
  54. this.calc.calculate(treeNode);
  55. // 存储、刷新本结点、所有父结点
  56. if (this.calc.changed){
  57. if (treeNode.parent) {
  58. projectObj.converseCalculateBills(treeNode.parent);
  59. };
  60. let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
  61. let newDta = {'updateType': 'ut_update', 'updateData': data};
  62. let newDataArr = [];
  63. newDataArr.push(newDta);
  64. projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
  65. projectObj.mainController.refreshTreeNode([treeNode]);
  66. this.calc.changed = false;
  67. };
  68. };
  69. gatherCalcItems(treeNode){
  70. let me = this;
  71. let rst = [];
  72. if (treeNode.sourceType === this.project.Bills.getSourceType()) {
  73. let rations = this.project.Ration.getRationsByNode(treeNode);
  74. for (let ft of feeType) {
  75. let ftObj = {};
  76. ftObj.type = ft.type;
  77. ftObj.name = ft.name;
  78. let uf = 0, tf = 0, tuf = 0, ttf = 0;
  79. for (let ration of rations) {
  80. if (ration.feesIndex && ration.feesIndex[ft.type]) {
  81. uf = (uf + parseFloat(ration.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
  82. tf = (tf + parseFloat(ration.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
  83. tuf = (tuf + parseFloat(ration.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
  84. ttf = (ttf + parseFloat(ration.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
  85. };
  86. };
  87. ftObj.unitFee = uf;
  88. ftObj.totalFee = tf;
  89. ftObj.tenderUnitFee = tuf;
  90. ftObj.tenderTotalFee = ttf;
  91. rst.push(ftObj);
  92. };
  93. };
  94. return rst;
  95. }
  96. }