calc_program.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /**
  2. * Created by CSL on 2017-07-19.
  3. * 计算程序。所有定额、清单、父清单的计算都从此入。
  4. * dispExpr: F8*(L-1); expression: "@('8') * (L-1)";
  5. * 说明:F后跟行号,L替换人工系数值,@后跟ID。用到L的规则必须有labourCoeID属性(反过来不要求),
  6. * 用到费率的规则必须有feeRateID属性,当有该属性时,会自动显示费率值。
  7. */
  8. /* 新版GLD 取消了默认清单模板,所以这里废弃。先留着,预防不时之需。
  9. let defaultBillTemplate = {
  10. ID: 15,
  11. name: "清单公式",
  12. calcItems: [
  13. {
  14. ID: 1,
  15. code: "1",
  16. name: "定额直接费",
  17. dispExpr: "F2+F3+F4",
  18. expression: "@('2')+@('3')+@('4')",
  19. statement: "人工费+材料费+机械费",
  20. feeRate: null,
  21. memo: ''
  22. },
  23. {
  24. ID: 2,
  25. code: "1.1",
  26. name: "人工费",
  27. dispExpr: "HJ",
  28. expression: "HJ",
  29. statement: "合计",
  30. feeRate: 50,
  31. fieldName: 'labour',
  32. memo: ''
  33. },
  34. {
  35. ID: 3,
  36. code: "1.2",
  37. name: "材料费",
  38. dispExpr: "HJ",
  39. expression: "HJ",
  40. statement: "合计",
  41. feeRate: 30,
  42. fieldName: 'material',
  43. memo: ''
  44. },
  45. {
  46. ID: 4,
  47. code: "1.3",
  48. name: "机械费",
  49. dispExpr: "HJ",
  50. expression: "HJ",
  51. statement: "合计",
  52. feeRate: 20,
  53. fieldName: 'machine',
  54. memo: ''
  55. },
  56. {
  57. ID: 5,
  58. code: "2",
  59. name: "企业管理费",
  60. dispExpr: "F1",
  61. expression: "@('1')",
  62. statement: "定额直接费",
  63. feeRate: null,
  64. fieldName: 'manage',
  65. memo: ''
  66. },
  67. {
  68. ID: 6,
  69. code: "3",
  70. name: "利润",
  71. dispExpr: "F1",
  72. expression: "@('1')",
  73. statement: "定额直接费",
  74. feeRate: null,
  75. fieldName: 'profit',
  76. memo: ''
  77. },
  78. {
  79. ID: 7,
  80. code: "4",
  81. name: "风险费用",
  82. dispExpr: "F1",
  83. expression: "@('1')",
  84. statement: "定额直接费",
  85. feeRate: null,
  86. fieldName: 'risk',
  87. memo: ''
  88. },
  89. {
  90. ID: 8,
  91. code: "5",
  92. name: "综合单价",
  93. dispExpr: "F1+F5+F6+F7",
  94. expression: "@('1')+@('5')+@('6')+@('7')",
  95. statement: "定额直接费+企业管理费+利润+风险费用",
  96. feeRate: null,
  97. fieldName: 'common',
  98. memo: ''
  99. }
  100. ]
  101. };*/
  102. const baseCalcType = {baseCalc: 0, adjustCalc: 1, budgetCalc: 2, diffCalc: 3, offerCalc: 4};
  103. let rationCalcBase = [
  104. {
  105. 'dispName': '定额基价人工费',
  106. 'calcType': baseCalcType.baseCalc,
  107. 'gljTypes': [gljType.LABOUR]
  108. },
  109. {
  110. 'dispName': '定额基价材料费',
  111. 'calcType': baseCalcType.baseCalc,
  112. 'gljTypes': [gljType.GENERAL_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]
  113. },
  114. {
  115. 'dispName': '定额基价机械费',
  116. 'calcType': baseCalcType.baseCalc,
  117. 'gljTypes': [gljType.GENERAL_MACHINE]
  118. },
  119. {
  120. 'dispName': '定额基价机上人工费',
  121. 'calcType': baseCalcType.baseCalc,
  122. 'gljTypes': [gljType.MACHINE_LABOUR]
  123. },
  124. {
  125. 'dispName': '人工费价差',
  126. 'calcType': baseCalcType.diffCalc,
  127. 'gljTypes': [gljType.LABOUR]
  128. },
  129. {
  130. 'dispName': '材料费价差',
  131. 'calcType': baseCalcType.diffCalc,
  132. 'gljTypes': [gljType.GENERAL_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO, gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR]
  133. },
  134. {
  135. 'dispName': '机械费价差',
  136. 'calcType': baseCalcType.diffCalc,
  137. 'gljTypes': [gljType.GENERAL_MACHINE]
  138. },
  139. {
  140. 'dispName': '主材费',
  141. 'calcType': baseCalcType.budgetCalc,
  142. 'gljTypes': [gljType.MAIN_MATERIAL]
  143. },
  144. {
  145. 'dispName': '设备费',
  146. 'calcType': baseCalcType.budgetCalc,
  147. 'gljTypes': [gljType.EQUIPMENT]
  148. }
  149. ];
  150. let cpFeeTypes = [
  151. {type: 'direct', name: '直接费'},
  152. {type: 'labour', name: '人工费'},
  153. {type: 'material', name: '材料费'},
  154. {type: 'machine', name: '机械费'},
  155. {type: 'mainMaterial', name: '主材费'},
  156. {type: 'equipment', name: '设备费'},
  157. {type: 'manage', name: '企业管理费'},
  158. {type: 'profit', name: '利润'},
  159. {type: 'risk', name: '风险费'},
  160. {type: 'labourDiff', name: '人工价差'},
  161. {type: 'materialDiff', name: '材料价差'},
  162. {type: 'machineDiff', name: '机械价差'},
  163. {type: 'adjustLabour', name: '调整人工费'},
  164. {type: 'adjustMachineLabour', name: '调整机上人工费'},
  165. {type: 'zangu', name: '暂估'},
  166. {type: 'fee1', name: '甲供材料费'},
  167. // 模拟用户新增
  168. {type: 'common', name: '工程造价'}
  169. ];
  170. let analyzer = {
  171. calcTemplate: null,
  172. success: true,
  173. standard: function(expr){
  174. let str = expr;
  175. str = str.replace(/\s/g, ""); // 去空格、去中文空格
  176. str = str.replace(/(/g, "("); // 中文括号"("换成英文括号"("
  177. str = str.replace(/)/g, ")"); // 中文括号")"换成英文括号")"
  178. str = str.replace(/f/g, "F"); // f换成F
  179. return str;
  180. },
  181. analyzeCalcBase: function(expr){
  182. // 前提:必须无空格、无特殊符号
  183. function getCalcBase(expr){
  184. let base = '',
  185. iPos1 = -1, iPos2 = -1;
  186. for (let i = 0; i < expr.length; i++) {
  187. if (expr[i] === '['){
  188. iPos1 = i;
  189. }
  190. else if (iPos1 != -1 && expr[i]===']'){
  191. iPos2 = i;
  192. };
  193. if (iPos1 != -1 && iPos2 != -1){
  194. base = expr.slice(iPos1, iPos2 + 1);
  195. break;
  196. }
  197. };
  198. return base;
  199. };
  200. function calcBaseToIDExpr(base){
  201. /*// for test. 公路模式,基数到ID
  202. let id = -1;
  203. if (base == '[人工费]'){
  204. id = 111;
  205. }
  206. else if (base == '[材料费]'){
  207. id = 222;
  208. }
  209. else if (base == '[机械费]'){
  210. id = 333;
  211. }
  212. else id = "错误";
  213. return "@('" + id + "')";*/
  214. let baseValue = base.slice(1, -1);
  215. return "base('" + baseValue + "')";
  216. };
  217. while (expr.indexOf('[') > 0) {
  218. let base = getCalcBase(expr);
  219. let id = calcBaseToIDExpr(base);
  220. let baseValue = base.slice(1, -1); // []会给下面的正则带来干扰,这里去掉
  221. var pattBase =new RegExp(baseValue, "g");
  222. expr = expr.replace(pattBase, id);
  223. expr = expr.replace(/\[base\('/g, "base('"); // [@(' [base('
  224. expr = expr.replace(/'\)\]/g, "')"); // ')]
  225. };
  226. return expr;
  227. },
  228. analyzeLineRef: function(expr){
  229. let me = this;
  230. function isOperator(char){
  231. var operator = "+-*/()";
  232. return operator.indexOf(char) > -1;
  233. };
  234. function lineNumToID(lineNum){
  235. if (lineNum > me.calcTemplate.calcItems.length){
  236. me.success = false;
  237. return '越界';
  238. }
  239. else{
  240. let id = me.calcTemplate.calcItems[lineNum - 1].ID;
  241. return id;
  242. }
  243. };
  244. // 前提:必须无空格、无特殊符号、标准大写F
  245. function getSection(expr){
  246. let section = '',
  247. iPos1 = -1, iPos2 = -1;
  248. for (let i = 0; i < expr.length; i++) {
  249. if (expr[i] === 'F'){
  250. iPos1 = i;
  251. }
  252. else if (iPos1 != -1 && isOperator(expr[i])){
  253. iPos2 = i;
  254. }
  255. else if (iPos1 != -1 && i == expr.length - 1){
  256. iPos2 = i + 1;
  257. };
  258. if (iPos1 != -1 && iPos2 != -1){
  259. section = expr.slice(iPos1, iPos2);
  260. break;
  261. }
  262. };
  263. return section;
  264. };
  265. function sectionToIDExpr(section){
  266. if (section){
  267. let lineNum = section.slice(1);
  268. if (isNaN(lineNum)){
  269. me.success = false;
  270. return '错误'; // 这里的返回提示不能加上section,因为会无限循环
  271. }
  272. else
  273. return "@('" + lineNumToID(lineNum) + "')";
  274. }
  275. else return '';
  276. };
  277. while (expr.indexOf('F') > 0) {
  278. let sec = getSection(expr);
  279. let id = sectionToIDExpr(sec);
  280. var pattSec =new RegExp(sec, "g");
  281. expr = expr.replace(pattSec, id);
  282. };
  283. return expr;
  284. },
  285. analyzeUserExpr: function(calcTemplate, calcItem){
  286. let me = this;
  287. me.calcTemplate = calcTemplate;
  288. let expr = calcItem.dispExpr;
  289. // 标准化:处理特殊字符、中文符号、大小写
  290. expr = me.standard(expr);
  291. calcItem.dispExpr = expr;
  292. // 先换掉计算基数
  293. expr = me.analyzeCalcBase(expr);
  294. // 再换掉行引用
  295. expr = me.analyzeLineRef(expr);
  296. calcItem.expression = expr;
  297. return me.success;
  298. }
  299. };
  300. let executeObj = {
  301. treeNode: null,
  302. template: null,
  303. calcBase: null,
  304. at: function(ID) {
  305. let me = executeObj,
  306. rst = 0;
  307. rst = me.template.compiledCalcItems[ID].unitFee;
  308. rst = parseFloat(rst);
  309. return rst;
  310. },
  311. base: function(calcBaseName) {
  312. let me = executeObj, rst = 0,
  313. base = me.calcBase[calcBaseName];
  314. if (base != null) {
  315. function isSubset(sub, arr){
  316. for(var i = 0, len = sub.length; i < len; i++){
  317. if(arr.indexOf(sub[i]) == -1) return false;
  318. }
  319. return true;
  320. };
  321. // 机上人工费:多一层
  322. function machineLabourFee() {
  323. if (!me.treeNode.data.gljList) return 0;
  324. let result = 0, mdSum = 0;
  325. for (let glj of me.treeNode.data.gljList) {
  326. if (glj.type == gljType.GENERAL_MACHINE) {
  327. // 获取机械组成物
  328. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  329. if (!mds) mds = [];
  330. for (let md of mds){
  331. if (base.gljTypes.indexOf(md.type) >= 0) {
  332. let q = md["consumption"] ? md["consumption"] : 0;
  333. let p = md["basePrice"] ? md["basePrice"] : 0;
  334. mdSum = mdSum + (q * p).toDecimal(decimalObj.process);
  335. mdSum = (mdSum).toDecimal(decimalObj.process);
  336. }
  337. };
  338. result = result + (glj["quantity"] * mdSum).toDecimal(decimalObj.process);
  339. result = (result).toDecimal(decimalObj.process);
  340. };
  341. };
  342. return result;
  343. };
  344. function commonGLJFee(){
  345. if (!me.treeNode.data.gljList) return 0;
  346. let result = 0;
  347. for (let glj of me.treeNode.data.gljList) {
  348. let price = 0, temp = 0;
  349. if (base.gljTypes.indexOf(glj.type) >= 0) {
  350. if (base.calcType == baseCalcType.diffCalc){
  351. let aprice = glj["adjustPrice"] ? glj["adjustPrice"] : 0;
  352. aprice = parseFloat(aprice);
  353. let mprice = glj["marketPrice"] ? glj["marketPrice"] : 0;
  354. mprice = parseFloat(mprice);
  355. temp = (glj["quantity"] * mprice).toDecimal(decimalObj.ration.unitPrice) - (glj["quantity"] * aprice).toDecimal(decimalObj.ration.unitPrice);
  356. temp = temp.toDecimal(decimalObj.ration.unitPrice);
  357. }
  358. else {
  359. if (base.calcType == baseCalcType.baseCalc){ price = parseFloat(glj["basePrice"]);}
  360. else if (base.calcType == baseCalcType.adjustCalc){price = parseFloat(glj["adjustPrice"]);}
  361. else if (base.calcType == baseCalcType.budgetCalc){price = parseFloat(glj["marketPrice"]);}
  362. temp = (glj["quantity"] * price).toDecimal(decimalObj.ration.unitPrice);
  363. };
  364. result = (result + temp).toDecimal(decimalObj.ration.unitPrice);
  365. };
  366. };
  367. return result;
  368. };
  369. // 量价。没有具体的工料机类型,但仍然要用定额的计算程序,所以要给计算基数直接指定。
  370. function volumePriceFee() {
  371. let result = 0;
  372. if (
  373. ( me.treeNode.data.subType === gljType.LABOUR && base.dispName === '定额基价人工费') ||
  374. ( me.treeNode.data.subType === gljType.GENERAL_MATERIAL && base.dispName === '定额基价材料费') ||
  375. ( me.treeNode.data.subType === gljType.GENERAL_MACHINE && base.dispName === '定额基价机械费') ||
  376. ( me.treeNode.data.subType === gljType.MAIN_MATERIAL && base.dispName === '主材费') ||
  377. ( me.treeNode.data.subType === gljType.EQUIPMENT && base.dispName === '设备费')
  378. ) result = me.treeNode.data.marketUnitFee ? me.treeNode.data.marketUnitFee : 0;
  379. return result;
  380. };
  381. if (me.treeNode.data.type == rationType.volumePrice || me.treeNode.data.type == rationType.gljRation){
  382. rst = volumePriceFee();
  383. }
  384. else{
  385. if (isSubset(base.gljTypes, [gljType.MACHINE_LABOUR]))
  386. rst = machineLabourFee()
  387. else
  388. rst = commonGLJFee();
  389. }
  390. };
  391. return rst;
  392. },
  393. HJ: function () {
  394. let me = this;
  395. let p = me.treeNode.data.calcBaseValue ? me.treeNode.data.calcBaseValue : 0;
  396. let q = me.treeNode.data.quantity ? me.treeNode.data.quantity : 1;
  397. let u = (p / q).toDecimal(decimalObj.decimal('unitPrice', me.treeNode));
  398. return u;
  399. }
  400. };
  401. let treeNodeTools = {
  402. // 获取全部有公式的树节点清单
  403. getFormulaNodes: function () {
  404. let nodes = [];
  405. for (let node of projectObj.project.mainTree.items){
  406. if (node.sourceType == ModuleNames.bills && node.data.calcBase && node.data.calcBase != '')
  407. nodes.push(node);
  408. };
  409. if (nodes.length >= 2) return this.orderFormulaNodes(nodes)
  410. else return nodes;
  411. },
  412. // 给公式结点清单换照引用计算顺序排序。
  413. orderFormulaNodes: function (nodesArr) {
  414. let orderArr = [];
  415. function getNodesByExp(expression){
  416. // for test --------------
  417. function getNode(name) {
  418. for (let node of projectObj.project.mainTree.items){
  419. if (node.data.name == name)
  420. return node;
  421. };
  422. };
  423. if (expression.hasSubStr("{措施项目费}")){
  424. let node = getNode('措施项目');
  425. return [node];
  426. }
  427. else if (expression.hasSubStr("{技术措施项目费}")){
  428. let node = getNode('1.技术措施项目');
  429. return [node];
  430. }
  431. // -------------------------------
  432. return [];
  433. };
  434. function recursionNode(nodes) {
  435. for (let node of nodes){
  436. if (orderArr.includes(node)) continue; // 已排过序的节点则跳过
  437. if (node.data.calcBase){
  438. let subNodes = getNodesByExp(node.data.calcBase);
  439. recursionNode(subNodes);
  440. };
  441. if (nodesArr.includes(node) && !orderArr.includes(node)) orderArr.push(node);
  442. };
  443. }
  444. recursionNode(nodesArr);
  445. return orderArr;
  446. },
  447. isBill: function(treeNode){
  448. return treeNode.sourceType === ModuleNames.bills;
  449. },
  450. isLeafBill: function(treeNode){
  451. return treeNode.sourceType === ModuleNames.bills &&
  452. treeNode.source.children &&
  453. treeNode.source.children.length === 0;
  454. },
  455. isNullBill: function (treeNode) {
  456. return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (!treeNode.data.calcBase);
  457. },
  458. isRationCategory: function(treeNode){
  459. return treeNode.sourceType === ModuleNames.ration;
  460. },
  461. isRation: function(treeNode){
  462. return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.ration;
  463. },
  464. isVolumePrice: function (treeNode) {
  465. return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.volumePrice;
  466. },
  467. isGljRation: function (treeNode) {
  468. return treeNode.sourceType === ModuleNames.ration && treeNode.data.type === rationType.gljRation;
  469. },
  470. initFeeField(treeNode, fieldName){
  471. if (!treeNode.data.fees) {
  472. treeNode.data.fees = [];
  473. treeNode.data.feesIndex = {};
  474. };
  475. if (!treeNode.data.feesIndex[fieldName]) {
  476. let fee = {
  477. 'fieldName': fieldName,
  478. 'unitFee': 0,
  479. 'totalFee': 0,
  480. 'tenderUnitFee': 0,
  481. 'tenderTotalFee': 0
  482. };
  483. treeNode.data.fees.push(fee);
  484. treeNode.data.feesIndex[fieldName] = fee;
  485. };
  486. },
  487. getCalcType(treeNode) {
  488. if (this.isRationCategory(treeNode)){
  489. return treeNodeCalcType.ctRationCalcProgram;
  490. }
  491. else if (this.isNullBill(treeNode)){
  492. return treeNodeCalcType.ctCommonUnitFee;
  493. }
  494. else if (this.isLeafBill(treeNode)) {
  495. if (treeNode.children && treeNode.children.length > 0){
  496. // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
  497. if (projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  498. return treeNodeCalcType.ctBillCalcProgram;
  499. else // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
  500. return treeNodeCalcType.ctGatherRationsFees;
  501. }
  502. else{ // 公式计算
  503. return treeNodeCalcType.ctCalcBaseValue;
  504. };
  505. }
  506. else if (this.isBill(treeNode)) { // 父清单:汇总子清单的费用类别
  507. return treeNodeCalcType.ctGatherBillsFees;
  508. }
  509. else {
  510. return treeNodeCalcType.ctRationCalcProgram;
  511. };
  512. }
  513. };
  514. class CalcProgram {
  515. constructor(project){
  516. let me = this;
  517. me.project = project;
  518. me.datas = [];
  519. project.registerModule(ModuleNames.calc_program, me);
  520. };
  521. // 兼容Project框架方法
  522. getSourceType () {
  523. return ModuleNames.calc_program;
  524. };
  525. // 兼容Project框架方法
  526. loadData (datas) {
  527. this.datas = datas;
  528. this.compileAllTemps();
  529. };
  530. // 兼容Project框架方法
  531. doAfterUpdate (err, data) {
  532. if(!err){
  533. $.bootstrapLoading.end();
  534. }
  535. };
  536. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  537. compileAllTemps(){
  538. let me = this;
  539. me.compiledFeeRates = {};
  540. me.compiledLabourCoes = {};
  541. me.compiledTemplates = {};
  542. me.compiledTemplateMaps = {};
  543. me.compiledTemplateNames = [];
  544. me.compiledFeeTypeMaps = {};
  545. me.compiledFeeTypeNames = [];
  546. me.compiledCalcBases = {};
  547. me.saveForReports = [];
  548. me.feeRates = this.project.FeeRate.datas.rates;
  549. me.labourCoes = this.project.labourCoe.datas.coes;
  550. me.feeTypes = cpFeeTypes;
  551. me.calcBases = rationCalcBase;
  552. me.templates = this.project.calcProgram.datas.templates;
  553. // me.templates.push(defaultBillTemplate);
  554. // 先编译公用的基础数据
  555. me.compilePublics();
  556. for (let t of me.templates){
  557. me.compileTemplate(t);
  558. };
  559. // 存储费率临时数据,报表用。
  560. if (me.saveForReports.length > 0){
  561. let saveDatas = {};
  562. saveDatas.projectID = projectInfoObj.projectInfo.ID;
  563. saveDatas.calcItems = me.saveForReports;
  564. CommonAjax.post('/calcProgram/saveCalcItems', saveDatas, function (data) {
  565. me.saveForReports = [];
  566. });
  567. };
  568. };
  569. compilePublics(){
  570. let me = this;
  571. for (let rate of me.feeRates) {
  572. me.compiledFeeRates[rate.ID] = rate;
  573. }
  574. for (let coe of me.labourCoes) {
  575. me.compiledLabourCoes[coe.ID] = coe;
  576. }
  577. for (let ft of me.feeTypes) {
  578. me.compiledFeeTypeMaps[ft.type] = ft.name;
  579. me.compiledFeeTypeMaps[ft.name] = ft.type; // 中文预编译,可靠性有待验证
  580. me.compiledFeeTypeNames.push(ft.name);
  581. }
  582. for (let cb of me.calcBases) {
  583. me.compiledCalcBases[cb.dispName] = cb; // 中文预编译,可靠性有待验证
  584. }
  585. };
  586. compileTemplate(template){
  587. let me = this;
  588. me.compiledTemplates[template.ID] = template;
  589. me.compiledTemplateMaps[template.ID] = template.name;
  590. me.compiledTemplateMaps[template.name] = template.ID;
  591. me.compiledTemplateNames.push(template.name);
  592. template.hasCompiled = false;
  593. template.errs = [];
  594. let private_extract_ID = function(str, idx){
  595. let rst = '', lBracket = 0, rBracket = 0, firstIdx = idx, lastIdx = 0;
  596. for (let i = idx; i < str.length; i++) {
  597. if (str[i] === '(') {
  598. lBracket++;
  599. if (lBracket == 1) firstIdx = i + 1;
  600. }
  601. if (str[i] === ')') {
  602. rBracket++;
  603. if (lBracket == rBracket) {
  604. lastIdx = i - 1;
  605. if (lastIdx > firstIdx) {
  606. if (str[firstIdx] === "'") firstIdx++;
  607. if (str[lastIdx] !== "'") lastIdx++;
  608. if (lastIdx > firstIdx) {
  609. rst = str.slice(firstIdx, lastIdx);
  610. }
  611. }
  612. break;
  613. }
  614. }
  615. }
  616. return rst;
  617. };
  618. let private_parse_ref = function(item, itemIdx){
  619. let idx = item.expression.indexOf('@(', 0);
  620. while (idx >= 0) {
  621. let ID = private_extract_ID(item.expression, idx);
  622. if (ID.length > 0) {
  623. let subItem = template.compiledCalcItems[ID];
  624. if (subItem) {
  625. if (subItem.ID !== item.ID) {
  626. private_parse_ref(subItem, template.compiledCalcItems[ID + "_idx"]);
  627. } else {
  628. template.errs.push("There exists the self refer ID: " + ID);
  629. }
  630. } else {
  631. template.errs.push("There exists the invalid ID by which could not find the item: " + ID);
  632. console.log('invalid ID: ' + ID);
  633. }
  634. }
  635. idx = item.expression.indexOf('@(', idx + ID.length + 3);
  636. }
  637. if (template.compiledSeq.indexOf(itemIdx) < 0) {
  638. template.compiledSeq.push(itemIdx);
  639. }
  640. };
  641. let private_compile_items = function() {
  642. for (let idx of template.compiledSeq) {
  643. let item = template.calcItems[idx];
  644. item.dispExprUser = item.dispExpr; // 用于界面显示。disExpr是公式模板,不允许修改:人工系数占位符被修改后变成数值,第二次无法正确替换。
  645. if (item.expression == 'HJ')
  646. item.compiledExpr = '$CE.HJ()'
  647. else{
  648. item.compiledExpr = item.expression.split('@(').join('$CE.at(');
  649. item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
  650. };
  651. if (item.labourCoeID){
  652. let lc = me.compiledLabourCoes[item.labourCoeID].coe;
  653. item.dispExprUser = item.dispExpr.replace(/L/gi, lc.toString());
  654. item.compiledExpr = item.compiledExpr.replace(/L/gi, lc.toString());
  655. };
  656. if (item.feeRateID) {
  657. let orgFeeRate = item.feeRate;
  658. let cmf = me.compiledFeeRates[item.feeRateID];
  659. item.feeRate = cmf?cmf.rate:100;
  660. if (!orgFeeRate || (orgFeeRate && orgFeeRate != item.feeRate)){
  661. me.saveForReports.push({templatesID: template.ID, calcItem: item});
  662. }
  663. };
  664. // 字段名映射
  665. item.displayFieldName = me.compiledFeeTypeMaps[item.fieldName];
  666. }
  667. };
  668. if (template && template.calcItems && template.calcItems.length > 0) {
  669. template.compiledSeq = [];
  670. template.compiledCalcItems = {};
  671. for (let i = 0; i < template.calcItems.length; i++) {
  672. let item = template.calcItems[i];
  673. template.compiledCalcItems[item.ID] = item;
  674. template.compiledCalcItems[item.ID + "_idx"] = i;
  675. }
  676. for (let i = 0; i < template.calcItems.length; i++) {
  677. let item = template.calcItems[i];
  678. if (template.compiledSeq.indexOf(i) < 0) {
  679. private_parse_ref(item, i);
  680. }
  681. }
  682. if (template.errs.length == 0) {
  683. private_compile_items();
  684. template.hasCompiled = true;
  685. } else {
  686. console.log('errors: ' + template.errs.toString());
  687. }
  688. };
  689. };
  690. // 存储、刷新零散的多个结点。
  691. saveNodes(treeNodes){
  692. if (treeNodes.length < 1) return;
  693. let me = this;
  694. me.project.beginUpdate('');
  695. for (let node of treeNodes){
  696. if (node.changed){
  697. let data = {
  698. ID: node.data.ID,
  699. projectID: me.project.ID(),
  700. /* subType、quantity、calcBase、programID、marketUnitFee等等字段较为特殊,它们的改变一定会触发计算并导致计算
  701. 结果的变化,从而引发保存动作。将这些字段放在该位置跟计算结果一起保存,可减少前端跟后端的通讯频率。 */
  702. subType: node.data.subType,
  703. quantity: node.data.quantity,
  704. calcBase: node.data.calcBase,
  705. calcBaseValue: node.data.calcBaseValue,
  706. programID: node.data.programID,
  707. marketUnitFee: node.data.marketUnitFee,
  708. marketTotalFee: node.data.marketTotalFee,
  709. fees: node.data.fees,
  710. isFromDetail:node.data.isFromDetail,
  711. feeRate: node.data.feeRate,
  712. feeRateID: node.data.feeRateID,
  713. contain:node.data.contain,
  714. quantityEXP:node.data.quantityEXP
  715. };
  716. if(node.sourceType==ModuleNames.ration && node.data.type==rationType.gljRation){//定额类型的工料机做特殊处理
  717. data.code=node.data.code;
  718. data.projectGLJID = node.data.projectGLJID;
  719. delete data.marketUnitFee;
  720. }
  721. let newData = {'updateType': 'ut_update', 'updateData': data};
  722. me.project.push(node.sourceType, [newData]);
  723. }
  724. };
  725. me.project.endUpdate();
  726. for (let node of treeNodes){delete node.changed};
  727. projectObj.mainController.refreshTreeNode(treeNodes);
  728. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  729. calcProgramObj.showData(me.project.mainTree.selected, false);
  730. };
  731. };
  732. // 只计算treeNode自身。changedArr: 外部传来的一个数组,专门存储发生变动的节点。
  733. innerCalc(treeNode, changedArr){
  734. let me = this;
  735. // 仅用作树节点显示的工料机不能参与计算。
  736. if (treeNode.sourceType === me.project.ration_glj.getSourceType()) return;
  737. treeNode.calcType = treeNodeTools.getCalcType(treeNode);
  738. // if (treeNode.calcType == treeNodeCalcType.ctCalcBaseValue) return;
  739. function initFees(treeNode){
  740. if (!treeNode.data.fees) {
  741. treeNode.data.fees = [];
  742. treeNode.data.feesIndex = {};
  743. treeNode.changed = true;
  744. };
  745. };
  746. function checkFee(treeNode, feeObj){
  747. if (feeObj.fieldName == '') return;
  748. if (!treeNode.data.feesIndex[feeObj.fieldName]){
  749. let fee = {
  750. 'fieldName': feeObj.fieldName,
  751. 'unitFee': feeObj.unitFee,
  752. 'totalFee': feeObj.totalFee,
  753. 'tenderUnitFee': 0,
  754. 'tenderTotalFee': 0
  755. };
  756. treeNode.data.fees.push(fee);
  757. treeNode.data.feesIndex[feeObj.fieldName] = fee;
  758. treeNode.changed = true;
  759. }
  760. else{
  761. if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee){
  762. treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
  763. treeNode.changed = true;
  764. };
  765. if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee){
  766. treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
  767. treeNode.changed = true;
  768. };
  769. };
  770. };
  771. function isBaseFeeType(type){
  772. return ['labour', 'material', 'machine', 'mainMaterial', 'equipment'].indexOf(type) > -1;
  773. };
  774. // 父清单汇总子项(定额或子清单)的费用类别
  775. if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees ||
  776. treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
  777. treeNode.data.programID = null;
  778. initFees(treeNode);
  779. let objsArr = (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees) ? me.project.Ration.getRationsByNode(treeNode) : treeNode.children;
  780. let rst = [];
  781. for (let ft of cpFeeTypes) {
  782. let ftObj = {};
  783. ftObj.fieldName = ft.type;
  784. ftObj.name = ft.name;
  785. let buf = 0, btf = 0, btuf = 0, bttf = 0;
  786. if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
  787. for (let item of objsArr) {
  788. let data = item.data;
  789. if (data.feesIndex && data.feesIndex[ft.type]) {
  790. buf = (buf + parseFloatPlus(data.feesIndex[ft.type].unitFee)).toDecimal(decimalObj.process);
  791. btf = (btf + parseFloatPlus(data.feesIndex[ft.type].totalFee)).toDecimal(decimalObj.process);
  792. btuf = (btuf + parseFloatPlus(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(decimalObj.process);
  793. bttf = (bttf + parseFloatPlus(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(decimalObj.process);
  794. };
  795. };
  796. }
  797. else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){ // 这里的算法要配合冷姐姐的神图才能看懂^_^
  798. let sum_rtf = 0, sum_rttf = 0;
  799. let bq = parseFloat(treeNode.data.quantity ? treeNode.data.quantity : 1);
  800. for (let data of objsArr) {
  801. let rq = parseFloat(data.quantity ? data.quantity : 0);
  802. let ruf = 0, rtuf = 0, rtf = 0, rttf = 0;
  803. if (data.feesIndex && data.feesIndex[ft.type]) {
  804. ruf = parseFloat(data.feesIndex[ft.type].unitFee);
  805. rtuf = parseFloat(data.feesIndex[ft.type].tenderUnitFee);
  806. rtf = parseFloat(data.feesIndex[ft.type].totalFee);
  807. rttf = parseFloat(data.feesIndex[ft.type].tenderTotalFee);
  808. };
  809. if (me.project.property.billsCalcMode === leafBillGetFeeType.rationContent) {
  810. buf = (buf + (ruf * rq / bq).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
  811. btuf = (btuf + (rtuf * rq / bq).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
  812. };
  813. sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
  814. sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
  815. };
  816. if (me.project.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse || me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice) {
  817. buf = (sum_rtf / bq).toDecimal(decimalObj.process);
  818. btuf = (sum_rttf / bq).toDecimal(decimalObj.process);
  819. };
  820. if (isBaseFeeType(ft.type) || (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")){
  821. btf = sum_rtf;
  822. bttf = sum_rttf;
  823. }
  824. else{
  825. btf = (buf * bq).toDecimal(decimalObj.process);
  826. bttf = (btuf * bq).toDecimal(decimalObj.process);
  827. };
  828. };
  829. ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
  830. ftObj.totalFee = btf.toDecimal(decimalObj.bills.totalPrice);
  831. ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
  832. ftObj.tenderTotalFee = bttf.toDecimal(decimalObj.bills.totalPrice);
  833. checkFee(treeNode, ftObj);
  834. rst.push(ftObj);
  835. };
  836. treeNode.data.calcTemplate = {"calcItems": rst};
  837. }
  838. // 叶子清单的手工综合单价计算
  839. else if (treeNode.calcType == treeNodeCalcType.ctCommonUnitFee){
  840. delete treeNode.data.gljList;
  841. if (treeNode.data.calcBase) treeNode.data.calcBase = null; // 不能直接删除该属性,否则无法冲掉库中已存储的值
  842. if (treeNode.data.calcBaseValue) treeNode.data.calcBaseValue = null; // 不能直接删除该属性,否则无法冲掉库中已存储的值
  843. if (treeNode.data.programID) treeNode.data.programID = null;
  844. let uf = (treeNode.data.feesIndex && treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.unitFee) ? treeNode.data.feesIndex.common.unitFee : 0;
  845. let tuf = (treeNode.data.feesIndex && treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.tenderUnitFee) ? treeNode.data.feesIndex.common.tenderUnitFee : 0;
  846. let q = treeNode.data.quantity ? treeNode.data.quantity : 0;
  847. let tf = (uf * q).toDecimal(decimalObj.bills.totalPrice);
  848. let ttf = (tuf * q).toDecimal(decimalObj.bills.totalPrice);
  849. delete treeNode.data.fees; // 直接删掉再新增,不用一个个费判断更新,效率更高。
  850. delete treeNode.data.feesIndex;
  851. treeNodeTools.initFeeField(treeNode, 'common');
  852. treeNode.data.feesIndex.common.unitFee = uf.toDecimal(decimalObj.bills.unitPrice);
  853. treeNode.data.feesIndex.common.totalFee = tf.toDecimal(decimalObj.bills.totalPrice);
  854. treeNode.data.feesIndex.common.tenderUnitFee = tuf.toDecimal(decimalObj.bills.unitPrice);
  855. treeNode.data.feesIndex.common.tenderTotalFee = ttf.toDecimal(decimalObj.bills.totalPrice);
  856. treeNode.changed = true;
  857. treeNode.data.calcTemplate = {"calcItems": []};
  858. }
  859. // 叶子清单公式计算
  860. else if (treeNode.calcType == treeNodeCalcType.ctCalcBaseValue){
  861. delete treeNode.data.gljList;
  862. if (treeNode.data.programID) treeNode.data.programID = null;
  863. let f = treeNode.data.feeRate ? treeNode.data.feeRate : 100;
  864. if (!treeNode.data.quantity) treeNode.data.quantity = 1;
  865. let q = treeNode.data.quantity;
  866. let b = treeNode.data.calcBaseValue ? treeNode.data.calcBaseValue : 0;
  867. let uf = (b * f * q / 100).toDecimal(decimalObj.bills.unitPrice);
  868. let tuf = uf;
  869. let tf = (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice) ? (b * f / 100).toDecimal(decimalObj.bills.totalPrice) : (uf * q).toDecimal(decimalObj.bills.totalPrice);
  870. let ttf = tf;
  871. delete treeNode.data.fees; // 直接删掉再新增,不用一个个费判断更新,效率更高。
  872. delete treeNode.data.feesIndex;
  873. treeNodeTools.initFeeField(treeNode, 'common');
  874. treeNode.data.feesIndex.common.unitFee = uf;
  875. treeNode.data.feesIndex.common.totalFee = tf;
  876. treeNode.data.feesIndex.common.tenderUnitFee = tuf;
  877. treeNode.data.feesIndex.common.tenderTotalFee = ttf;
  878. treeNode.changed = true;
  879. treeNode.data.calcTemplate = {"calcItems": []};
  880. }
  881. // 定额或叶子清单自己的计算程序计算
  882. else{
  883. if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
  884. if (treeNode.data.type == rationType.volumePrice){
  885. delete treeNode.data.gljList;
  886. let muf = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
  887. let q = treeNode.data.quantity ? treeNode.data.quantity : 0;
  888. treeNode.data.marketTotalFee = (muf * q).toDecimal(decimalObj.ration.totalPrice);
  889. }
  890. else if (treeNode.data.type == rationType.gljRation){
  891. }
  892. else{
  893. treeNode.data.gljList = me.project.ration_glj.getGljArrByRation(treeNode.data.ID);
  894. };
  895. if (treeNode.data.programID == undefined){
  896. treeNode.data.programID = projectInfoObj.projectInfo.property.engineering;
  897. };
  898. }
  899. else if (treeNode.calcType == treeNodeCalcType.ctBillCalcProgram) {
  900. let rations = me.project.Ration.getBillsSortRation(treeNode.source.getID());
  901. treeNode.data.gljList = me.project.ration_glj.getGatherGljArrByRations(rations);
  902. if (treeNode.data.programID == undefined){
  903. treeNode.data.programID = projectInfoObj.projectInfo.property.engineering;
  904. }
  905. };
  906. let template = me.compiledTemplates[treeNode.data.programID];
  907. treeNode.data.calcTemplate = template;
  908. if (treeNode && template.hasCompiled) {
  909. let $CE = executeObj;
  910. $CE.treeNode = treeNode;
  911. $CE.template = template;
  912. $CE.calcBase = me.compiledCalcBases;
  913. initFees(treeNode);
  914. for (let idx of template.compiledSeq) {
  915. let calcItem = template.calcItems[idx];
  916. let feeRate = calcItem.feeRate;
  917. if (!feeRate) feeRate = 100; // 100%
  918. feeRate = feeRate.toDecimal(decimalObj.feeRate);
  919. calcItem.unitFee = (eval(calcItem.compiledExpr) * feeRate * 0.01).toDecimal(decimalObj.decimal('unitPrice', treeNode)); // 如果eval()对清单树有影响,就换成小麦的Expression对象再试
  920. let quantity = treeNode.data.quantity;
  921. if (!quantity) quantity = 0
  922. else quantity = parseFloat(quantity).toDecimal(decimalObj.decimal('quantity', treeNode));
  923. calcItem.totalFee = (calcItem.unitFee * quantity).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  924. checkFee(treeNode, calcItem);
  925. };
  926. }
  927. };
  928. if (treeNode.changed && !changedArr.includes(treeNode)) changedArr.push(treeNode);
  929. };
  930. // 计算本节点、所有父节点(默认,可选)、公式引用节点。
  931. calculate(treeNode, calcParents = true, calcFormulas = true){
  932. let me = this;
  933. let changedNodes = [];
  934. me.innerCalc(treeNode, changedNodes);
  935. if (treeNode.changed) {
  936. // 计算父结点
  937. if (calcParents){
  938. let curNode = treeNode.parent;
  939. while (curNode){
  940. me.innerCalc(curNode, changedNodes);
  941. curNode = curNode.parent;
  942. };
  943. };
  944. // 父结点算完,再计算所有的公式结点(必须先算完父结点,再算公式结点)
  945. if (calcFormulas) {
  946. me.calcFormulaNodes(changedNodes);
  947. };
  948. };
  949. return changedNodes;
  950. };
  951. /* 计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。
  952. 参数取值如下:
  953. calcAllType.catAll 计算所有树结点 (不指定参数时的默认值)
  954. calcAllType.catBills 计算所有清单 (改变项目属性中清单取费算法时会用到)
  955. calcAllType.catRations 计算所有定额、工料机形式的定额、量价,因为它们都走自己的计算程序 (改变人工系数、费率值、工料机单价时会用到) */
  956. calcAllNodes(calcType = calcAllType.catAll){
  957. let me = this;
  958. let changedNodes = [];
  959. function calcNodes(nodes) {
  960. for (let node of nodes) {
  961. if (node.children.length > 0) {
  962. calcNodes(node.children);
  963. };
  964. if ((calcType == calcAllType.catAll || calcType == node.sourceType) && node.calcType != treeNodeCalcType.ctCalcBaseValue) {
  965. me.innerCalc(node, changedNodes);
  966. };
  967. }
  968. };
  969. calcNodes(me.project.mainTree.roots);
  970. me.calcFormulaNodes(changedNodes);
  971. return changedNodes;
  972. };
  973. // 计算全部公式项。 (参数意义:将通过本方法后发生改变的节点存入changedNodesArr中)
  974. calcFormulaNodes(changedArr){
  975. let me = this;
  976. let formulaNodes = treeNodeTools.getFormulaNodes();
  977. if (formulaNodes.length == 0) return;
  978. for (let formulaNode of formulaNodes){
  979. formulaNode.data.userCalcBase = formulaNode.data.calcBase; // 这句不该出现,projectObj.project.calcBase中要改进。
  980. projectObj.project.calcBase.calculate(formulaNode, true);
  981. if (projectObj.project.calcBase.success){
  982. // 计算公式结点
  983. me.innerCalc(formulaNode, changedArr);
  984. // 计算父结点
  985. if (formulaNode.changed){
  986. let curNode = formulaNode.parent;
  987. while (curNode){
  988. me.innerCalc(curNode, changedArr);
  989. curNode = curNode.parent;
  990. };
  991. };
  992. };
  993. };
  994. };
  995. // 计算叶子清单下的所有子结点、自身、所有父结点、公式引用结点(即跟该叶子清单相关的所有结点)。最后打包存储。
  996. calcLeafAndSave(treeNode){
  997. let me = this;
  998. if(!treeNodeTools.isLeafBill(treeNode)) return;
  999. if (treeNode.children && treeNode.children.length > 0) {
  1000. let changedNodes = [];
  1001. for (let child of treeNode.children){
  1002. me.innerCalc(child, changedNodes);
  1003. };
  1004. let curChangeds = me.calculate(treeNode);
  1005. mergeArr(changedNodes, curChangeds);
  1006. me.saveNodes(changedNodes);
  1007. };
  1008. };
  1009. // 计算多条零散的定额,并计算他们所属的清单、父级清单,然后打包存储。如:批量替换工料机后受影响的定额。
  1010. calcRationsAndSave(rationNodes){
  1011. let me = this, leafBills = [], allChangedNodes = [];
  1012. for (let node of rationNodes) {
  1013. me.innerCalc(node, allChangedNodes);
  1014. let leafBill = node.parent;
  1015. // 多条定额同属一条叶子清单时,避免叶子清单重复计算
  1016. if (leafBill && leafBills.indexOf(leafBill) < 0) leafBills.push(leafBill);
  1017. };
  1018. for (let node of leafBills){
  1019. let curChangeds = me.calculate(node);
  1020. mergeArr(allChangedNodes, curChangeds);
  1021. };
  1022. me.saveNodes(allChangedNodes);
  1023. };
  1024. // 计算并保存指定的一个树节点。修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点。
  1025. // 这个方法实际上封装了calculate()和saveNodes()两个方法,主要目的是为了外部调用方便,少写一点累赘代码。
  1026. calcAndSave(treeNode){
  1027. let changedNodes = this.calculate(treeNode);
  1028. this.saveNodes(changedNodes);
  1029. };
  1030. }