calc_program.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. let me = this;
  48. if (treeNode.sourceType === this.project.Ration.getSourceType()) {
  49. treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
  50. }
  51. else if (treeNode.sourceType === this.project.Bills.getSourceType()) {
  52. let rations = this.project.Ration.getBillsSortRation(treeNode.source.getID());
  53. treeNode.data.gljList = this.project.ration_glj.getGatherGljArrByRations(rations);
  54. };
  55. this.calc.calculate(treeNode);
  56. // 存储、刷新本结点、所有父结点
  57. if (treeNode.changed) {
  58. me.saveAndCalcParents(treeNode);
  59. delete treeNode.changed;
  60. };
  61. };
  62. saveAndCalcParents(treeNode) {
  63. if (treeNode.parent) {
  64. projectObj.converseCalculateBills(treeNode.parent);
  65. };
  66. let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
  67. let newDta = {'updateType': 'ut_update', 'updateData': data};
  68. let newDataArr = [];
  69. newDataArr.push(newDta);
  70. projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
  71. projectObj.mainController.refreshTreeNode([treeNode]);
  72. };
  73. initFees(treeNode){
  74. if (!treeNode.data.fees) {
  75. treeNode.data.fees = [];
  76. treeNode.data.feesIndex = {};
  77. treeNode.changed = true;
  78. };
  79. };
  80. checkFee(treeNode, ftObj){
  81. if (!treeNode.data.feesIndex[ftObj.type]){
  82. let fee = {
  83. 'fieldName': ftObj.type,
  84. 'unitFee': ftObj.unitFee,
  85. 'totalFee': ftObj.totalFee,
  86. 'tenderUnitFee': 0,
  87. 'tenderTotalFee': 0
  88. };
  89. treeNode.data.fees.push(fee);
  90. treeNode.data.feesIndex[ftObj.type] = fee;
  91. treeNode.changed = true;
  92. }
  93. else{
  94. if (treeNode.data.feesIndex[ftObj.type].unitFee != ftObj.unitFee){
  95. treeNode.data.feesIndex[ftObj.type].unitFee = ftObj.unitFee;
  96. treeNode.changed = true;
  97. };
  98. if (treeNode.data.feesIndex[ftObj.type].totalFee != ftObj.totalFee){
  99. treeNode.data.feesIndex[ftObj.type].totalFee = ftObj.totalFee;
  100. treeNode.changed = true;
  101. };
  102. };
  103. };
  104. gatherFeeTypes(treeNode, gatherType){
  105. let me = this;
  106. let rst = [];
  107. if (treeNode.sourceType === this.project.Bills.getSourceType()) {
  108. me.initFees(treeNode);
  109. let objsArr = [];
  110. if (gatherType == CP_GatherType.rations){
  111. objsArr = this.project.Ration.getRationsByNode(treeNode);
  112. }else if (gatherType == CP_GatherType.bills){
  113. objsArr = treeNode.children;
  114. };
  115. for (let ft of feeType) {
  116. let ftObj = {};
  117. ftObj.type = ft.type;
  118. ftObj.name = ft.name;
  119. let uf = 0, tf = 0, tuf = 0, ttf = 0;
  120. for (let item of objsArr) {
  121. let data = {};
  122. if (gatherType == CP_GatherType.rations){
  123. data = item;
  124. }else if (gatherType == CP_GatherType.bills){
  125. data = item.data;
  126. };
  127. if (data.feesIndex && data.feesIndex[ft.type]) {
  128. uf = (uf + parseFloat(data.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
  129. tf = (tf + parseFloat(data.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
  130. tuf = (tuf + parseFloat(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
  131. ttf = (ttf + parseFloat(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
  132. };
  133. };
  134. ftObj.unitFee = uf.toDecimal(me.digit);
  135. ftObj.totalFee = tf.toDecimal(me.digit);
  136. ftObj.tenderUnitFee = tuf.toDecimal(me.digit);
  137. ftObj.tenderTotalFee = ttf.toDecimal(me.digit);
  138. me.checkFee(treeNode, ftObj);
  139. rst.push(ftObj);
  140. };
  141. if (treeNode.changed) {
  142. me.saveAndCalcParents(treeNode);
  143. delete treeNode.changed;
  144. };
  145. };
  146. return rst;
  147. };
  148. }