calc_program.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. let defaultBillTemplate = {
  8. ID: 15,
  9. name: "清单缺省",
  10. calcItems: [
  11. {
  12. ID: 1,
  13. code: "1",
  14. name: "定额直接费",
  15. dispExpr: "F2+F3+F4",
  16. expression: "@('2')+@('3')+@('4')",
  17. statement: "人工费+材料费+机械费",
  18. feeRate: null,
  19. memo: ''
  20. },
  21. {
  22. ID: 2,
  23. code: "1.1",
  24. name: "人工费",
  25. dispExpr: "HJ",
  26. expression: "HJ",
  27. statement: "合计",
  28. feeRate: 50,
  29. fieldName: 'labour',
  30. memo: ''
  31. },
  32. {
  33. ID: 3,
  34. code: "1.2",
  35. name: "材料费",
  36. dispExpr: "HJ",
  37. expression: "HJ",
  38. statement: "合计",
  39. feeRate: 30,
  40. fieldName: 'material',
  41. memo: ''
  42. },
  43. {
  44. ID: 4,
  45. code: "1.3",
  46. name: "机械费",
  47. dispExpr: "HJ",
  48. expression: "HJ",
  49. statement: "合计",
  50. feeRate: 20,
  51. fieldName: 'machine',
  52. memo: ''
  53. },
  54. {
  55. ID: 5,
  56. code: "2",
  57. name: "企业管理费",
  58. dispExpr: "F1",
  59. expression: "@('1')",
  60. statement: "定额直接费",
  61. feeRate: null,
  62. fieldName: 'manage',
  63. memo: ''
  64. },
  65. {
  66. ID: 6,
  67. code: "3",
  68. name: "利润",
  69. dispExpr: "F1",
  70. expression: "@('1')",
  71. statement: "定额直接费",
  72. feeRate: null,
  73. fieldName: 'profit',
  74. memo: ''
  75. },
  76. {
  77. ID: 7,
  78. code: "4",
  79. name: "风险费用",
  80. dispExpr: "F1",
  81. expression: "@('1')",
  82. statement: "定额直接费",
  83. feeRate: null,
  84. fieldName: 'risk',
  85. memo: ''
  86. },
  87. {
  88. ID: 8,
  89. code: "5",
  90. name: "综合单价",
  91. dispExpr: "F1+F5+F6+F7",
  92. expression: "@('1')+@('5')+@('6')+@('7')",
  93. statement: "定额直接费+企业管理费+利润+风险费用",
  94. feeRate: null,
  95. fieldName: 'common',
  96. memo: ''
  97. }
  98. ]
  99. };
  100. class CalcProgram {
  101. constructor(project){
  102. this.project = project;
  103. this.datas = [];
  104. this.calc = new Calculation();
  105. project.registerModule(ModuleNames.calc_program, this);
  106. };
  107. getSourceType () {
  108. return ModuleNames.calc_program;
  109. };
  110. loadData (datas) {
  111. this.datas = datas;
  112. };
  113. doAfterUpdate (err, data) {
  114. if(!err){
  115. // do
  116. }
  117. };
  118. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  119. compileAllTemps(){
  120. let calcFeeRates = this.project.FeeRate.datas.rates;
  121. let calcLabourCoes = this.project.labourCoe.datas.coes;
  122. let calcTemplates = this.project.calcProgram.datas.templates;
  123. calcTemplates.push(defaultBillTemplate);
  124. this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase);
  125. for (let ct of calcTemplates){
  126. this.calc.compileTemplate(ct);
  127. };
  128. // 存储费率临时数据,报表用。
  129. if (this.calc.saveForReports.length > 0){
  130. let saveDatas = {};
  131. saveDatas.projectID = projectInfoObj.projectInfo.ID;
  132. saveDatas.calcItems = this.calc.saveForReports;
  133. CommonAjax.post('/calcProgram/saveCalcItems', saveDatas, function (data) {
  134. this.calc.saveForReports = [];
  135. });
  136. };
  137. };
  138. calculate(treeNode){
  139. let me = this;
  140. me.calc.calculate(treeNode);
  141. // 还原,防止出现混乱影响下次计算
  142. delete treeNode.data.baseTotalPrice;
  143. delete treeNode.data.gatherType;
  144. // 存储、刷新本结点、所有父结点
  145. if (treeNode.changed) {
  146. me.saveAndCalcParents(treeNode);
  147. delete treeNode.changed;
  148. };
  149. };
  150. saveAndCalcParents(treeNode) {
  151. if (treeNode.parent) {
  152. projectObj.converseCalculateBills(treeNode.parent);
  153. };
  154. let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
  155. let newDta = {'updateType': 'ut_update', 'updateData': data};
  156. let newDataArr = [];
  157. newDataArr.push(newDta);
  158. projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
  159. projectObj.mainController.refreshTreeNode([treeNode]);
  160. };
  161. getCalcDatas(treeNode){
  162. let me = this;
  163. let rst = [];
  164. let isRation = treeNode.sourceType === me.project.Ration.getSourceType();
  165. let isBill = treeNode.sourceType === me.project.Bills.getSourceType();
  166. let isLeafBill = isBill && treeNode.source.children && treeNode.source.children.length === 0;
  167. let isBillPriceCalc = me.project.projSetting.billsCalcMode === billsPrice;
  168. if (isRation) {
  169. //
  170. }
  171. else if (isLeafBill) {
  172. let ct = '';
  173. if (treeNode.children && treeNode.children.length > 0){
  174. if (treeNode.children[0].sourceType == me.project.Ration.getSourceType()){
  175. ct = childrenType.ration;
  176. }
  177. else if (treeNode.children[0].sourceType == me.project.VolumePrice.getSourceType()){
  178. ct = childrenType.volumePrice;
  179. };
  180. }
  181. else{
  182. ct = childrenType.formula;
  183. };
  184. if (ct == childrenType.ration){
  185. if (isBillPriceCalc){ // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算
  186. }
  187. else{ // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
  188. treeNode.data.gatherType = CP_GatherType.rations;
  189. };
  190. }
  191. else if (ct == childrenType.volumePrice){
  192. let totalPrice = 10000;
  193. treeNode.data.baseTotalPrice = totalPrice;
  194. }
  195. else if (ct == childrenType.formula){
  196. let totalPrice = 20000;
  197. treeNode.data.baseTotalPrice = totalPrice;
  198. };
  199. }
  200. else if (isBill){ // 父清单:汇总子清单的费用类别
  201. treeNode.data.gatherType = CP_GatherType.bills;
  202. };
  203. me.calculate(treeNode);
  204. rst = treeNode.data.calcTemplate.calcItems;
  205. return rst;
  206. }
  207. }