calc_program.js 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824
  1. /**
  2. * Created by CSL on 2017-07-19.
  3. * 计算程序。所有定额、清单、父清单的计算都从此入。
  4. */
  5. let calcTools = {
  6. getNodeByFlag: function (flag) {
  7. let bill = cbTools.findBill(flag);
  8. if (bill) return this.getNodeByID(bill.ID)
  9. else return null;
  10. },
  11. getNodeByID: function (ID){
  12. return cbTools.getNodeByID(ID);
  13. },
  14. // 是否是标题清单
  15. isTitleBills: function (node) {
  16. let flag = node.getFlag();
  17. return titleFlags.includes(flag);
  18. },
  19. isBill: function(treeNode){
  20. return treeNode.sourceType === ModuleNames.bills;
  21. },
  22. isParentBill: function (treeNode) {
  23. return this.isBill(treeNode) &&
  24. treeNode.source.children &&
  25. treeNode.source.children.length > 0;
  26. },
  27. isLeafBill: function(treeNode){ // 下面挂有定额的清单也是叶子清单
  28. return this.isBill(treeNode) &&
  29. treeNode.source.children &&
  30. treeNode.source.children.length === 0;
  31. },
  32. isLeafNode: function(treeNode){ // 最底层结点,如定额等。
  33. return treeNode.children.length === 0;
  34. },
  35. isBill_DXFY: function(treeNode){
  36. return this.isBill(treeNode) && treeNode.data.type == billType.DXFY;
  37. },
  38. isBill_FB: function(treeNode){
  39. return this.isBill(treeNode) && treeNode.data.type == billType.FB;
  40. },
  41. isBill_FX: function(treeNode){
  42. return this.isBill(treeNode) && treeNode.data.type == billType.FX;
  43. },
  44. isBill_BILL: function(treeNode){
  45. return this.isBill(treeNode) && treeNode.data.type == billType.BILL;
  46. },
  47. isBill_BX: function(treeNode){
  48. return this.isBill(treeNode) && treeNode.data.type == billType.BX;
  49. },
  50. isNullBill: function (treeNode) {
  51. return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (!treeNode.data.calcBase);
  52. },
  53. isCalcBaseBill: function(treeNode){
  54. return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (treeNode.data.calcBase);
  55. },
  56. isTotalCostBill: function (treeNode) {
  57. return treeNode.data.flagsIndex && treeNode.data.flagsIndex.fixed && treeNode.data.flagsIndex.fixed.flag &&
  58. treeNode.data.flagsIndex.fixed.flag == fixedFlag.ENGINEERINGCOST;
  59. },
  60. isRationCategory: function(treeNode){
  61. return treeNode.sourceType === ModuleNames.ration;
  62. },
  63. isRationItem: function(treeNode){
  64. return this.isRationCategory(treeNode) && treeNode.data.type === rationType.ration;
  65. },
  66. isCalcManageRation:function(treeNode){
  67. return this.isRationCategory(treeNode) && (treeNode.data.type === rationType.ration || treeNode.data.type === rationType.install|| treeNode.data.type === rationType.itemIncrease);
  68. },
  69. isVolumePrice: function (treeNode) {
  70. return this.isRationCategory(treeNode) && treeNode.data.type === rationType.volumePrice;
  71. },
  72. isGljRation: function (treeNode) {
  73. return this.isRationCategory(treeNode) && treeNode.data.type === rationType.gljRation;
  74. },
  75. isVP_or_GLJR: function (treeNode) { // 是量价或工料机类型的定额
  76. return this.isRationCategory(treeNode) &&
  77. (treeNode.data.type == rationType.volumePrice || treeNode.data.type == rationType.gljRation);
  78. },
  79. isSameTypeNode: function (node1, node2) {
  80. if (node1.parent && node2.parent && (node1.parent === node2.parent) && (node1.sourceType === node1.sourceType)
  81. && (node1.data && node2.data && node1.data.type === node2.data.type)){
  82. return true;
  83. }
  84. return false;
  85. },
  86. isInheritFrom: function (treeNode, flagsArr){
  87. let cur = treeNode;
  88. while (cur.parent) {
  89. cur = cur.parent;
  90. };
  91. let flag = -1;
  92. if (cur.data.flagsIndex && cur.data.flagsIndex.fixed && cur.data.flagsIndex.fixed.flag)
  93. flag = cur.data.flagsIndex.fixed.flag;
  94. return flagsArr.includes(flag);
  95. },
  96. isFBFX:function (treeNode) {
  97. return projectObj.project.Bills.isFBFX(treeNode);
  98. },
  99. isTechMeasure:function(treeNode){
  100. return projectObj.project.Bills.isTechMeasure(treeNode)
  101. },
  102. canCalcToTalFeeByOwn: function (treeNode) {
  103. return !projectObj.project.Bills.cantCalcToTalFeeByOwn(treeNode);
  104. },
  105. getChildrenFormulaNodes: function (self, allFormulaNodesArr, parentNodes){ // 获取结点parentNodes下有公式的子结点
  106. let nodes = [];
  107. for (let pn of parentNodes){
  108. for (let node of allFormulaNodesArr){
  109. let cur = node;
  110. while (cur) {
  111. if (cur == pn && node != self){
  112. nodes.push(node);
  113. break;
  114. }
  115. cur = cur.parent;
  116. };
  117. };
  118. };
  119. return nodes;
  120. },
  121. /* 重要说明:
  122. 此时得到的GLJList,每条glj都有tenderQuantity = glj的quantity * 定额的quantity * glj的消耗量调整系数coe。
  123. 与定额的tenderQuantity无关,与定额的子目工程量调整系数coe无关。例如:
  124. 例:定额AB0003,工程量5,下含工料机“建筑综合工”,消耗量0.202。调价:人材机单价系数4,人工系数3,子目工程量系数2。
  125. 则GLJList中的建筑综合工:quantity 1.01, tenderQuantity 3.03。marketPrice 115, tenderPrice 460。
  126. */
  127. getGLJList: function (treeNode, needOneBill) {
  128. delete treeNode.data.gljList;
  129. if (this.isRationCategory(treeNode)) {
  130. if (!calcTools.isVP_or_GLJR(treeNode)){
  131. treeNode.data.gljList = projectObj.project.calcProgram.getGljArrByRation(treeNode.data);
  132. }
  133. }
  134. else if (this.isBill(treeNode)){
  135. treeNode.data.gljList = projectObj.project.ration_glj.getGljArrByBill(treeNode, needOneBill);
  136. };
  137. },
  138. getGLJListByProgramID: function (programID) {
  139. return null;
  140. },
  141. getLeafBills: function (treeNode){
  142. let leafBills = [];
  143. function getBill(node){
  144. if (!node) return;
  145. if (calcTools.isLeafBill(node))
  146. leafBills.push(node);
  147. if (node.firstChild()) getBill(node.firstChild());
  148. if (node.nextSibling) getBill(node.nextSibling);
  149. };
  150. let fc = treeNode.firstChild();
  151. if (fc) getBill(fc);
  152. return leafBills;
  153. },
  154. forceSelect: function (treeNode, rowsCount = 1, colsCount = 2){
  155. projectObj.mainController.tree.selected = treeNode;
  156. let tree = treeNode.tree;
  157. let idx = tree.items.indexOf(treeNode);
  158. let sheet = projectObj.mainSpread.getActiveSheet();
  159. sheet.setSelection(idx, 0, rowsCount, colsCount);
  160. sheet.showRow(idx, GC.Spread.Sheets.VerticalPosition.center);
  161. },
  162. initFees: function (treeNode){
  163. if (!treeNode.data.fees) {
  164. treeNode.data.fees = [];
  165. treeNode.data.feesIndex = {};
  166. treeNode.changed = true;
  167. }
  168. else if (!treeNode.data.feesIndex){
  169. treeNode.data.feesIndex = {};
  170. for (let fee of treeNode.data.fees){
  171. treeNode.data.feesIndex[fee.fieldName] = fee;
  172. };
  173. treeNode.changed = true;
  174. };
  175. },
  176. initFeeField: function (treeNode, fieldName){
  177. this.initFees(treeNode);
  178. if (!treeNode.data.feesIndex[fieldName]) {
  179. let fee = {
  180. 'fieldName': fieldName,
  181. 'unitFee': 0,
  182. 'totalFee': 0,
  183. 'tenderUnitFee': 0,
  184. 'tenderTotalFee': 0
  185. };
  186. treeNode.data.fees.push(fee);
  187. treeNode.data.feesIndex[fieldName] = fee;
  188. treeNode.changed = true;
  189. };
  190. },
  191. checkFeeField: function (treeNode, feeObj){
  192. if (!feeObj) return;
  193. if (feeObj.fieldName == '') return;
  194. // 初始化前,先拦截属性未定义、又要给该属性赋0的情况
  195. if (!treeNode.data.feesIndex || !treeNode.data.feesIndex[feeObj.fieldName]){
  196. if (feeObj.unitFee == 0 && feeObj.totalFee == 0 && feeObj.tenderUnitFee == 0 && feeObj.tenderTotalFee == 0) return;
  197. }
  198. this.initFeeField(treeNode, feeObj.fieldName);
  199. if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee){
  200. treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
  201. treeNode.changed = true;
  202. };
  203. if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee){
  204. treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
  205. treeNode.changed = true;
  206. };
  207. // 不知在何种情况下,tenderUnitFee、tenderTotalFee的值会变成NaN,这里提前处理一下
  208. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee))
  209. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee = undefined;
  210. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee))
  211. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee = undefined;
  212. if (treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee != feeObj.tenderUnitFee){
  213. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee = feeObj.tenderUnitFee;
  214. treeNode.changed = true;
  215. };
  216. if (treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee != feeObj.tenderTotalFee){
  217. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee = feeObj.tenderTotalFee;
  218. treeNode.changed = true;
  219. };
  220. },
  221. setFieldValue: function (treeNode, fieldName, value){
  222. if (fieldName.includes('feesIndex')){
  223. let arr = fieldName.split('.');
  224. this.initFeeField(treeNode, arr[1]);
  225. treeNode.data.feesIndex[arr[1]][arr[2]] = value;
  226. if(fieldName == 'feesIndex.common.unitFee'){
  227. let fee = _.find(treeNode.data.fees,{'fieldName':arr[1]});
  228. if(fee) fee[arr[2]] = value;
  229. }
  230. }
  231. else{
  232. treeNode.data[fieldName] = value;
  233. };
  234. treeNode.changed = true;
  235. },
  236. initSummaryFee: function (treeNode){
  237. if (!treeNode.data.summaryFees){
  238. treeNode.data.summaryFees = {
  239. totalFee: 0,
  240. estimateFee: 0,
  241. safetyFee: 0,
  242. chargeFee: 0
  243. };
  244. treeNode.changed = true;
  245. };
  246. },
  247. hasAdjustPrice: function(){ // 编办是否有材料的调整价发文
  248. if (projectObj.project.projSetting.glj_col && projectObj.project.projSetting.glj_col.showAdjustPrice == true)
  249. return true
  250. else
  251. return false;
  252. },
  253. // 参数fieldName值: 'common.totalFee'、'equipment.unitFee'
  254. getFee: function (treeNode, fieldName) {
  255. if (!treeNode) return 0;
  256. let ns = fieldName.split(".");
  257. if (ns.length != 2)
  258. return 0
  259. else if (treeNode.data.feesIndex && treeNode.data.feesIndex[ns[0]] && treeNode.data.feesIndex[ns[0]][ns[1]])
  260. return parseFloat(treeNode.data.feesIndex[ns[0]][ns[1]])
  261. else
  262. return 0;
  263. },
  264. rationBaseFee: function (treeNode, gljTypes, priceType, isTender){
  265. if (!treeNode.data.gljList) return 0;
  266. let me = this, result = 0;
  267. let price = 0, temp = 0, temp2 = 0;
  268. // 机械组成物价差: 机上人工、动力燃料
  269. if ((priceType == priceTypes.ptDiffPrice) && (gljTypes.includes(gljType.MACHINE_LABOUR) || gljTypes.includes(gljType.FUEL_POWER_FEE))){
  270. for (let glj of treeNode.data.gljList) {
  271. if ([gljType.GENERAL_MACHINE, gljType.INSTRUMENT].includes(glj.type)){
  272. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  273. if (!mds) mds = [];
  274. for (let md of mds){
  275. if (gljTypes.includes(md.type)){
  276. let gljQ = isTender ? me.uiGLJQty(glj["tenderQuantity"]) : me.uiGLJQty(glj["quantity"]);
  277. let mdMP = isTender ? md["tenderPrice"] : md["marketPrice"];
  278. let mdQ = me.uiGLJQty(md.consumption);
  279. let mdAP = calcTools.hasAdjustPrice() ? md["adjustPrice"] : md["basePrice"];
  280. // if (aprice != mprice){
  281. temp = (temp + (gljQ * mdQ * mdMP).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
  282. temp2 = (temp2 + (gljQ * mdQ * mdAP).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
  283. // }
  284. }
  285. }
  286. }
  287. }
  288. }
  289. // 普通基数计算(包括普通价差)
  290. else{
  291. for (let glj of treeNode.data.gljList) {
  292. if (gljTypes.indexOf(glj.type) >= 0) {
  293. let qty = isTender ? me.uiGLJQty(glj["tenderQuantity"]) : me.uiGLJQty(glj["quantity"]);
  294. // let mprice = isTender ? me.uiGLJPrice(glj["tenderPrice"], glj) : me.uiGLJPrice(glj["marketPrice"], glj);
  295. // let aprice = calcTools.hasAdjustPrice() ? me.uiGLJPrice(glj["adjustPrice"], glj) : me.uiGLJPrice(glj["basePrice"], glj);
  296. let mprice = isTender ? glj["tenderPrice"] : glj["marketPrice"];
  297. let aprice = calcTools.hasAdjustPrice() ? glj["adjustPrice"] : glj["basePrice"];
  298. if (priceType == priceTypes.ptDiffPrice){
  299. // if (aprice != mprice){
  300. temp = (temp + (qty * mprice).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
  301. temp2 = (temp2 + (qty * aprice).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
  302. // }
  303. }
  304. else {
  305. // if (priceType == priceTypes.ptBasePrice){ price = me.uiGLJPrice(glj["basePrice"], glj);}
  306. if (priceType == priceTypes.ptBasePrice){ price = glj["basePrice"];}
  307. else if (priceType == priceTypes.ptAdjustPrice){price = aprice;}
  308. else if (priceType == priceTypes.ptMarketPrice){price = mprice;}
  309. /*if (projectObj.project.property.areaSetting && treeNode.data.areaIncreaseFee){
  310. let p;
  311. if ([gljType.LABOUR].includes(glj.type))
  312. p = projectObj.project.property.areaSetting.labour
  313. else if (baseMaterialTypes.includes(glj.type))
  314. p = projectObj.project.property.areaSetting.material
  315. else if ([gljType.GENERAL_MACHINE].includes(glj.type))
  316. p = projectObj.project.property.areaSetting.machine;
  317. qty = qty * (1 + p * 0.01).toDecimal(decimalObj.process);
  318. }*/
  319. temp = (qty * price).toDecimal(decimalObj.process);
  320. result = (result + temp).toDecimal(decimalObj.process);
  321. };
  322. };
  323. };
  324. };
  325. if (priceType == priceTypes.ptDiffPrice){
  326. if (typeof isCQ2018 != 'undefined'){
  327. // 如下这一句十分重要!JS计算误差导致379.08-331.695=47.38499999999999。如果直接取2位会变成47.38。所以先取6位47.385,再取2位47.39。
  328. result = (temp - temp2).toDecimal(decimalObj.process);
  329. result = result.toDecimal(decimalObj.ration.unitPrice) // 重庆2018所有都是先汇总相减后再取舍
  330. }
  331. else{
  332. if (gljTypes == baseMaterialTypes)
  333. result = (temp - temp2).toDecimal(decimalObj.ration.unitPrice)
  334. else
  335. result = (temp.toDecimal(decimalObj.ration.unitPrice) - temp2.toDecimal(decimalObj.ration.unitPrice)).toDecimal(decimalObj.ration.unitPrice);
  336. };
  337. }
  338. else{
  339. result = result.toDecimal(decimalObj.ration.unitPrice);
  340. };
  341. return result;
  342. },
  343. // masterTypeFilter 过滤机械机型:[]全部, [1,2]特大机械 [3,4]中小机械。 detailType 如机上人工费、机械折旧费等
  344. machineDetailFee: function (treeNode, gljArr, masterTypeFilter, detailType, isTender) {
  345. if (!gljArr) return 0;
  346. let result = 0;
  347. for (let glj of gljArr) {
  348. if (baseMachineMasterTypes.includes(glj.type)){
  349. // 机型不符
  350. if ((masterTypeFilter.length > 0) && (glj.model && !masterTypeFilter.includes(glj.model))) continue;
  351. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  352. // 获取机械组成物(调价不深入到组成物)
  353. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  354. if (!mds) mds = [];
  355. let mdSum = 0;
  356. for (let md of mds) {
  357. if (md.type == detailType) {
  358. let q = md["consumption"] ? md["consumption"] : 0;
  359. // 下面这句从养护来,建筑暂时用不上,以后可能会用上
  360. // let p = isTender ? (md["tenderPrice"] ? md["tenderPrice"] : 0) : (md["marketPrice"] ? md["marketPrice"] : 0);
  361. let p = md["basePrice"] ? md["basePrice"] : 0;
  362. mdSum = mdSum + (q * p).toDecimal(decimalObj.glj.unitPriceHasMix);
  363. mdSum = (mdSum).toDecimal(decimalObj.glj.unitPriceHasMix);
  364. }
  365. }
  366. if (typeof isCQ2018 != 'undefined')
  367. result = (result + (gljQ * mdSum).toDecimal(decimalObj.process)).toDecimal(decimalObj.process)
  368. else
  369. result = (result + (gljQ * mdSum).toDecimal(decimalObj.ration.unitPrice)).toDecimal(decimalObj.ration.unitPrice);
  370. }
  371. }
  372. result = (result).toDecimal(decimalObj.ration.unitPrice);
  373. return result;
  374. },
  375. // 叶子清单、定额、总造价清单的暂估费。(父级清单是汇总子清单的暂估费,走计算程序逻辑,不在这里)
  376. estimateFee: function (treeNode, isBase, isTender){ // isBase, isTender 这两个参数用于基数计算
  377. let me = this, sumU = 0, sumT = 0, sumTU = 0, sumTT = 0;
  378. let nodeQ = me.uiNodeQty(treeNode);
  379. let nodeTQ = me.uiNodeTenderQty(treeNode);
  380. let isGather = (projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial);
  381. // 先汇总数量,再乘市场价。如果是叶子清单,进入这里的gljList中的材料,已经是同类材料跨定额汇总过的了。
  382. function eTFee(){
  383. let rst = {eT: 0, eTT: 0};
  384. if (!treeNode.data.gljList) return rst;
  385. let GLJObjs = [];
  386. for (let glj of treeNode.data.gljList) {
  387. if (!allMaterialTypes.includes(glj.type)) continue;
  388. if (glj.isEstimate){
  389. let q = me.uiGLJQty((glj.totalQuantity)).toDecimal(decimalObj.process);
  390. GLJObjs.push({code: glj.code, name: glj.name, specs: glj.specs, unit: glj.unit, type: glj.type, quantity: q,
  391. marketPrice: glj.marketPrice, tenderQuantity: glj.tenderQuantity, tenderPrice: glj.tenderPrice});
  392. }
  393. else{ // 组成物
  394. if (!compositionTypes.includes(glj.type)) continue;
  395. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  396. if (!mds) mds = [];
  397. for (let md of mds){
  398. if (!md.isEstimate) continue;
  399. let isExist = false;
  400. // let glj_totalQ = (nodeQ * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.glj.quantity);
  401. let glj_totalQ = me.uiGLJQty((glj.totalQuantity)).toDecimal(decimalObj.glj.quantity);
  402. let glj_tender_totalQ = (nodeTQ * me.uiGLJQty(glj.tenderQuantity)).toDecimal(decimalObj.glj.quantity);
  403. let mdQ = (glj_totalQ * me.uiGLJQty(md.consumption)).toDecimal(decimalObj.process);
  404. let mdTQ = (glj_tender_totalQ * me.uiGLJQty(md.consumption)).toDecimal(decimalObj.process);
  405. for (let obj of GLJObjs){
  406. if (gljOprObj.getIndex(md, gljKeyArray) == gljOprObj.getIndex(obj, gljKeyArray)){
  407. isExist = true;
  408. obj.quantity = (obj.quantity + mdQ).toDecimal(decimalObj.glj.quantity);
  409. obj.tenderQuantity = (obj.tenderQuantity + mdTQ).toDecimal(decimalObj.glj.quantity);
  410. break;
  411. }
  412. };
  413. if (!isExist)
  414. GLJObjs.push({code: md.code, name: md.name, specs: md.specs, unit: md.unit, type: md.type, quantity: mdQ,
  415. marketPrice: md.marketPrice, tenderQuantity: mdTQ, tenderPrice: md.tenderPrice});
  416. }
  417. }
  418. };
  419. for (let obj of GLJObjs){
  420. let t = (me.uiGLJQty(obj.quantity) * me.uiGLJPrice(obj.marketPrice, obj)).toDecimal(decimalObj.bills.totalPrice);
  421. rst.eT = (rst.eT + t).toDecimal(decimalObj.bills.totalPrice);
  422. let tt = (me.uiGLJQty(obj.tenderQuantity) * me.uiGLJPrice(obj.tenderPrice, obj)).toDecimal(decimalObj.bills.totalPrice);
  423. rst.eTT = (rst.eTT + tt).toDecimal(decimalObj.bills.totalPrice);
  424. };
  425. return rst;
  426. };
  427. // 汇总子结点的暂估合价
  428. function eTFeeByChildren(){
  429. let rst = {eT: 0, eTT: 0};
  430. for (let node of treeNode.children){
  431. if (node.data.feesIndex && node.data.feesIndex['estimate']) {
  432. rst.eT = (rst.eT + parseFloatPlus(node.data.feesIndex['estimate'].totalFee)).toDecimal(decimalObj.process);
  433. rst.eTT = (rst.eTT + parseFloatPlus(node.data.feesIndex['estimate'].tenderTotalFee)).toDecimal(decimalObj.process);
  434. };
  435. };
  436. rst.eT = (rst.eT).toDecimal(decimalObj.bills.totalPrice);
  437. rst.eTT = (rst.eTT).toDecimal(decimalObj.bills.totalPrice);
  438. return rst;
  439. };
  440. // 先数量乘市场价,再汇总
  441. function eUFee(){
  442. if (!treeNode.data.gljList) return 0;
  443. let rst = {eU: 0, eTU: 0};
  444. for (let glj of treeNode.data.gljList) {
  445. if (!allMaterialTypes.includes(glj.type)) continue;
  446. if (glj.isEstimate){
  447. rst.eU = rst.eU + (me.uiGLJQty(glj.quantity) * me.uiGLJPrice(glj.marketPrice, glj)).toDecimal(decimalObj.process);
  448. rst.eU = rst.eU.toDecimal(decimalObj.process);
  449. // 不能直接用glj.tenderPrice,这个值不可靠。当调价界面删除单价系数后,tenderPrice没有实时计算,取得的值为0
  450. rst.eTU = rst.eTU + (me.uiGLJQty(glj.tenderQuantity) * glj.tenderPrice).toDecimal(decimalObj.process);
  451. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  452. }
  453. else{ // 组成物。
  454. if (!compositionTypes.includes(glj.type)) continue;
  455. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  456. if (!mds) mds = [];
  457. for (let md of mds){
  458. if (!md.isEstimate) continue;
  459. let mdU = (me.uiGLJQty(md.consumption) * me.uiGLJPrice(md.marketPrice)).toDecimal(decimalObj.glj.unitPrice);
  460. rst.eU = rst.eU + (mdU * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.process);
  461. rst.eU = rst.eU.toDecimal(decimalObj.process);
  462. // 数量只调到工料机级别,工料机下的组成物不调量(如机械、混凝土)。调价调的是工料机下的组成物的价。
  463. let mdTU = (me.uiGLJQty(md.consumption) * md.tenderPrice).toDecimal(decimalObj.glj.unitPrice);
  464. rst.eTU = rst.eTU + (mdTU * glj.tenderQuantity).toDecimal(decimalObj.process);
  465. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  466. }
  467. }
  468. };
  469. rst.eU = rst.eU.toDecimal(decimalObj.bills.unitPrice);
  470. rst.eTU = rst.eTU.toDecimal(decimalObj.bills.unitPrice);
  471. return rst;
  472. };
  473. // 总造价暂估费
  474. if (me.isTotalCostBill(treeNode)){
  475. let nodes = treeNode.tree.roots;
  476. for (let node of nodes){
  477. if (me.isTotalCostBill(node)) break;
  478. let eU = 0, eT = 0, eTU = 0, eTT = 0;
  479. if (node.data.feesIndex && node.data.feesIndex.estimate){
  480. eU = node.data.feesIndex.estimate.unitFee;
  481. eT = node.data.feesIndex.estimate.totalFee;
  482. eTU = node.data.feesIndex.estimate.tenderUnitFee;
  483. eTT = node.data.feesIndex.estimate.tenderTotalFee;
  484. }
  485. else {
  486. eU = 0, eT = 0, eTU = 0, eTT = 0;
  487. };
  488. sumU = (sumU + parseFloatPlus(eU)).toDecimal(decimalObj.process);
  489. sumT = (sumT + parseFloatPlus(eT)).toDecimal(decimalObj.process);
  490. sumTU = (sumTU + parseFloatPlus(eTU)).toDecimal(decimalObj.process);
  491. sumTT = (sumTT + parseFloatPlus(eTT)).toDecimal(decimalObj.process);
  492. };
  493. sumU = (sumU).toDecimal(decimalObj.bills.unitPrice);
  494. sumT = (sumT).toDecimal(decimalObj.bills.totalPrice);
  495. sumTU = (sumTU).toDecimal(decimalObj.bills.unitPrice);
  496. sumTT = (sumTT).toDecimal(decimalObj.bills.totalPrice);
  497. }
  498. else if (me.isParentBill(treeNode)){ // 父清单不要汇总单价。
  499. let eTFBC = eTFeeByChildren();
  500. sumT = eTFBC.eT;
  501. sumTT = eTFBC.eTT;
  502. sumU = undefined;
  503. sumTU = undefined;
  504. }
  505. else if (me.isLeafBill(treeNode)){
  506. if (projectObj.project.Bills.isEngineerEst(treeNode)){
  507. if (treeNode.data.feesIndex['common'] != undefined){
  508. sumT = treeNode.data.feesIndex['common'].totalFee;
  509. sumU = treeNode.data.feesIndex['common'].unitFee;
  510. sumTT = treeNode.data.feesIndex['common'].tenderTotalFee;
  511. sumTU = treeNode.data.feesIndex['common'].tenderUnitFee;
  512. }
  513. }
  514. else{
  515. if (isGather){
  516. me.getGLJList(treeNode, false);
  517. let eTF = eTFee();
  518. sumT = eTF.eT;
  519. sumTT = eTF.eTT;
  520. }
  521. else{
  522. let eTFBC = eTFeeByChildren();
  523. sumT = eTFBC.eT;
  524. sumTT = eTFBC.eTT;
  525. };
  526. let q = nodeQ ? nodeQ : 1;
  527. sumU = (sumT / q).toDecimal(decimalObj.bills.totalPrice);
  528. let tq = nodeTQ ? nodeTQ : 1;
  529. sumTU = (sumTT / tq).toDecimal(decimalObj.bills.totalPrice);
  530. }
  531. }
  532. else if (me.isRationCategory(treeNode)){
  533. me.getGLJList(treeNode, false);
  534. let eUF = eUFee();
  535. sumU = eUF.eU;
  536. sumTU = eUF.eTU;
  537. if (isBase) {
  538. if (isTender)
  539. return sumTU
  540. else
  541. return sumU;
  542. };
  543. if (isGather){
  544. let eTF = eTFee();
  545. sumT = eTF.eT;
  546. sumTT = eTF.eTT;
  547. }
  548. else{
  549. sumT = (nodeQ * sumU).toDecimal(decimalObj.ration.totalPrice);
  550. sumTT = (nodeTQ * sumTU).toDecimal(decimalObj.ration.totalPrice);
  551. }
  552. };
  553. me.checkFeeField(treeNode, {'fieldName': 'estimate', 'unitFee': sumU, 'totalFee': sumT,
  554. 'tenderUnitFee': sumTU, 'tenderTotalFee': sumTT});
  555. },
  556. marketPriceToBase: function (treeNode, baseName, isTender) {
  557. if (!calcTools.isVP_or_GLJR(treeNode)) return;
  558. let result = 0, me = this;
  559. function isRCJZC(treeNode, baseName) { // 基数名称中是否包含人材机主设,且树结点类型要匹配一致
  560. let rst = (treeNode.data.subType === gljType.LABOUR && baseName.includes('人工')) || // 人工费、市场人工费
  561. (baseMaterialTypes.includes(treeNode.data.subType) && baseName.includes('材料')) ||
  562. // (treeNode.data.subType === gljType.GENERAL_MACHINE && (baseName.includes('机械') || baseName.includes('机具'))) ||
  563. (baseMachineTypes.includes(treeNode.data.subType) && (baseName.includes('机械') || baseName.includes('机具'))) ||
  564. (treeNode.data.subType === gljType.MAIN_MATERIAL && baseName.includes('主材')) ||
  565. (treeNode.data.subType === gljType.EQUIPMENT && baseName.includes('设备'));
  566. return rst;
  567. }
  568. if (baseName.includes('甲供') || baseName.includes('甲定') || baseName.includes('分包')) {
  569. result = 0;
  570. }
  571. else if (baseName.includes('价差')) {
  572. if (treeNode.data.type == rationType.gljRation) {
  573. if (isRCJZC(treeNode, baseName)) {
  574. let aprice = me.uiGLJPrice(treeNode.data.basePrice); // 量价虚拟的工料机不可能有发文,这里直接取定额价。
  575. let mprice = me.uiGLJPrice(treeNode.data.marketUnitFee);
  576. result = (mprice - aprice).toDecimal(decimalObj.ration.unitPrice);
  577. }
  578. }
  579. }
  580. else if (baseName.includes('机上人工')) {
  581. if (treeNode.data.subType === gljType.GENERAL_MACHINE) {
  582. let glj = {
  583. 'code': treeNode.data.code,
  584. 'name': treeNode.data.name,
  585. 'specs': treeNode.data.specs,
  586. 'unit': treeNode.data.unit,
  587. 'quantity': 1,
  588. 'type': treeNode.data.subType // 注意:这里要取subType
  589. };
  590. result = me.machineDetailFee(treeNode, [glj], [], gljType.MACHINE_LABOUR, isTender);
  591. }
  592. }
  593. else {
  594. if (isRCJZC(treeNode, baseName)) {
  595. if (calcTools.isVolumePrice(treeNode)){
  596. if (isTender){
  597. let coe = this.tenderCoe_GLJPrice();
  598. if (treeNode.data.marketUnitFee)
  599. result = (parseFloat(treeNode.data.marketUnitFee) * coe).toDecimal(decimalObj.ration.unitPrice)
  600. else
  601. result = 0;
  602. }
  603. else
  604. result = treeNode.data.marketUnitFee ? parseFloat(treeNode.data.marketUnitFee).toDecimal(decimalObj.ration.unitPrice) : 0
  605. }
  606. else if (calcTools.isGljRation(treeNode)) {
  607. // result = treeNode.data.basePrice ? parseFloat(treeNode.data.basePrice).toDecimal(decimalObj.ration.unitPrice) : 0;
  608. // 这里要取基价或市场价,但不能直接取basePrice,受限于项目属性的三个选项。
  609. if (baseName.includes('定额'))
  610. result = gljOprObj.getBasePrice(treeNode)
  611. else
  612. result = treeNode.data.marketUnitFee ? parseFloat(treeNode.data.marketUnitFee).toDecimal(decimalObj.ration.unitPrice) : gljOprObj.getBasePrice(treeNode);
  613. };
  614. }
  615. };
  616. return result;
  617. },
  618. partASupplyFee: function (treeNode, baseName, isTender, isRationPirce = true) { // isRationPirce 为true时表示取定额价。如:甲供定额材料费
  619. if (!treeNode.data.gljList) return 0;
  620. let projectGLJ = projectObj.project.projectGLJ;
  621. let supplyT = [];
  622. if (baseName.includes('甲供'))
  623. supplyT = [supplyType.BFJG, supplyType.WQJG] // 字段中存储的是汉字、数字混杂!
  624. else if (baseName.includes('甲定'))
  625. supplyT = [supplyType.JDYG];
  626. let gljT = [], compT = [];
  627. if (baseName.includes('人工')) gljT = [gljType.LABOUR]; // 含人工的:如甲供人工、甲定人工
  628. else if (baseName.includes('材料')){
  629. gljT = baseMaterialTypes;
  630. compT = compositionTypes;
  631. }
  632. else if (baseName.includes('机械') || baseName.includes('机具')) {
  633. gljT = baseMachineTypes;
  634. compT = [gljType.GENERAL_MACHINE, gljType.INSTRUMENT, gljType.OTHER_MACHINE_USED]; // 取并集,兼容重庆2018新定额
  635. }
  636. else if (baseName.includes('主材')) {
  637. gljT = [gljType.MAIN_MATERIAL];
  638. compT = [gljType.MAIN_MATERIAL];
  639. }
  640. else if (baseName.includes('设备')) {
  641. gljT = [gljType.EQUIPMENT];
  642. };
  643. // alert(JSON.stringify(projectGLJ.testGLJs()));
  644. let supplyGLJs = projectGLJ.getGLJsBySupply(supplyT, gljT);
  645. if (supplyGLJs.length == 0) return 0;
  646. let supplyGLJsIdx = {};
  647. for (let sglj of supplyGLJs){supplyGLJsIdx[sglj.id] = sglj};
  648. function isSupply(composition, supplies) {
  649. for (let supply of supplies){
  650. if(supply.code == composition.code && supply.name == composition.name && supply.unit == composition.unit &&
  651. supply.specs == composition.specs && supply.type == composition.type ){
  652. composition.basePrice = supply.unit_price.base_price;
  653. composition.marketPrice = supply.unit_price.market_price;
  654. composition.supply = supply.supply;
  655. composition.supplyX = 1;
  656. if (composition.supply == supplyType.BFJG){
  657. let Q = supply.quantity ? supply.quantity : 1;
  658. composition.supplyX = supply.supply_quantity / Q;
  659. }
  660. return true;
  661. }
  662. };
  663. return false;
  664. };
  665. let sum = 0;
  666. for (let glj of treeNode.data.gljList){
  667. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  668. let X = 1; // 部分甲供系数(默认1,即完全甲供)
  669. let tempSGLJ = supplyGLJsIdx[glj.projectGLJID];
  670. // 当前材料是甲供材料:①普通 ②商品硂等不计组成物的母体材料
  671. if (tempSGLJ) {
  672. // 处理部分甲供
  673. if (baseName.includes('甲供') && (tempSGLJ.supply == supplyType.BFJG)){
  674. let Q = isTender ? tempSGLJ.tenderQuantity : tempSGLJ.quantity;
  675. // let Q = tempSGLJ.quantity;
  676. Q = Q ? Q : 1;
  677. X = tempSGLJ.supply_quantity / Q;
  678. };
  679. let gljP = isRationPirce ? glj.basePrice : (isTender ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(glj)) : glj.marketPrice);
  680. sum = (sum + gljP * gljQ * X).toDecimal(decimalObj.process);
  681. }
  682. else{ // 当前材料不是甲供材料
  683. // 混凝土等。组成物的母体,母体如果有组成物,则母体无法作为甲供材料,无法设置,此时要看其组成物是否是甲供材料;母体如果没有组成物,则母体有可能成为甲供材料。
  684. if (compT.includes(glj.type)) {
  685. let pGLJ = projectGLJ.getDataByID(glj.projectGLJID);
  686. let compositions = pGLJ.ratio_data; // 组成物明细
  687. if (compositions.length > 0){
  688. for (let c of compositions){
  689. if (isSupply(c, supplyGLJs)) {
  690. X = 1;
  691. if (baseName.includes('甲供') && (c.supply == supplyType.BFJG)){
  692. X = c.supplyX;
  693. };
  694. let cP = isRationPirce ? c.basePrice : (isTender ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(c)) : c.marketPrice);
  695. sum = (sum + cP * c.consumption * gljQ * X).toDecimal(decimalObj.process);
  696. }
  697. }
  698. };
  699. }
  700. };
  701. };
  702. sum = sum.toDecimal(decimalObj.ration.unitPrice);
  703. return sum;
  704. },
  705. getCalcType: function (treeNode) {
  706. if (this.isRationCategory(treeNode)){
  707. return treeNodeCalcType.ctRationCalcProgram;
  708. }
  709. else if (this.isNullBill(treeNode)){
  710. return treeNodeCalcType.ctNull;
  711. }
  712. else if (this.isLeafBill(treeNode)) {
  713. if (treeNode.children && treeNode.children.length > 0){
  714. // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
  715. if (projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  716. return treeNodeCalcType.ctBillCalcProgram;
  717. else // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
  718. return treeNodeCalcType.ctGatherRationsFees;
  719. }
  720. else{ // 公式计算
  721. return treeNodeCalcType.ctCalcBaseValue;
  722. };
  723. }
  724. else if (this.isBill(treeNode)) { // 父清单:汇总子清单的费用类别
  725. return treeNodeCalcType.ctGatherBillsFees;
  726. }
  727. else {
  728. return treeNodeCalcType.ctRationCalcProgram;
  729. };
  730. },
  731. cutNodeForSave(treeNode){
  732. let me = this;
  733. /* subType、quantity、calcBase、programID、marketUnitFee等等字段较为特殊,它们的改变一定会触发计算并导致计算
  734. 结果的变化,从而引发保存动作。将这些字段放在该位置跟计算结果一起保存,可减少前端跟后端的通讯频率。 */
  735. let data = {
  736. projectID: projectObj.project.ID(),
  737. ID: treeNode.data.ID,
  738. unit: treeNode.data.unit, //对清单来说,改变单位,工程量精度会跟着改变从而影响计算。
  739. subType: treeNode.data.subType,
  740. quantity: treeNode.data.quantity,
  741. calcBase: treeNode.data.calcBase,
  742. calcBaseValue: treeNode.data.calcBaseValue,
  743. tenderCalcBaseValue: treeNode.data.tenderCalcBaseValue,
  744. programID: treeNode.data.programID,
  745. marketUnitFee: treeNode.data.marketUnitFee,
  746. marketTotalFee: treeNode.data.marketTotalFee,
  747. fees: treeNode.data.fees,
  748. isFromDetail:treeNode.data.isFromDetail,
  749. feeRate: treeNode.data.feeRate,
  750. feeRateID: treeNode.data.feeRateID,
  751. contain: treeNode.data.contain,
  752. quantityEXP: treeNode.data.quantityEXP,
  753. summaryFees: treeNode.data.summaryFees,
  754. name:treeNode.data.name,
  755. rationQuantityCoe: treeNode.data.rationQuantityCoe,
  756. quantityCoe: treeNode.data.quantityCoe == null ? {} : treeNode.data.quantityCoe,
  757. targetUnitFee: treeNode.data.targetUnitFee,
  758. targetTotalFee: treeNode.data.targetTotalFee
  759. };
  760. // 定额大类
  761. if (me.isRationCategory(treeNode)) {
  762. data.isSubcontract = treeNode.data.isSubcontract;
  763. data.evaluationProject = treeNode.data.evaluationProject;
  764. //定额类型的工料机做特殊处理
  765. if(me.isGljRation(treeNode)){
  766. data.code = treeNode.data.code;
  767. data.projectGLJID = treeNode.data.projectGLJID;
  768. delete data.marketUnitFee;
  769. };
  770. };
  771. // 优化掉 undefined 属性
  772. data = JSON.parse(JSON.stringify(data));
  773. return data;
  774. },
  775. uiNodeQty: function (treeNode){
  776. return parseFloatPlus(treeNode.data.quantity).toDecimal(decimalObj.decimal("quantity", treeNode));
  777. },
  778. // 在项目工料机里检查该工料机是否参与调价
  779. isTenderProjectGLJ: function (glj){
  780. let projGLJ = this.getProjectGLJ(glj);
  781. return !(projGLJ && projGLJ.is_adjust_price == 1);
  782. },
  783. // 取单价调价系数
  784. tenderCoe_GLJPrice: function (){
  785. let coe = 1;
  786. if (projectObj.project.property.tenderSetting && projectObj.project.property.tenderSetting.gljPriceTenderCoe){
  787. coe = projectObj.project.property.tenderSetting.gljPriceTenderCoe;
  788. if (coe == '0') coe = 1; // 这里加个保护
  789. };
  790. return coe;
  791. },
  792. tenderCoe_NodeQty: function (treeNode){
  793. let coe = 1;
  794. if (treeNode.data.rationQuantityCoe){
  795. coe = treeNode.data.rationQuantityCoe;
  796. if (coe == '0') coe = 1; // 这里加个保护
  797. };
  798. return coe;
  799. },
  800. tenderCoe_GLJQty: function (treeNode, glj){
  801. let coe = 1;
  802. if (!treeNode.data.quantityCoe) return coe;
  803. if (!calcTools.isTenderProjectGLJ(glj)) return coe;
  804. if (gljType.LABOUR == glj.type){
  805. if (treeNode.data.quantityCoe.labour)
  806. coe = treeNode.data.quantityCoe.labour;
  807. }
  808. else if (baseMaterialTypes.indexOf(glj.type)){
  809. if (treeNode.data.quantityCoe.material)
  810. coe = treeNode.data.quantityCoe.material;
  811. }
  812. else if (baseMachineTypes.indexOf(glj.type)){
  813. if (treeNode.data.quantityCoe.machine)
  814. coe = treeNode.data.quantityCoe.machine;
  815. }
  816. else if (gljType.MAIN_MATERIAL == glj.type){
  817. if (treeNode.data.quantityCoe.main)
  818. coe = treeNode.data.quantityCoe.main;
  819. }
  820. else if (gljType.EQUIPMENT == glj.type){
  821. if (treeNode.data.quantityCoe.equipment)
  822. coe = treeNode.data.quantityCoe.equipment;
  823. };
  824. if (coe == '0') coe = 1; // 这里加个保护
  825. return coe;
  826. },
  827. uiNodeTenderQty: function (treeNode){
  828. return this.calcNodeTenderQty(treeNode);
  829. },
  830. calcNodeTenderQty: function (treeNode){
  831. if (this.isBill(treeNode)) // 清单只有一个工程量,没有调整后工程量。
  832. return this.uiNodeQty(treeNode)
  833. else{
  834. let qCoe = 1;
  835. /* 量价、工料机类型的定额,在反向调价之调整人材机消耗量系数时,因为他们没有工料机可调,调价结果没变,影响汇总后的父结点金额。
  836. 所以要特殊处理:此种情况下仍然要调量价的消耗量,即还是要像"子目工程量调整系数"方式那样调,但系数又不能在"子目工程量调整系数"
  837. 中显示出来(明明是调工料机,你却调到树结点上,这比较搞笑啊),所以可以改变tenderQuantity达到同样的效果以瞒天过海。所以在取系数时,
  838. 无论什么系数,只要能取到就算正确。
  839. 2020-04-05 注: 以上是老黄历。新思路是量价只作为定额调整,不作为工料机调整。两种反调模式下,统一都只调子目消耗量系数。
  840. 为避免歧义,量价的工料机调整系数不允许输入。
  841. */
  842. // if (calcTools.isVP_or_GLJR(treeNode)){
  843. // if (treeNode.data.rationQuantityCoe)
  844. // qCoe = treeNode.data.rationQuantityCoe
  845. // else if (treeNode.data.quantityCoe && treeNode.data.quantityCoe.labour)
  846. // qCoe = treeNode.data.quantityCoe.labour;
  847. // }
  848. // else {
  849. if (treeNode.data.rationQuantityCoe)
  850. qCoe = treeNode.data.rationQuantityCoe;
  851. // };
  852. if (qCoe == '0' || qCoe == 0) qCoe = 1;
  853. treeNode.data.tenderQuantity = (this.uiNodeQty(treeNode) * qCoe).toDecimal(decimalObj.decimal("quantity", treeNode));
  854. return treeNode.data.tenderQuantity;
  855. }
  856. },
  857. calcGLJTenderQty: function (treeNode, glj){
  858. if (treeNode.data.quantityCoe == undefined){
  859. glj.tenderQuantity = glj.quantity;
  860. }
  861. else{
  862. let coe = 1;
  863. if (this.isTenderProjectGLJ(glj))
  864. coe = this.tenderCoe_GLJQty(treeNode, glj);
  865. glj.tenderQuantity = (glj.quantity * coe).toDecimal(decimalObj.glj.quantity);
  866. }
  867. return glj.tenderQuantity;
  868. },
  869. calcGLJTenderPrice: function (glj) {
  870. let projGLJ = calcTools.getProjectGLJ(glj);
  871. if (projGLJ == null){ // 量价定额虚拟出来的工料机,在项目工料机中查不到。
  872. glj.tenderPrice = projectObj.project.projectGLJ.getTenderMarketPrice(projGLJ);
  873. }else{
  874. let pCoe = 1;
  875. // 先从项目工料机里检查该工料机是否参与调价
  876. if (projGLJ.is_adjust_price != 1) pCoe = this.tenderCoe_GLJPrice();
  877. glj.tenderPrice = (glj.marketPrice * pCoe).toDecimal(decimalObj.glj.unitPrice);
  878. };
  879. return glj.tenderPrice;
  880. },
  881. // 界面显示的工料机价格,包括定额价、市场价等。参数 price 传入一个普通的价格数值即可。
  882. uiGLJPrice: function (price, glj){
  883. if (price){
  884. let projGLJ = glj ? calcTools.getProjectGLJ(glj) : null;
  885. let d = (projGLJ && projGLJ.ratio_data.length > 0) ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice;
  886. return parseFloat(price).toDecimal(d);
  887. }
  888. else return 0;
  889. },
  890. // 界面显示的工料机数量。参数 quantity 传入一个普通的数量数值即可。
  891. uiGLJQty: function (quantity){
  892. if (quantity)
  893. return parseFloat(quantity).toDecimal(decimalObj.glj.quantity)
  894. else return 0;
  895. },
  896. hasTargetTotalFee: function (treeNode){ // targetTotalFee 有时为字符串“0”,此种情况会执行if 条件引起逻辑错误。所以这里封闭成方法直接调用。
  897. return (treeNode.data.targetTotalFee && parseFloat(treeNode.data.targetTotalFee));
  898. },
  899. hasQuantity: function (treeNode){
  900. return (treeNode.data.quantity && parseFloat(treeNode.data.quantity));
  901. },
  902. getRationsByProjectGLJ(PGLJID, tree = projectObj.project.mainTree){
  903. let rationIDs = [];
  904. let RGs = projectObj.project.ration_glj.datas;
  905. let PGLJIDs = [];
  906. if(Array.isArray(PGLJID)){//为了提高效率,改成支持传入数组
  907. PGLJIDs = PGLJID
  908. }else {
  909. PGLJIDs = [PGLJID];
  910. }
  911. for (let rg of RGs){
  912. if (PGLJIDs.indexOf(rg.projectGLJID) !== -1){
  913. rationIDs.push(rg.rationID);
  914. }
  915. };
  916. let rationNodes = [];
  917. let nodes = tree.nodes;
  918. for (let rID of rationIDs){
  919. rationNodes.push(nodes['id_' + rID]);
  920. };
  921. // 工料机形式的定额
  922. let items = tree.items;
  923. for (let item of items){
  924. if (PGLJIDs.indexOf(item.data.projectGLJID) !== -1)
  925. rationNodes.push(item);
  926. };
  927. return rationNodes;
  928. },
  929. getNodesByProgramID(programID, tree = projectObj.project.mainTree){
  930. let discreteNodes = [];
  931. let nodes = tree.items;
  932. for (let node of nodes){
  933. if (node.data.programID == programID)
  934. discreteNodes.push(node);
  935. };
  936. return discreteNodes;
  937. },
  938. getProjectGLJ(glj){
  939. if (glj.projectGLJID){
  940. return projectObj.project.projectGLJ.getDataByID(glj.projectGLJID);
  941. }
  942. else return null;
  943. },
  944. labourDays(node, isTender){
  945. if (!node.data.gljList) return 0;
  946. let rst = 0;
  947. calcTools.uiNodeQty(node);
  948. for (let glj of node.data.gljList) {
  949. if (glj.type == gljType.LABOUR) {
  950. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  951. gljQ = gljQ.toDecimal(decimalObj.glj.quantity);
  952. rst = (rst + gljQ).toDecimal(decimalObj.process);
  953. }
  954. };
  955. return rst.toDecimal(decimalObj.glj.quantity);
  956. },
  957. getProjectFeatureProperty(propertyKey){
  958. for (let o of projectObj.project.property.projectFeature){
  959. if (o.key == propertyKey){
  960. return o.value;
  961. }
  962. };
  963. },
  964. getFeeRateByNode(node){
  965. let decimal = getDecimal("feeRate");
  966. if(node.data.feeRateID) {
  967. let r = projectObj.project.FeeRate.getFeeRateByID(node.data.feeRateID);
  968. if (r) return scMathUtil.roundForObj(r.rate, decimal);
  969. };
  970. if (node.data.feeRate || node.data.feeRate == 0)
  971. return scMathUtil.roundForObj(node.data.feeRate,decimal);
  972. return 100;
  973. },
  974. isEmptyObject(obj){
  975. let arr = Object.keys(obj);
  976. return arr.length == 0;
  977. },
  978. // 清单价格是否大于最高限价
  979. unitFeeGTMaxPrice: function (node, feeField) {
  980. if (!this.isBill(node)) {
  981. return false;
  982. }
  983. const totalFee = this.getFee(node, feeField);
  984. const maxPrice = node.data.maxPrice;
  985. // 最高限价有值才对比
  986. if (!commonUtil.isNumber(maxPrice)) {
  987. return false;
  988. }
  989. return totalFee > +maxPrice;
  990. },
  991. // 清单价格是否小于最低限价
  992. unitFeeLTMinPrice: function (node, feeField) {
  993. if (!this.isBill(node)) {
  994. return false;
  995. }
  996. const totalFee = this.getFee(node, feeField);
  997. const minPrice = node.data.minPrice;
  998. // 最低限价有值才对比
  999. if (!commonUtil.isNumber(minPrice)) {
  1000. return false;
  1001. }
  1002. return totalFee < +minPrice;
  1003. },
  1004. getTenderTypeStr: function () {
  1005. let tenderSetting = projectObj.project.property.tenderSetting;
  1006. let ct = tenderSetting && tenderSetting.calcPriceOption ? tenderSetting.calcPriceOption : "priceBase_RCJ";
  1007. if (ct == 'priceBase') ct = 'priceBase_RCJ'; // 兼容旧项目
  1008. return ct;
  1009. },
  1010. getTenderType: function () {
  1011. let rst;
  1012. let sOption = calcTools.getTenderTypeStr();
  1013. if (sOption == 'coeBase')
  1014. rst = tenderTypes.ttCalc
  1015. else if (sOption == 'priceBase_RCJ')
  1016. rst = tenderTypes.ttReverseGLJ
  1017. else if (sOption == 'priceBase_ZM')
  1018. rst = tenderTypes.ttReverseRation;
  1019. return rst;
  1020. },
  1021. // 取树结点的调价系数。
  1022. getCoe: function (node, tender) {
  1023. if (tender == tenderTypes.ttReverseGLJ)
  1024. return calcTools.isVP_or_GLJR(node) ? node.data.rationQuantityCoe : (node.data.quantityCoe ? node.data.quantityCoe.labour : 0)
  1025. else if (tender == tenderTypes.ttReverseRation)
  1026. return node.data.rationQuantityCoe;
  1027. },
  1028. getUsedTemplates: function(){
  1029. let arr = [];
  1030. let rations = projectObj.project.Ration.datas;
  1031. for (const r of rations) {
  1032. let tpl = projectObj.project.calcProgram.compiledTemplates[r.programID];
  1033. if (!arr.includes(tpl))
  1034. arr.push(tpl);
  1035. };
  1036. return arr;
  1037. }
  1038. };
  1039. let rationCalcBases = {
  1040. '定额基价人工费': function (node, isTender) {
  1041. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice, isTender);
  1042. },
  1043. '定额基价材料费': function (node, isTender) {
  1044. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice, isTender);
  1045. },
  1046. '定额基价机械费': function (node, isTender) {
  1047. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptBasePrice, isTender);
  1048. },
  1049. '定额基价机上人工费': function (node, isTender) {
  1050. return calcTools.machineDetailFee(node, node.data.gljList, [], gljType.MACHINE_LABOUR, isTender);
  1051. },
  1052. '人工费价差': function (node, isTender) {
  1053. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptDiffPrice, isTender);
  1054. },
  1055. '材料费价差': function (node, isTender) {
  1056. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptDiffPrice, isTender);
  1057. },
  1058. '机械费价差': function (node, isTender) {
  1059. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptDiffPrice, isTender);
  1060. },
  1061. '主材费价差': function (node, isTender) {
  1062. return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptDiffPrice, isTender);
  1063. },
  1064. '设备费价差': function (node, isTender) {
  1065. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptDiffPrice, isTender);
  1066. },
  1067. '主材费': function (node, isTender) {
  1068. return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptBasePrice, isTender);
  1069. },
  1070. '设备费': function (node, isTender) {
  1071. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptBasePrice, isTender);
  1072. },
  1073. '人工工日': function (node, isTender) {
  1074. return calcTools.labourDays(node, isTender);
  1075. },
  1076. '甲供定额基价人工费': function (node, isTender) {
  1077. return calcTools.partASupplyFee(node, '甲供定额基价人工费', isTender, true);
  1078. },
  1079. '甲供定额基价材料费': function (node, isTender) {
  1080. return calcTools.partASupplyFee(node, '甲供定额基价材料费', isTender, true);
  1081. },
  1082. '甲供定额基价机械费': function (node, isTender) {
  1083. return calcTools.partASupplyFee(node, '甲供定额基价机械费', isTender, true);
  1084. },
  1085. '甲供主材费': function (node, isTender) {
  1086. return calcTools.partASupplyFee(node, '甲供主材费', isTender, false);
  1087. },
  1088. '甲供设备费': function (node, isTender) {
  1089. return calcTools.partASupplyFee(node, '甲供设备费', isTender, false);
  1090. },
  1091. '甲定定额基价人工费': function (node, isTender) {
  1092. return calcTools.partASupplyFee(node, '甲定定额基价人工费', isTender, true);
  1093. },
  1094. '甲定定额基价材料费': function (node, isTender) {
  1095. return calcTools.partASupplyFee(node, '甲定定额基价材料费', isTender, true);
  1096. },
  1097. '甲定定额基价机械费': function (node, isTender) {
  1098. return calcTools.partASupplyFee(node, '甲定定额基价机械费', isTender, true);
  1099. },
  1100. '甲定主材费': function (node, isTender) {
  1101. return calcTools.partASupplyFee(node, '甲定主材费', isTender, false);
  1102. },
  1103. '甲定设备费': function (node, isTender) {
  1104. return calcTools.partASupplyFee(node, '甲定设备费', isTender, false);
  1105. },
  1106. '暂估材料费': function (node, isTender) {
  1107. return calcTools.estimateFee(node, true, isTender);
  1108. },
  1109. '分包定额基价人工费': function (node, isTender) {
  1110. if (node.data.isSubcontract)
  1111. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice, isTender)
  1112. else
  1113. return 0;
  1114. },
  1115. '分包定额基价材料费': function (node, isTender) {
  1116. if (node.data.isSubcontract)
  1117. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice, isTender)
  1118. else
  1119. return 0;
  1120. },
  1121. '分包定额基价机械费': function (node, isTender) {
  1122. if (node.data.isSubcontract)
  1123. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptBasePrice, isTender)
  1124. else
  1125. return 0;
  1126. },
  1127. '分包主材费': function (node, isTender) {
  1128. if (node.data.isSubcontract)
  1129. return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptBasePrice, isTender)
  1130. else
  1131. return 0;
  1132. },
  1133. '分包设备费': function (node, isTender) {
  1134. if (node.data.isSubcontract)
  1135. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptBasePrice, isTender)
  1136. else
  1137. return 0;
  1138. },
  1139. '分包人工工日': function (node, isTender) {
  1140. if (node.data.isSubcontract)
  1141. return calcTools.labourDays(node, isTender)
  1142. else
  1143. return 0;
  1144. }
  1145. };
  1146. let analyzer = {
  1147. error: '',
  1148. standard: function(expr){
  1149. let str = expr;
  1150. str = str.replace(/\s/g, ""); // 去空格、去中文空格
  1151. str = str.replace(/(/g, "("); // 中文括号"("换成英文括号"("
  1152. str = str.replace(/)/g, ")"); // 中文括号")"换成英文括号")"
  1153. str = str.replace(/f/g, "F"); // f换成F
  1154. str = str.replace(/l/g, "L"); // l换成L
  1155. return str;
  1156. },
  1157. getFArr: function (expr) {
  1158. let pattF = new RegExp(/F\d+/gi);
  1159. let arrF = expr.match(pattF);
  1160. return arrF ? arrF : [];
  1161. },
  1162. getAtIDArr: function (expr) { // ['@1','@2']
  1163. let patt = new RegExp(/@\d+/gi);
  1164. let arr = expr.match(patt);
  1165. return arr ? arr : [];
  1166. },
  1167. getBaseArr: function (expr) {
  1168. let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
  1169. let arrBase = expr.match(pattBase);
  1170. return arrBase ? arrBase : [];
  1171. },
  1172. getID: function (FName, template) { // F13 → 4
  1173. let idx = FName.slice(1) - 1;
  1174. let id = template.calcItems[idx] ? template.calcItems[idx].ID : null;
  1175. return id;
  1176. },
  1177. getFName: function (atID, template) { // @3 → F7
  1178. for (var i = 0; i < template.calcItems.length; i++) {
  1179. if (template.calcItems[i].ID == atID.slice(1)) {
  1180. return 'F'+ (i + 1);
  1181. }
  1182. }
  1183. return null;
  1184. },
  1185. getItem: function (FName, template){ // F3 → calcItems[2] → {Object}
  1186. let idx = FName.slice(1) - 1;
  1187. return template.calcItems[idx];
  1188. },
  1189. isCycleCalc: function (expression, ID, template) { // 这里判断expression,是ID引用: @5+@6
  1190. let atID = `@${ID}`;
  1191. // 避免部分匹配,如:@10匹配@1
  1192. let idx = expression.indexOf(atID);
  1193. if (idx >= 0){
  1194. let nextPos = idx + atID.length;
  1195. if (nextPos >= expression.length)
  1196. return true;
  1197. let char = expression.charAt(nextPos);
  1198. if (!char.isNumberStr())
  1199. return true;
  1200. };
  1201. let atIDs = analyzer.getAtIDArr(expression);
  1202. for (let atID of atIDs) {
  1203. let item = template.compiledCalcItems[atID.slice(1)];
  1204. if (analyzer.isCycleCalc(item.expression, ID, template))
  1205. return true;
  1206. }
  1207. return false;
  1208. },
  1209. isLegal: function (dispExpr, itemID, template) { // 检测包括:无效字符、基数是否中括号、基数是否定义、行引用、循环计算
  1210. function testValue(expr){
  1211. try {
  1212. expr = expr.replace(/\[[\u4E00-\u9FA5]+\]/gi, '0');
  1213. expr = expr.replace(/@\d+/gi, '0');
  1214. expr = expr.replace(/L/gi, '0');
  1215. expr = expr.replace(/%/gi, '*0.01');
  1216. if (expr.includes('00'))
  1217. return false;
  1218. eval(expr);
  1219. return true;
  1220. }
  1221. catch (err) {
  1222. return false;
  1223. }
  1224. };
  1225. let me = analyzer;
  1226. let expr = me.standard(dispExpr);
  1227. let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]FL%]/g;
  1228. if (invalidChars.test(expr)){
  1229. analyzer.error = `表达式中含有${hintBox.font('无效字符')}!`;
  1230. // hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
  1231. return false;
  1232. };
  1233. let i = expr.search(/\df/ig); // 4F3
  1234. let j = expr.search(/\d\[/ig); // 4[定额基价人工费]
  1235. if (i > -1 || j > -1){
  1236. analyzer.error = `表达式中${hintBox.font('缺少运算符')}!`;
  1237. // hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
  1238. return false;
  1239. }
  1240. let pattCn = new RegExp(/[\u4E00-\u9FA5]+/gi);
  1241. let arrCn = expr.match(pattCn);
  1242. let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
  1243. let arrBase = expr.match(pattBase);
  1244. if (arrCn && !arrBase){
  1245. analyzer.error = `定额基数必须用中括号${hintBox.font('[]')}括起来!`;
  1246. // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1247. return false;
  1248. };
  1249. if (arrCn && arrBase && (arrCn.length != arrBase.length)){
  1250. for (let cn of arrCn){
  1251. let tempBase = `[${cn}]`;
  1252. if (!arrBase.includes(tempBase)){
  1253. analyzer.error = `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`;
  1254. // hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1255. return false;
  1256. }
  1257. };
  1258. // 这里要加一个保险。因为上面的 for 循环在“主材费 + [主材费]” 情况下有Bug
  1259. analyzer.error =`定额基数必须用中括号${hintBox.font('[]')}括起来!`;
  1260. // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1261. return false;
  1262. };
  1263. if (arrBase){
  1264. for (let base of arrBase){
  1265. let baseName = base.slice(1, -1);
  1266. if (!rationCalcBases[baseName]){
  1267. analyzer.error = `定额基数${hintBox.font('[' +baseName + ']')}未定义!`;
  1268. // hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}未定义!`, 1);
  1269. return false;
  1270. }
  1271. };
  1272. };
  1273. let arrF = me.getFArr(expr);
  1274. for (let F of arrF){
  1275. let num = F.slice(1);
  1276. if (num > template.calcItems.length){
  1277. let s = hintBox.font('F'+num);
  1278. analyzer.error = `表达式中 “${hintBox.font(s)}” 行号引用错误!`;
  1279. // hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
  1280. return false;
  1281. };
  1282. };
  1283. let expression = me.getExpression(expr, template);
  1284. if (me.isCycleCalc(expression, itemID, template)){
  1285. analyzer.error = `表达式中有${hintBox.font('循环计算')}!`;
  1286. // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
  1287. return false;
  1288. };
  1289. if (!testValue(expression)){
  1290. analyzer.error = `表达式中有${hintBox.font('语法错误')}!`;
  1291. // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
  1292. return false;
  1293. };
  1294. return true; // 表达式合法
  1295. },
  1296. refIDToLines: function (expression, template) { // @2、@3 → F7、F8
  1297. let rst = expression;
  1298. let atIDArr = analyzer.getAtIDArr(rst);
  1299. let fArr = [];
  1300. for (let atID of atIDArr) {
  1301. let FN = analyzer.getFName(atID, template);
  1302. fArr.push(FN);
  1303. };
  1304. for (let i = 0; i < atIDArr.length; i++) {
  1305. let patt = new RegExp(atIDArr[i]);
  1306. let val = fArr[i];
  1307. rst = rst.replace(patt, val);
  1308. };
  1309. return rst;
  1310. },
  1311. refLineToIDs: function (dispExpr, template) { // F7、F8 → @2、@3
  1312. let rst = analyzer.standard(dispExpr);
  1313. let fArr = analyzer.getFArr(rst);
  1314. let IDArr = [];
  1315. for (let F of fArr) {
  1316. let ID = analyzer.getID(F, template);
  1317. IDArr.push(ID);
  1318. };
  1319. for (let i = 0; i < fArr.length; i++) {
  1320. let patt = new RegExp(fArr[i]);
  1321. let val = `@${IDArr[i]}`;
  1322. rst = rst.replace(patt, val);
  1323. };
  1324. return rst;
  1325. },
  1326. getDispExpr: function (expression, template) {
  1327. return analyzer.refIDToLines(expression, template);
  1328. },
  1329. getExpression: function (dispExpr, template) {
  1330. return analyzer.refLineToIDs(dispExpr, template);
  1331. },
  1332. getDispExprUser: function (dispExpr, labourCoe) { // labourCoe 是 str 类型
  1333. let rst = analyzer.standard(dispExpr);
  1334. rst = rst.replace(/L/g, labourCoe);
  1335. return rst;
  1336. },
  1337. getCompiledExpr: function (expression, labourCoe) { // labourCoe 是 str 类型
  1338. let rst = expression;
  1339. let atIDArr = analyzer.getAtIDArr(rst);
  1340. let IDArr = atIDArr.map(function (atID) {
  1341. return atID.slice(1);
  1342. });
  1343. for (var i = 0; i < atIDArr.length; i++) {
  1344. let patt = new RegExp(atIDArr[i]);
  1345. let val = `$CE.at(${IDArr[i]},false)`;
  1346. rst = rst.replace(patt, val);
  1347. };
  1348. rst = rst.replace(/%/g, "*0.01");
  1349. rst = rst.replace(/\[/g, "$CE.base('");
  1350. rst = rst.replace(/\]/g, "',false)");
  1351. rst = rst.replace(/L/g, labourCoe);
  1352. return rst;
  1353. },
  1354. getCompiledTenderExpr: function (compiledExpr) {
  1355. let rst = compiledExpr.replace(/false/g, "true");
  1356. return rst;
  1357. },
  1358. getStatement: function (expression, template) {
  1359. let rst = expression;
  1360. let atIDArr = analyzer.getAtIDArr(rst);
  1361. let IDArr = atIDArr.map(function (atID) {
  1362. return atID.slice(1);
  1363. });
  1364. for (var i = 0; i < atIDArr.length; i++) {
  1365. let patt = new RegExp(atIDArr[i]);
  1366. let val = projectObj.project.calcProgram.compiledTemplates[template.ID].compiledCalcItems[IDArr[i]].name;
  1367. rst = rst.replace(patt, val);
  1368. };
  1369. rst = rst.replace(/\[/g, "");
  1370. rst = rst.replace(/\]/g, "");
  1371. rst = rst.replace(/L/g, '人工系数');
  1372. return rst;
  1373. },
  1374. calcItemMaxID: function(template){
  1375. let MaxID = 0;
  1376. for (let item of template.calcItems){
  1377. if (item.ID > MaxID)
  1378. MaxID = item.ID;
  1379. };
  1380. return MaxID;
  1381. },
  1382. calcItemIsUsed: function(template, calcItem){
  1383. let atID = '@' + calcItem.ID;
  1384. for (var i = 0; i < template.calcItems.length; i++) {
  1385. let item = template.calcItems[i];
  1386. let atIDArr = analyzer.getAtIDArr(item.expression);
  1387. if (atIDArr.indexOf(atID) >= 0){
  1388. calcItem.tempUsed = i;
  1389. return true;
  1390. }
  1391. }
  1392. return false;
  1393. },
  1394. refreshUsedCalcItemsStatement: function(template, calcItem){
  1395. let atID = '@' + calcItem.ID;
  1396. for (var i = 0; i < template.calcItems.length; i++) {
  1397. let item = template.calcItems[i];
  1398. let atIDArr = analyzer.getAtIDArr(item.expression);
  1399. if (atIDArr.indexOf(atID) >= 0){
  1400. item.statement = analyzer.getStatement(item.expression, template);
  1401. };
  1402. }
  1403. },
  1404. calcItemLabourCoe: function(calcItem){
  1405. let lc = 0;
  1406. if (calcItem.labourCoeID)
  1407. lc = projectObj.project.calcProgram.compiledLabourCoes[calcItem.labourCoeID].coe.toString();
  1408. return lc;
  1409. },
  1410. templateRefresh: function(template){
  1411. for (let item of template){
  1412. item.dispExpr = analyzer.getDispExpr(item.expression, template);
  1413. item.dispExprUser = analyzer.getDispExprUser(item.dispExpr, me.calcItemLabourCoe(item));
  1414. };
  1415. },
  1416. templateMaxID: function(){
  1417. let ts = projectObj.project.calcProgram.templates;
  1418. let MaxID = 0;
  1419. for (let t of ts){
  1420. if (t.ID > MaxID)
  1421. MaxID = t.ID;
  1422. };
  1423. return MaxID;
  1424. },
  1425. templateNewName: function (name) {
  1426. let i = 1;
  1427. while (projectObj.project.calcProgram.compiledTemplateMaps[name + i]) {
  1428. i++;
  1429. };
  1430. return name + i;
  1431. },
  1432. templateNameIsExist: function (name) {
  1433. if (projectObj.project.calcProgram.compiledTemplateMaps[name])
  1434. return true
  1435. else return false;
  1436. },
  1437. templateIsUsed: function (ID, tree = projectObj.project.mainTree){
  1438. let nodes = tree.items;
  1439. for (let node of nodes){
  1440. if (node.data && node.data.programID && node.data.programID == ID) {
  1441. return true;
  1442. }
  1443. };
  1444. return false;
  1445. },
  1446. fieldNameIsUsed: function(template, fieldName){
  1447. let fieldNameEn = projectObj.project.calcProgram.compiledFeeTypeMaps[fieldName];
  1448. for (var i = 0; i < template.calcItems.length; i++) {
  1449. if (template.calcItems[i].fieldName == fieldNameEn){
  1450. template.fieldNameTempUsed = i;
  1451. return true;
  1452. }
  1453. }
  1454. return false;
  1455. }
  1456. };
  1457. let executeObj = {
  1458. treeNode: null,
  1459. template: null,
  1460. tempCalcItem: null,
  1461. at: function(ID, isTender) {
  1462. let item = executeObj.template.compiledCalcItems[ID];
  1463. let rst = isTender ? item.tenderUnitFee : item.unitFee;
  1464. rst = parseFloat(rst);
  1465. return rst;
  1466. },
  1467. base: function(baseName, isTender) {
  1468. let me = executeObj;
  1469. // 量价、工料机形式的定额, 要把自己的市场单价用于计算程序中的基数。
  1470. if (calcTools.isVP_or_GLJR(me.treeNode))
  1471. return calcTools.marketPriceToBase(me.treeNode, baseName, isTender)
  1472. else{
  1473. if (!rationCalcBases[baseName]){
  1474. hintBox.infoBox('系统提示', '定额基数“' + baseName + '”未定义,计算错误。 (模板 ' + me.template.ID + ',规则 ' + me.tempCalcItem.ID +')', 1);
  1475. return 0;
  1476. }
  1477. else
  1478. return rationCalcBases[baseName](me.treeNode, isTender);
  1479. }
  1480. },
  1481. HJ: function () {
  1482. let me = this;
  1483. let p = me.treeNode.data.calcBaseValue ? me.treeNode.data.calcBaseValue : 0;
  1484. let q = calcTools.uiNodeQty(me.treeNode) ? calcTools.uiNodeQty(me.treeNode) : 1;
  1485. let u = (p / q).toDecimal(decimalObj.decimal('unitPrice', me.treeNode));
  1486. return u;
  1487. }
  1488. };
  1489. class CalcProgram {
  1490. constructor(project){
  1491. let me = this;
  1492. me.project = project;
  1493. me.datas = [];
  1494. me.rationMap = null;//定额 - 工料机映射临时变量
  1495. me.pgljMap = null;
  1496. project.registerModule(ModuleNames.calc_program, me);
  1497. };
  1498. // 兼容Project框架方法
  1499. getSourceType () {
  1500. return ModuleNames.calc_program;
  1501. };
  1502. // 兼容Project框架方法
  1503. // isInit:是否初始化,进入单位工程为true,导出接口为false,不需要存储费率临时数据
  1504. loadData (datas, isInit) {
  1505. this.datas = datas;
  1506. this.compileAllTemps(isInit);
  1507. };
  1508. // 兼容Project框架方法
  1509. doAfterUpdate (err, data) {
  1510. if(!err){
  1511. $.bootstrapLoading.end();
  1512. }
  1513. };
  1514. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  1515. compileAllTemps(isInit = false){
  1516. let me = this;
  1517. me.compiledFeeRates = {};
  1518. me.compiledLabourCoes = {};
  1519. me.compiledTemplates = {};
  1520. me.compiledTemplateMaps = {};
  1521. me.compiledTemplateNames = [];
  1522. me.compiledFeeTypeMaps = {};
  1523. me.compiledFeeTypeNames = [];
  1524. me.compiledCalcBases = {};
  1525. me.feeRates = this.project.FeeRate.datas.rates;
  1526. me.labourCoes = this.project.labourCoe.datas.coes;
  1527. me.feeTypes = cpFeeTypes;
  1528. // me.calcBases = rationCalcBase;
  1529. me.templates = this.project.calcProgram.datas.templates;
  1530. // me.templates.push(defaultBillTemplate);
  1531. // 先编译公用的基础数据
  1532. me.compilePublics();
  1533. me.compileTemplateMaps();
  1534. for (let t of me.templates){
  1535. me.compileTemplate(t);
  1536. };
  1537. };
  1538. compilePublics(){
  1539. let me = this;
  1540. for (let rate of me.feeRates) {
  1541. me.compiledFeeRates[rate.ID] = rate;
  1542. }
  1543. for (let coe of me.labourCoes) {
  1544. me.compiledLabourCoes[coe.ID] = coe;
  1545. }
  1546. for (let ft of me.feeTypes) {
  1547. me.compiledFeeTypeMaps[ft.type] = ft.name;
  1548. me.compiledFeeTypeMaps[ft.name] = ft.type; // 中文预编译,可靠性有待验证
  1549. me.compiledFeeTypeNames.push(ft.name);
  1550. }
  1551. /* for (let cb of me.calcBases) {
  1552. me.compiledCalcBases[cb.dispName] = cb; // 中文预编译,可靠性有待验证
  1553. }*/
  1554. };
  1555. compileTemplateMaps(){
  1556. let me = this;
  1557. function clearObj(obj){
  1558. for (let key in obj) {
  1559. delete obj[key];
  1560. }
  1561. };
  1562. clearObj(me.compiledTemplates);
  1563. clearObj(me.compiledTemplateMaps);
  1564. me.compiledTemplateNames.splice(0, me.compiledTemplateNames.length);
  1565. for (let t of me.templates){
  1566. me.compiledTemplates[t.ID] = t;
  1567. me.compiledTemplateMaps[t.ID] = t.name;
  1568. me.compiledTemplateMaps[t.name] = t.ID;
  1569. me.compiledTemplateNames.push(t.name);
  1570. };
  1571. };
  1572. compileTemplate(template){
  1573. let me = this;
  1574. // me.compiledTemplates[template.ID] = template;
  1575. // me.compiledTemplateMaps[template.ID] = template.name;
  1576. // me.compiledTemplateMaps[template.name] = template.ID;
  1577. // me.compiledTemplateNames.push(template.name);
  1578. template.hasCompiled = false;
  1579. template.errs = [];
  1580. let private_extract_ID = function(str, idx){
  1581. let subStr = str.slice(idx);
  1582. let patt = new RegExp(/@\d+/);
  1583. let atID = subStr.match(patt);
  1584. let ID = atID ? atID[0].slice(1) : null;
  1585. return ID;
  1586. };
  1587. let private_parse_ref = function(item, itemIdx){
  1588. let idx = item.expression.indexOf('@', 0);
  1589. while (idx >= 0) {
  1590. let ID = private_extract_ID(item.expression, idx);
  1591. let len = ID ? ID.toString().length : 0;
  1592. if (len) {
  1593. let subItem = template.compiledCalcItems[ID];
  1594. if (subItem) {
  1595. if (subItem.ID !== item.ID) {
  1596. private_parse_ref(subItem, template.compiledCalcItems[ID + "_idx"]);
  1597. } else {
  1598. template.errs.push("循环引用ID: " + ID);
  1599. }
  1600. } else {
  1601. template.errs.push("找不到ID: " + ID);
  1602. console.log('找不到ID: ' + ID);
  1603. }
  1604. }
  1605. idx = item.expression.indexOf('@', idx + len + 1);
  1606. }
  1607. if (template.compiledSeq.indexOf(itemIdx) < 0) {
  1608. template.compiledSeq.push(itemIdx);
  1609. }
  1610. };
  1611. let private_compile_items = function() {
  1612. for (let idx of template.compiledSeq) {
  1613. let item = template.calcItems[idx];
  1614. let lc = analyzer.calcItemLabourCoe(item);
  1615. // 用于界面显示。disExpr是公式模板,不允许修改:人工系数占位符被修改后变成数值,第二次无法正确替换。
  1616. item.dispExprUser = analyzer.getDispExprUser(item.dispExpr, lc);
  1617. if (item.expression == 'HJ')
  1618. item.compiledExpr = '$CE.HJ()'
  1619. else
  1620. item.compiledExpr = analyzer.getCompiledExpr(item.expression, lc);
  1621. if (item.feeRateID) {
  1622. let orgFeeRate = item.feeRate;
  1623. let cfr = me.compiledFeeRates[item.feeRateID];
  1624. item.feeRate = cfr ? cfr.rate : 100;
  1625. // if (!orgFeeRate || (orgFeeRate && orgFeeRate != item.feeRate)){
  1626. // me.saveForReports.push({templatesID: template.ID, calcItem: item});
  1627. // }
  1628. };
  1629. // 字段名映射
  1630. item.displayFieldName = me.compiledFeeTypeMaps[item.fieldName];
  1631. }
  1632. };
  1633. if (template && template.calcItems && template.calcItems.length > 0) {
  1634. template.compiledSeq = [];
  1635. template.compiledCalcItems = {};
  1636. for (let i = 0; i < template.calcItems.length; i++) {
  1637. let item = template.calcItems[i];
  1638. item.dispExpr = analyzer.getDispExpr(item.expression, template);
  1639. template.compiledCalcItems[item.ID] = item;
  1640. template.compiledCalcItems[item.ID + "_idx"] = i;
  1641. }
  1642. for (let i = 0; i < template.calcItems.length; i++) {
  1643. let item = template.calcItems[i];
  1644. if (template.compiledSeq.indexOf(i) < 0) {
  1645. private_parse_ref(item, i);
  1646. }
  1647. }
  1648. if (template.errs.length == 0) {
  1649. private_compile_items();
  1650. template.hasCompiled = true;
  1651. } else {
  1652. console.log('errors: ' + template.errs.toString());
  1653. }
  1654. };
  1655. };
  1656. // 删掉多余的费用。例如:①切换取费类别 ②从其它计算方式(有很多费)切换到公式计算方式(只需要common费),多出来的费要删除。
  1657. // 如果指定了保留字段,则按用户指定的来。如果没指定保留字段,则按默认的来:总造价清单只留common, estimate两个费用类别。其它公式清单只留common。
  1658. deleteUselessFees(treeNode, fieldNameArr){
  1659. if (!(treeNode.data.fees && treeNode.data.fees.length > 0)) return;
  1660. let keeps = fieldNameArr ? fieldNameArr : [];
  1661. // 这两个默认是要保留的
  1662. if (!keeps.includes('common')) keeps.push('common');
  1663. if (!keeps.includes('estimate')) keeps.push('estimate');
  1664. for (let i = 0; i < treeNode.data.fees.length; i++) {
  1665. if (!keeps.includes(treeNode.data.fees[i].fieldName)) {
  1666. delete treeNode.data.feesIndex[treeNode.data.fees[i].fieldName];
  1667. treeNode.data.fees.splice(i, 1);
  1668. treeNode.changed = true;
  1669. }
  1670. };
  1671. };
  1672. // 不能直接删除该属性,否则无法冲掉库中已存储的值。下同。
  1673. deleteProperties (treeNode, propNamesArr){
  1674. for (let pn of propNamesArr){
  1675. if (treeNode.data[pn]){
  1676. treeNode.data[pn] = null;
  1677. treeNode.changed = true;
  1678. }
  1679. };
  1680. };
  1681. // 只计算treeNode自身。changedArr: 外部传来的一个数组,专门存储发生变动的节点。
  1682. innerCalc(treeNode, changedArr, tenderType){
  1683. if (treeNode.sourceType === ModuleNames.ration_glj) return; // 仅用作树节点显示的工料机不能参与计算。
  1684. let me = this;
  1685. //设置定额工料机映射表
  1686. me.setRationMap();
  1687. treeNode.calcType = calcTools.getCalcType(treeNode);
  1688. // 父清单汇总子清单的费用类别
  1689. if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees)
  1690. me.innerCalcBill(treeNode, 2)
  1691. // 叶子清单汇总定额的费用类别
  1692. else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees)
  1693. me.innerCalcBill(treeNode, 1)
  1694. // 叶子清单:公式计算
  1695. else if (treeNode.calcType == treeNodeCalcType.ctCalcBaseValue)
  1696. me.innerCalcBillExpr(treeNode)
  1697. // 叶子清单:手工修改单价或金额(无定额、无公式计算,什么都没有时)。
  1698. else if (treeNode.calcType == treeNodeCalcType.ctNull)
  1699. me.innerCalcBillCustom(treeNode)
  1700. // 定额:计算程序
  1701. else
  1702. me.innerCalcRation(treeNode, tenderType);
  1703. if (!calcTools.isTotalCostBill(treeNode)) // 已在上面的分支中计算过
  1704. calcTools.estimateFee(treeNode);
  1705. if (treeNode.changed && !changedArr.includes(treeNode)) changedArr.push(treeNode);
  1706. };
  1707. // 清单部分抽取出来,供分摊清单公用。commonCalcType:1 叶子清单汇总定额的费用类别; 2 父清单汇总子清单的费用类别。3: 分摊:叶子清单汇总定额的费用类别。
  1708. innerCalcBill(treeNode, commonCalcType, tender = tenderTypes.ttCalc){
  1709. let me = this;
  1710. treeNode.data.programID = null;
  1711. calcTools.initFees(treeNode);
  1712. let nodes = [];
  1713. if (commonCalcType == 1){
  1714. calcTools.getGLJList(treeNode, true);
  1715. nodes = me.project.Ration.getRationNodes(treeNode);
  1716. }
  1717. else if (commonCalcType == 2){ // 固定清单 "材料(工程设备)暂估价" 比较特殊,不进行父项汇总(需求是这么要求的)
  1718. // nodes = treeNode.children
  1719. nodes = me.project.Bills.getGatherNodes(treeNode);
  1720. }
  1721. else if (commonCalcType == 3)
  1722. nodes = treeNode.children;
  1723. function isBaseFeeType(type){
  1724. return ['labour', 'material', 'machine', 'mainMaterial', 'equipment'].indexOf(type) > -1;
  1725. };
  1726. let nQ = calcTools.uiNodeQty(treeNode);
  1727. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1728. let bq = nQ ? nQ : 1;
  1729. let btq = nTQ ? nTQ : 1;
  1730. let rst = [];
  1731. for (let ft of cpFeeTypes) {
  1732. let ftObj = {};
  1733. ftObj.fieldName = ft.type;
  1734. ftObj.name = ft.name;
  1735. let buf = 0, btf = 0, btuf = 0, bttf = 0;
  1736. if (commonCalcType == 2){
  1737. for (let node of nodes) {
  1738. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  1739. btf = (btf + parseFloatPlus(node.data.feesIndex[ft.type].totalFee)).toDecimal(decimalObj.process);
  1740. bttf = (bttf + parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee)).toDecimal(decimalObj.process);
  1741. };
  1742. };
  1743. }
  1744. else if ((commonCalcType == 1) || (commonCalcType == 3)){
  1745. if (treeNode.data.lockUnitPrice == true){ // 清单单价锁定
  1746. if (treeNode.data.feesIndex && treeNode.data.feesIndex[ft.type]) {
  1747. buf = parseFloatPlus(treeNode.data.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
  1748. btuf = parseFloatPlus(treeNode.data.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
  1749. btf = (bq * buf).toDecimal(decimalObj.bills.totalPrice);
  1750. bttf = (btq * btuf).toDecimal(decimalObj.bills.totalPrice);
  1751. }
  1752. }
  1753. else{
  1754. let sum_rtf = 0, sum_rttf = 0;
  1755. for (let node of nodes) {
  1756. let ruf = 0, rtuf = 0, rtf = 0, rttf = 0;
  1757. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  1758. ruf = parseFloatPlus(node.data.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
  1759. rtuf = parseFloatPlus(node.data.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
  1760. rtf = parseFloatPlus(node.data.feesIndex[ft.type].totalFee).toDecimal(decimalObj.bills.totalPrice);
  1761. rttf = parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee).toDecimal(decimalObj.bills.totalPrice);
  1762. };
  1763. // 取费方式为子目含量,清单行/列的XX单价应 =ROUND( ∑ROUND(定额XX单价*含量,清单单价精度),清单单价精度)
  1764. if (me.project.property.billsCalcMode === leafBillGetFeeType.rationContent) {
  1765. buf = (buf + (ruf * parseFloatPlus(node.data.contain)).toDecimal(decimalObj.bills.unitPrice)).toDecimal(decimalObj.process);
  1766. node.data.tenderContaion = (node.data.tenderQuantity / bq).toDecimal(decimalObj.process);
  1767. btuf = (btuf + (rtuf * parseFloatPlus(node.data.tenderContaion)).toDecimal(decimalObj.bills.unitPrice)).toDecimal(decimalObj.process);
  1768. };
  1769. sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
  1770. sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
  1771. };
  1772. if (me.project.property.billsCalcMode == leafBillGetFeeType.rationPriceConverse ||
  1773. me.project.property.billsCalcMode == leafBillGetFeeType.rationPrice) {
  1774. buf = (sum_rtf / bq).toDecimal(decimalObj.process);
  1775. btuf = (sum_rttf / btq).toDecimal(decimalObj.process);
  1776. };
  1777. if (isBaseFeeType(ft.type) ||
  1778. (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")){
  1779. btf = sum_rtf;
  1780. bttf = sum_rttf;
  1781. }
  1782. else{
  1783. btf = (buf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(decimalObj.process);
  1784. bttf = (btuf.toDecimal(decimalObj.bills.unitPrice) * btq).toDecimal(decimalObj.process);
  1785. };
  1786. }
  1787. };
  1788. ftObj.totalFee = btf.toDecimal(decimalObj.bills.totalPrice);
  1789. ftObj.tenderTotalFee = bttf.toDecimal(decimalObj.bills.totalPrice);
  1790. ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
  1791. ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
  1792. calcTools.checkFeeField(treeNode, ftObj);
  1793. rst.push(ftObj);
  1794. };
  1795. treeNode.data.calcTemplate = {"calcItems": rst};
  1796. };
  1797. innerCalcBillExpr(treeNode){
  1798. delete treeNode.data.gljList;
  1799. let me = this;
  1800. me.deleteProperties(treeNode, ['programID']);
  1801. me.deleteUselessFees(treeNode, ['common', 'rationCommon']);
  1802. let nQ = calcTools.uiNodeQty(treeNode);
  1803. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1804. let f = calcTools.getFeeRateByNode(treeNode);
  1805. let b = treeNode.data.calcBaseValue ? treeNode.data.calcBaseValue : 0;
  1806. let tb = treeNode.data.tenderCalcBaseValue ? treeNode.data.tenderCalcBaseValue : 0;
  1807. let q = nQ ? nQ : 1;
  1808. let tq = nTQ ? nTQ : 1;
  1809. let uf = (b * f * 0.01 / q).toDecimal(decimalObj.bills.unitPrice);
  1810. let tuf = (tb * f * 0.01 / tq).toDecimal(decimalObj.bills.unitPrice);
  1811. let tf = (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice) ? (b * f / 100) : (uf * q);
  1812. tf = tf.toDecimal(decimalObj.bills.totalPrice);
  1813. let ttf = (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice) ? (tb * f / 100) : (tuf * tq);
  1814. ttf = ttf.toDecimal(decimalObj.bills.totalPrice);
  1815. calcTools.checkFeeField(treeNode, {'fieldName': 'common', 'unitFee': uf, 'totalFee': tf, 'tenderUnitFee': tuf, 'tenderTotalFee': ttf});
  1816. // 总造价清单还要做单项工程、建设项目的四大项金额汇总
  1817. if (calcTools.isTotalCostBill(treeNode)){
  1818. // 公式叶子清单没有暂估费,但总造价清单除外。
  1819. calcTools.estimateFee(treeNode);
  1820. calcTools.initSummaryFee(treeNode);
  1821. treeNode.data.summaryFees.totalFee = tf;
  1822. treeNode.data.summaryFees.estimateFee = calcTools.getFee(treeNode, 'estimate.totalFee');
  1823. treeNode.data.summaryFees.safetyFee = calcTools.getFee(calcTools.getNodeByFlag(fixedFlag.SAFETY_CONSTRUCTION), 'common.totalFee');
  1824. treeNode.data.summaryFees.chargeFee = calcTools.getFee(calcTools.getNodeByFlag(fixedFlag.CHARGE), 'common.totalFee');
  1825. }
  1826. treeNode.data.calcTemplate = {"calcItems": []};
  1827. };
  1828. innerCalcBillCustom(treeNode){
  1829. let me = this;
  1830. delete treeNode.data.gljList;
  1831. me.deleteProperties(treeNode, ['calcBase', 'calcBaseValue', 'tenderCalcBaseValue', 'programID']);
  1832. me.deleteUselessFees(treeNode, ['rationCommon']);
  1833. // 2017-09-27 需求改了,除了第 1 、 2.2部分以外,都可以手工修改综合单价、综合合价并参与计算
  1834. // 在没有公式的情况下可以手工修改综合单价并参与计算
  1835. if(calcTools.canCalcToTalFeeByOwn(treeNode)){
  1836. if (treeNode.data.feesIndex && treeNode.data.feesIndex.common){
  1837. let ftObj = {fieldName: 'common'};
  1838. let nQ = calcTools.uiNodeQty(treeNode);
  1839. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1840. ftObj.unitFee = parseFloatPlus(treeNode.data.feesIndex.common.unitFee);
  1841. ftObj.totalFee = (ftObj.unitFee * nQ).toDecimal(decimalObj.bills.totalPrice);
  1842. ftObj.tenderUnitFee = ftObj.unitFee;
  1843. ftObj.tenderTotalFee = (ftObj.tenderUnitFee * nTQ).toDecimal(decimalObj.bills.totalPrice);
  1844. calcTools.checkFeeField(treeNode, ftObj);
  1845. }
  1846. } else{
  1847. if (treeNode.data.fees && treeNode.data.fees.length > 0){
  1848. treeNode.data.fees = null;
  1849. treeNode.data.feesIndex = null;
  1850. treeNode.changed = true;
  1851. }
  1852. };
  1853. treeNode.data.calcTemplate = {"calcItems": []};
  1854. };
  1855. // 定额部分抽取出来,供分摊定额公用。
  1856. innerCalcRation(treeNode, tenderType = tenderTypes.ttCalc){
  1857. let me = this;
  1858. let fnArr = [];
  1859. calcTools.getGLJList(treeNode, true);
  1860. let nQ = calcTools.uiNodeQty(treeNode);
  1861. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1862. if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
  1863. // 量价、工料机类型的定额要求"市场合价"
  1864. if (calcTools.isVP_or_GLJR(treeNode)){
  1865. let u = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
  1866. let t = (u * nQ).toDecimal(decimalObj.ration.totalPrice);
  1867. if (treeNode.data.marketTotalFee != t){
  1868. treeNode.data.marketTotalFee = t;
  1869. treeNode.changed = true;
  1870. } ;
  1871. };
  1872. };
  1873. let template = me.compiledTemplates[treeNode.data.programID];
  1874. treeNode.data.calcTemplate = template;
  1875. if (treeNode && template && template.hasCompiled) {//2018-08-27 空行的时候,取费专业为空,template也为空,加入template非空判断
  1876. let $CE = executeObj;
  1877. $CE.treeNode = treeNode;
  1878. $CE.template = template;
  1879. calcTools.initFees(treeNode);
  1880. for (let idx of template.compiledSeq) {
  1881. let calcItem = template.calcItems[idx];
  1882. $CE.tempCalcItem = calcItem;
  1883. let feeRate = 100; // 100%
  1884. if (calcItem.feeRate != undefined)
  1885. feeRate = parseFloat(calcItem.feeRate).toDecimal(decimalObj.feeRate);
  1886. calcItem.unitFee = (eval(calcItem.compiledExpr) * feeRate * 0.01).toDecimal(decimalObj.decimal('unitPrice', treeNode));
  1887. calcItem.totalFee = (calcItem.unitFee * nQ).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  1888. let tExpr = analyzer.getCompiledTenderExpr(calcItem.compiledExpr);
  1889. calcItem.tenderUnitFee = (eval(tExpr) * feeRate * 0.01).toDecimal(decimalObj.decimal('unitPrice', treeNode));
  1890. calcItem.tenderTotalFee = (calcItem.tenderUnitFee * nTQ).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  1891. if (calcItem.fieldName) {
  1892. fnArr.push(calcItem.fieldName);
  1893. calcTools.checkFeeField(treeNode, calcItem);
  1894. };
  1895. };
  1896. if (tenderType == tenderTypes.ttReverseRation || tenderType == tenderTypes.ttReverseGLJ)
  1897. this.reverseTenderCalc(treeNode, tenderType);
  1898. me.deleteUselessFees(treeNode, fnArr);
  1899. };
  1900. };
  1901. // 存储、刷新零散的多个结点。
  1902. saveNodes(treeNodes, callback){
  1903. if (treeNodes.length < 1) {
  1904. $.bootstrapLoading.end();
  1905. this.rationMap = null;
  1906. this.pgljMap = null;
  1907. return;
  1908. }
  1909. let me = this;
  1910. let dataArr = [];
  1911. for (let node of treeNodes){
  1912. if (node.changed){
  1913. // console.log(node.data.name);
  1914. let data = calcTools.cutNodeForSave(node);
  1915. let newData = {'type': node.sourceType, 'data': data};
  1916. dataArr.push(newData);
  1917. }
  1918. };
  1919. if (dataArr.length < 1) {
  1920. $.bootstrapLoading.end();
  1921. return;
  1922. };
  1923. if (projectObj.project.projectInfo.lastFileVer != VERSION){
  1924. let data = {
  1925. ID: projectObj.project.ID(),
  1926. lastFileVer: VERSION
  1927. };
  1928. let newData = {'type': 'project', 'data': data};
  1929. dataArr.push(newData);
  1930. };
  1931. $.bootstrapLoading.start();
  1932. let startTime = +new Date();
  1933. me.project.updateNodes(dataArr, function (data) {
  1934. me.rationMap = null;
  1935. me.pgljMap = null;
  1936. if(callback){
  1937. callback(data);
  1938. };
  1939. for (let node of treeNodes) { delete node.changed };
  1940. projectObj.mainController.refreshTreeNode(treeNodes,false,false);
  1941. projectObj.project.projectInfo.lastFileVer = VERSION;
  1942. // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
  1943. if (activeSubSheetIsCalcProgram())
  1944. calcProgramObj.refreshCalcProgram(treeNodes[0].tree.selected, 2);
  1945. $.bootstrapLoading.end();
  1946. });
  1947. };
  1948. // 计算本节点及所有会被影响到的节点,如:所有父节点(默认,可选)、公式引用节点(默认,可选)。
  1949. // 修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点。
  1950. calculate(treeNode, calcParents = true, calcFormulas = true, tender){
  1951. let me = this;
  1952. let changedNodes = [];
  1953. me.innerCalc(treeNode, changedNodes, tender);
  1954. if (treeNode.changed) {
  1955. // 计算父结点
  1956. if (calcParents){
  1957. let curNode = treeNode.parent;
  1958. while (curNode){
  1959. me.innerCalc(curNode, changedNodes, tender);
  1960. curNode = curNode.parent;
  1961. };
  1962. };
  1963. // 父结点算完,再计算所有的公式结点(必须先算完父结点,再算公式结点)
  1964. if (calcFormulas) {
  1965. me.calcFormulaNodes(changedNodes, tender);
  1966. };
  1967. };
  1968. return changedNodes;
  1969. };
  1970. // 计算并保存一个树节点。(修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点)
  1971. calcAndSave(treeNode, callback, tender){
  1972. this.calcNodesAndSave([treeNode],callback,tender);
  1973. /* let changedNodes = this.calculate(treeNode, true, true, tender); 统一调用相同的方法
  1974. this.saveNodes(changedNodes, callback);*/
  1975. };
  1976. /* 计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。参数取值如下:
  1977. calcAllType.catAll 计算所有树结点 (默认值)
  1978. calcAllType.catBills 计算所有清单 (改变项目属性中清单取费算法时会用到)
  1979. calcAllType.catRations 计算所有定额、工料机形式的定额、量价,因为它们都走自己的计算程序 (改变人工系数、费率值、工料机单价时会用到)
  1980. (calcAllType.catRations时程序中做了特殊处理,实际上是计算所有树结点!)
  1981. 调价相关参数:
  1982. tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  1983. */
  1984. calcAllNodes(calcType = calcAllType.catAll, tender, tree = projectObj.project.mainTree){
  1985. let me = this;
  1986. let changedNodes = [];
  1987. function calcNodes(nodes) {
  1988. for (let node of nodes) {
  1989. if (node.children.length > 0) {
  1990. calcNodes(node.children);
  1991. };
  1992. if (calcType == calcAllType.catAll || calcType == node.sourceType) {
  1993. node.calcType = calcTools.getCalcType(node);
  1994. if (node.calcType != treeNodeCalcType.ctCalcBaseValue)
  1995. me.innerCalc(node, changedNodes, tender);
  1996. };
  1997. }
  1998. };
  1999. // calcAllType.catRations 参数情况不会计算父结点(因为父结点是清单),所以这里进行特殊处理。
  2000. if (calcType == calcAllType.catRations)
  2001. calcType == calcAllType.catAll;
  2002. calcNodes(tree.roots);
  2003. me.calcFormulaNodes(changedNodes, tender);
  2004. debugger;
  2005. if (tender){
  2006. for(let node of tree.items){
  2007. this.clearTenderCache(node);
  2008. };
  2009. };
  2010. return changedNodes;
  2011. };
  2012. // tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  2013. calcAllNodesAndSave(calcType = calcAllType.catAll, callback, tender){
  2014. let changedNodes = this.calcAllNodes(calcType, tender);
  2015. this.saveNodes(changedNodes, callback);
  2016. };
  2017. // 计算零散的、混杂的树节点:清单、定额混合等(如:用到某一计算程序的定额和清单)。
  2018. // 计算多条零散的定额,并计算他们所属的清单、父清单、引用清单。如:批量替换工料机后受影响的定额。
  2019. // 计算多条零散的清单,并计算他们的父清单、引用清单。如:花选删除树结点(如花选清单、定额等,不区分树结点类型)。
  2020. calcNodes(nodes, tender){
  2021. let me = this, rationNodes = [], billNodes = [], leafBills = [], allChangedNodes = [];
  2022. for (let node of nodes) {
  2023. if (node.sourceType == ModuleNames.ration)
  2024. rationNodes.push(node)
  2025. else
  2026. billNodes.push(node);
  2027. };
  2028. // 多条定额同属一条叶子清单时,避免叶子清单重复计算
  2029. for (let ration of rationNodes) {
  2030. me.innerCalc(ration, allChangedNodes, tender);
  2031. let leafBill = ration.parent;
  2032. if (leafBill && leafBills.indexOf(leafBill) < 0)
  2033. leafBills.push(leafBill);
  2034. };
  2035. billNodes.merge(leafBills);
  2036. for (let bill of billNodes){
  2037. let changeBills = me.calculate(bill, true, false, tender);
  2038. allChangedNodes.merge(changeBills);
  2039. };
  2040. me.calcFormulaNodes(allChangedNodes, tender);
  2041. return allChangedNodes;
  2042. };
  2043. calcNodesAndSave(nodes, callback, tender){
  2044. let me = this;
  2045. let chgNodes = me.calcNodes(nodes, tender);
  2046. me.saveNodes(chgNodes, callback);
  2047. };
  2048. // 计算全部公式项。 (changedArr:将通过本方法后发生改变的节点存入changedArr中)
  2049. calcFormulaNodes(changedArr, tender){
  2050. let me = this;
  2051. let formulaNodes = cbTools.getFormulaNodes(true);
  2052. if (formulaNodes.length == 0) return;
  2053. for (let formulaNode of formulaNodes){
  2054. formulaNode.data.userCalcBase = formulaNode.data.calcBase; // 这句不该出现,projectObj.project.calcBase中要改进。
  2055. projectObj.project.calcBase.calculate(formulaNode, true);
  2056. if (projectObj.project.calcBase.success){
  2057. // 计算公式结点
  2058. me.innerCalc(formulaNode, changedArr, tender);
  2059. // 计算父结点
  2060. if (formulaNode.changed){
  2061. let curNode = formulaNode.parent;
  2062. while (curNode){
  2063. me.innerCalc(curNode, changedArr, tender);
  2064. curNode = curNode.parent;
  2065. };
  2066. };
  2067. };
  2068. };
  2069. };
  2070. // 计算叶子清单下的所有子结点、自身、所有父结点、公式引用结点(即跟该叶子清单相关的所有结点)。最后打包存储。
  2071. calcLeafAndSave(treeNode, tender){
  2072. let me = this;
  2073. if(!calcTools.isLeafBill(treeNode)) return;
  2074. if (treeNode.children && treeNode.children.length > 0) {
  2075. let changedNodes = [];
  2076. for (let child of treeNode.children){
  2077. me.innerCalc(child, changedNodes);
  2078. };
  2079. let curChangeds = me.calculate(treeNode, true, true, tender);
  2080. changedNodes.merge(curChangeds);
  2081. me.saveNodes(changedNodes);
  2082. };
  2083. };
  2084. // 排除指定项的综合合价计算(用于带循环计算的情况。这里的汇总只到清单级别即可:清单单价取费时,汇总到清单和汇总到定额两个值不一样)
  2085. getTotalFee(baseNodes, excludeNodes, tender){
  2086. let rst = 0;
  2087. const totalFeeType = tender ? 'common.tenderTotalFee' : 'common.totalFee';
  2088. function calcNodes(nodes) {
  2089. for (let node of nodes) {
  2090. if(!node){
  2091. continue;
  2092. }
  2093. if (!excludeNodes.includes(node)){
  2094. if (node.source && node.source.children && node.source.children.length > 0) {
  2095. calcNodes(node.children);
  2096. }
  2097. else{
  2098. if (node.sourceType == ModuleNames.bills) {
  2099. rst = (rst + calcTools.getFee(node, totalFeeType)).toDecimal(decimalObj.decimal("totalPrice", node));
  2100. };
  2101. }
  2102. }
  2103. }
  2104. };
  2105. calcNodes(baseNodes);
  2106. return rst;
  2107. };
  2108. // 税前工程造价 ,adj调价
  2109. getBeforeTaxTotalFee(excludeNodes, tender){
  2110. let baseNodes = [], me = this;
  2111. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.SUB_ENGINERRING));
  2112. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.MEASURE));
  2113. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.OTHER));
  2114. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.CHARGE));
  2115. return me.getTotalFee(baseNodes, excludeNodes, tender);
  2116. };
  2117. // 清理调价缓存数据
  2118. clearTenderCache(treeNode){
  2119. // 这些属性值为什么不定义在一个对象里?因为每次要判断对象是否存在,十分麻烦。不如直接写简单。分散书写,统一处理也很好用。
  2120. if (treeNode.data.tender_activeTotal) delete treeNode.data.tender_activeTotal;
  2121. if (treeNode.data.tender_activeTarget) delete treeNode.data.tender_activeTarget;
  2122. if (treeNode.data.tender_fullLoad) delete treeNode.data.tender_fullLoad;
  2123. if (treeNode.data.tender_distribute){
  2124. delete treeNode.data.targetTotalFee;
  2125. delete treeNode.data.targetUnitFee;
  2126. delete treeNode.data.tender_distribute;
  2127. };
  2128. };
  2129. initGljPriceTenderCoe (){
  2130. if (projectObj.project.property.tenderSetting && projectObj.project.property.tenderSetting.gljPriceTenderCoe
  2131. && (projectObj.project.property.tenderSetting.gljPriceTenderCoe != 1)){
  2132. projectObj.project.property.tenderSetting.gljPriceTenderCoe = 1; // 修改缓存值,用于计算
  2133. projectObj.project.property.needRestoreGgljPriceTenderCoe = true; // 做个标记,告诉回调函数
  2134. }
  2135. };
  2136. // 反向调价-初始化调价树、清理缓存数据等
  2137. reverseTenderInitDatas(){
  2138. for(let node of tender_obj.tenderTree.items){
  2139. if (node.data.rationQuantityCoe) node.data.rationQuantityCoe = null;
  2140. let qcObj = node.data.quantityCoe;
  2141. if (qcObj){
  2142. for (let pn in qcObj){
  2143. qcObj[pn] = null;
  2144. };
  2145. };
  2146. this.clearTenderCache(node);
  2147. };
  2148. // 反向调价时人材机单价调整系数要归1:因为既可以调量又可以调价,以哪个为基准进行反调?过于复杂,仅以通用的调量逻辑为基准即可满足需求。
  2149. this.initGljPriceTenderCoe();
  2150. };
  2151. // 反向调价简单计算:只计算当前单一结点,由目标金额计算定额量系数或工料机量系数coe,再根据此coe计算定额的调后量、调后合价。
  2152. // ⑴只计算参数指定的一个单一的结点,连父结点、引用结点都不计算。此结点只会是定额、量价、工料机款定额,不会是清单。
  2153. // ⑵执行此方法的前提:已在其它地方把总的目标金额分摊好了,此结点已获取目标金额。
  2154. reverseTenderCalc(treeNode, tender) {
  2155. if (tender == tenderTypes.ttReverseRation) {
  2156. if (treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.tenderUnitFee != treeNode.data.feesIndex.common.unitFee) {
  2157. treeNode.data.feesIndex.common.tenderUnitFee = treeNode.data.feesIndex.common.unitFee;
  2158. treeNode.changed = true;
  2159. }
  2160. };
  2161. if (!treeNode.data.targetTotalFee){ // 没有目标金额、但有输入目标单价的:根据目标单价算出目标金额。
  2162. if (treeNode.data.targetUnitFee){
  2163. treeNode.data.targetTotalFee = (treeNode.data.targetUnitFee * treeNode.data.quantity).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  2164. treeNode.changed = true;
  2165. }
  2166. else{ // 既没有目标金额也没有目标单价,此时要初始化使调价合价=原始综合合价,调价单价=原始综合单价。
  2167. if (treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.tenderUnitFee != treeNode.data.feesIndex.common.unitFee) {
  2168. treeNode.data.feesIndex.common.tenderUnitFee = treeNode.data.feesIndex.common.unitFee;
  2169. treeNode.changed = true;
  2170. };
  2171. if (treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.tenderTotalFee != treeNode.data.feesIndex.common.totalFee) {
  2172. treeNode.data.feesIndex.common.tenderTotalFee = treeNode.data.feesIndex.common.totalFee;
  2173. treeNode.changed = true;
  2174. };
  2175. return;
  2176. }
  2177. };
  2178. // 经过前面的一通折腾还是没有目标单价的话,那么就要通过目标金额算出来。
  2179. if (!treeNode.data.targetUnitFee || (parseFloat(treeNode.data.targetUnitFee) == 0)){
  2180. if (calcTools.hasQuantity(treeNode))
  2181. treeNode.data.targetUnitFee = (treeNode.data.targetTotalFee / treeNode.data.quantity).toDecimal(decimalObj.decimal('unitPrice', treeNode));
  2182. }
  2183. // 系数=调后单价/调前单价
  2184. let coe = 1;
  2185. if (treeNode.data.feesIndex.common.totalFee != 0)
  2186. coe = (treeNode.data.targetUnitFee / treeNode.data.feesIndex.common.unitFee).toDecimal(decimalObj.process);
  2187. // 量价、工料机款式的定额:它们无下挂工料机可调,直接调树结点的消耗量。
  2188. let isVP_RevGLJ =(tender == tenderTypes.ttReverseGLJ) && calcTools.isVP_or_GLJR(treeNode);
  2189. if ((tender == tenderTypes.ttReverseRation) || isVP_RevGLJ){
  2190. treeNode.data.tenderQuantity = (treeNode.data.quantity * coe).toDecimal(decimalObj.decimal("quantity", treeNode));
  2191. if (treeNode.data.rationQuantityCoe != coe){
  2192. treeNode.data.rationQuantityCoe = coe;
  2193. treeNode.changed = true;
  2194. };
  2195. if (isVP_RevGLJ){
  2196. treeNode.data.quantityCoe = {labour: 0, material: 0, machine: 0, main: 0, equipment: 0};
  2197. treeNode.changed = true;
  2198. };
  2199. let ttf = (treeNode.data.tenderQuantity * treeNode.data.feesIndex.common.tenderUnitFee).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  2200. if (treeNode.data.feesIndex.common.tenderTotalFee != ttf){
  2201. treeNode.data.feesIndex.common.tenderTotalFee = ttf;
  2202. treeNode.changed = true;
  2203. };
  2204. }else if (tender == tenderTypes.ttReverseGLJ){
  2205. let qcObj = treeNode.data.quantityCoe;
  2206. if (!qcObj || calcTools.isEmptyObject(qcObj)){
  2207. treeNode.data.quantityCoe = {labour: coe, material: coe, machine: coe, main: coe, equipment: coe};
  2208. treeNode.changed = true;
  2209. }else{
  2210. // 这种写法会漏掉属性,导致界面显示不统一。
  2211. /* for (let pn in qcObj){
  2212. if (qcObj[pn] != coe){
  2213. qcObj[pn] = coe;
  2214. treeNode.changed = true;
  2215. }
  2216. };*/
  2217. if (qcObj.labour != coe) {
  2218. qcObj.labour = coe;
  2219. treeNode.changed = true;
  2220. };
  2221. if (qcObj.material != coe) {
  2222. qcObj.material = coe;
  2223. treeNode.changed = true;
  2224. };
  2225. if (qcObj.machine != coe) {
  2226. qcObj.machine = coe;
  2227. treeNode.changed = true;
  2228. };
  2229. if (qcObj.main != coe) {
  2230. qcObj.main = coe;
  2231. treeNode.changed = true;
  2232. };
  2233. if (qcObj.equipment != coe) {
  2234. qcObj.equipment = coe;
  2235. treeNode.changed = true;
  2236. };
  2237. };
  2238. projectObj.project.calcProgram.calculate(treeNode, false, false, tenderTypes.ttCalc); // 再正向算
  2239. };
  2240. };
  2241. // 反向调价-分摊前的准备工作。包括:
  2242. // ⑴结点是否满载
  2243. // ⑵若是满载,汇总孩子的金额、目标金额给它
  2244. // ⑶标记此结点的目标金额来自孩子,未来它不往下分摊(汇上来再摊下去无用功)
  2245. prepareForDistribute(treeNode){
  2246. if (!treeNode) return;
  2247. if (treeNode.firstChild())
  2248. this.prepareForDistribute(treeNode.firstChild());
  2249. if (treeNode.children.length == 0){}
  2250. else{
  2251. let full = true;
  2252. for (let i = 0; i < treeNode.children.length; i++) {
  2253. let child = treeNode.children[i];
  2254. if (!child.data.tender_fullLoad && !calcTools.hasTargetTotalFee(child)){
  2255. full = false;
  2256. break;
  2257. };
  2258. }
  2259. if (full) {
  2260. let total = 0, target = 0;
  2261. for (let i = 0; i < treeNode.children.length; i++) {
  2262. let child = treeNode.children[i];
  2263. total = total + parseFloat(child.data.feesIndex['common'].totalFee);
  2264. target = target + parseFloat(child.data.targetTotalFee);
  2265. };
  2266. treeNode.data.tender_activeTotal = total;
  2267. treeNode.data.tender_activeTarget = target;
  2268. treeNode.data.targetTotalFee = target;
  2269. treeNode.data.tender_distribute = 2;
  2270. };
  2271. treeNode.data.tender_fullLoad = full;
  2272. };
  2273. if (treeNode.nextSibling)
  2274. this.prepareForDistribute(treeNode.nextSibling);
  2275. };
  2276. // 反向调价-分摊目标合价:从父到子往下分摊。
  2277. distributeTargetTotalFee(treeNode){
  2278. if (!treeNode) return;
  2279. if (treeNode.data.feesIndex && treeNode.data.feesIndex['common']){ // 空清单忽略
  2280. // 默认能够执行到这里时每个节点已经被初始化,缓存已删除
  2281. treeNode.data.tender_activeTotal = treeNode.data.feesIndex['common'].totalFee;
  2282. // 开始分摊:只分摊自有目标金额、从父结点分摊到的金额(不分摊子结点汇总上来的金额)
  2283. if (calcTools.hasTargetTotalFee(treeNode) && !(treeNode.data.tender_distribute && treeNode.data.tender_distribute == 2)){
  2284. treeNode.data.tender_activeTarget = treeNode.data.targetTotalFee;
  2285. // 先把会破坏金额比例关系的孩子排除:1.有目标金额的 2.满载的(孙子全满,没有分摊空间,所以实质上该孩子的金额已被锁死无法分摊)
  2286. for (let i = 0; i < treeNode.children.length; i++) {
  2287. let child = treeNode.children[i];
  2288. if (!child.data.feesIndex || !child.data.feesIndex['common']) continue; // 空白行清单、定额
  2289. child.data.tender_activeTotal = child.data.feesIndex['common'].totalFee;
  2290. if (calcTools.hasTargetTotalFee(child)){
  2291. child.data.tender_activeTarget = child.data.targetTotalFee;
  2292. console.log(treeNode.data.tender_activeTotal);
  2293. console.log(child.data.tender_activeTotal);
  2294. treeNode.data.tender_activeTotal = treeNode.data.tender_activeTotal - child.data.tender_activeTotal;
  2295. treeNode.data.tender_activeTarget = treeNode.data.tender_activeTarget - child.data.tender_activeTarget;
  2296. };
  2297. }
  2298. if (treeNode.data.tender_activeTotal != 0){
  2299. let coe = (treeNode.data.tender_activeTarget / treeNode.data.tender_activeTotal).toDecimal(decimalObj.process);
  2300. for (let i = 0; i < treeNode.children.length; i++) {
  2301. let child = treeNode.children[i];
  2302. if (!child.data.feesIndex || !child.data.feesIndex['common']) continue; // 空白行清单、定额
  2303. if (!calcTools.hasTargetTotalFee(child)){
  2304. child.data.tender_activeTarget = (coe * child.data.tender_activeTotal).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  2305. child.data.targetTotalFee = child.data.tender_activeTarget;
  2306. child.data.tender_distribute = 1; // 1表示分摊金额来自父结点。2表示分摊金额来自孩子结点。
  2307. }
  2308. }
  2309. };
  2310. };
  2311. }
  2312. if (treeNode.firstChild())
  2313. this.distributeTargetTotalFee(treeNode.firstChild());
  2314. if (treeNode.nextSibling)
  2315. this.distributeTargetTotalFee(treeNode.nextSibling);
  2316. };
  2317. // 反向调价逼近
  2318. reverseTenderApproach(callback, tender){
  2319. let me = this;
  2320. let G_DIGIT = 0.01; // 系数调整步距(0.1最终结果误差大。0.001目标金额与逼前金额差距大时无法有效逼近)
  2321. let MaxDiffValue = 0.1; // 可接受的最大差值。(如果实际差值比这个大:说明列表结点耗尽,无法达到指定精度。公路设为1,建筑设为0.1)
  2322. let times = 300; // 逼近计算的极限次数。正常情况下“单位系数金额”列表中的结点耗尽即退出,这里指定轮数是最后保险阀,防止无限死循环。
  2323. let calcModel = 1; // 计算模式:1 精度优先(差值不接近0不停,直到结点用完或极限次数用完。时间长精度高)2 速度优先(达到指定差值范围即熔断逼近。时间短差值大)
  2324. let diffProp = 0.0001; // 计算模式=2(速度优先)时有效。 通过这个金额比例值计算可接受的最大差值D。差值D = 根结点金额 * diffProp
  2325. let isTest = false; // 测试
  2326. // 按指定的比例获取可接受的差值:如目标金额的万分之一。
  2327. function getPropV(node){
  2328. let v = parseFloat((node.data.targetTotalFee * diffProp).toFixed(0)); // node.data.feesIndex.common.totalFee
  2329. return Math.max(v, MaxDiffValue);
  2330. }
  2331. // 取根结点的:调后金额跟目标金额差值,看还有多少误差需要处理。
  2332. function getRootDiff() {
  2333. let root = tender_obj.tenderTree.roots[0];
  2334. return (root.data.feesIndex.common.tenderTotalFee - root.data.targetTotalFee).toDecimal(3);
  2335. }
  2336. // 生成每单位差值的定额结点列表。
  2337. function getNodeDiffs() {
  2338. let arr = [];
  2339. for (let i = 0; i < tender_obj.tenderTree.items.length; i++) {
  2340. let node = tender_obj.tenderTree.items[i];
  2341. // 量价还是要参与,因为它贡献了金额,如果它的金额比重很大,它退出了,会导致其它结点过调。
  2342. // if (calcTools.isRationCategory(node) && (!calcTools.isVP_or_GLJR(node))){
  2343. if (calcTools.isRationCategory(node)){
  2344. let coe = calcTools.getCoe(node, tender);
  2345. if (coe!= 0) {
  2346. let diff = Math.abs(node.data.feesIndex.common.tenderTotalFee - node.data.feesIndex.common.totalFee);
  2347. node.data.tender_diffValuePerCoe = (diff * G_DIGIT / coe).toDecimal(decimalObj.process);
  2348. node.data.tender_rowNo = i + 1; // node在UI上显示的行号
  2349. arr.push(node);
  2350. }
  2351. }
  2352. };
  2353. arr.sort(function sortArr(a, b) { return a.data.tender_diffValuePerCoe - b.data.tender_diffValuePerCoe});
  2354. if (isTest){
  2355. let arr2 = [];
  2356. for (let i = 0; i < arr.length; i++) {
  2357. arr2.push({row: arr[i].data.tender_rowNo, code: arr[i].data.code + ' ' + arr[i].data.name, diff: arr[i].data.tender_diffValuePerCoe});
  2358. }
  2359. console.log(arr2);
  2360. }
  2361. return arr;
  2362. }
  2363. // 每单位差值的定额结点列表中,取离给定值最近的定额结点。
  2364. function getCloseNode(arr, value) {
  2365. let index = 0;
  2366. let d_value = Number.MAX_VALUE;
  2367. for (let i = 0; i < arr.length; i++) {
  2368. let new_d_value = Math.abs(arr[i].data.tender_diffValuePerCoe - value);
  2369. if (new_d_value <= d_value) {
  2370. if (new_d_value === d_value && arr[i].data.tender_diffValuePerCoe < arr[index].data.tender_diffValuePerCoe) {
  2371. continue;
  2372. }
  2373. index = i;
  2374. d_value = new_d_value;
  2375. }
  2376. }
  2377. return {idx: index, node: arr[index]}
  2378. }
  2379. // 逼近(单轮)。arr 参考取值列表。返回{type, node, nodeIdx}。
  2380. // type:1正常,2无结点,3结点过调。node:结点。nodeIdx:结点在列表中的索引位置。node.data.tender_rowNo 在UI上的行号。
  2381. function approach(arr){
  2382. let v = getRootDiff();
  2383. let obj = getCloseNode(arr, Math.abs(v)); // {idx, node} 极端:{0, undefind}
  2384. let closeNode = obj.node;
  2385. if (!closeNode)
  2386. return {type: 2, node: undefined, nodeIdx: -1}; // arr 被清空了
  2387. let d = (v > 0) ? -G_DIGIT : G_DIGIT;
  2388. let coe = calcTools.getCoe(closeNode, tender);
  2389. if ((coe + d) < 0)
  2390. return {type: 3, node: obj.node, nodeIdx: obj.idx}; // 再调的话,系数就变负数了,过调
  2391. if (tender == tenderTypes.ttReverseRation){
  2392. closeNode.data.tender_previousCoe = closeNode.data.rationQuantityCoe; // tender_previousCoe: 上一次的调整系数,用于撤回
  2393. closeNode.data.rationQuantityCoe = (closeNode.data.rationQuantityCoe + d).toDecimal(decimalObj.process);
  2394. }
  2395. else if (tender == tenderTypes.ttReverseGLJ){
  2396. if (calcTools.isVP_or_GLJR(closeNode)){
  2397. closeNode.data.tender_previousCoe = closeNode.data.rationQuantityCoe;
  2398. closeNode.data.rationQuantityCoe = (closeNode.data.rationQuantityCoe + d).toDecimal(decimalObj.process);
  2399. }
  2400. else {
  2401. closeNode.data.tender_previousCoe = closeNode.data.quantityCoe.labour;
  2402. closeNode.data.quantityCoe.labour = (closeNode.data.quantityCoe.labour + d).toDecimal(decimalObj.process)
  2403. closeNode.data.quantityCoe.material = (closeNode.data.quantityCoe.material + d).toDecimal(decimalObj.process)
  2404. closeNode.data.quantityCoe.machine = (closeNode.data.quantityCoe.machine + d).toDecimal(decimalObj.process)
  2405. closeNode.data.quantityCoe.main = (closeNode.data.quantityCoe.main + d).toDecimal(decimalObj.process)
  2406. closeNode.data.quantityCoe.equipment = (closeNode.data.quantityCoe.equipment + d).toDecimal(decimalObj.process)
  2407. };
  2408. }
  2409. me.calculate(closeNode, true, true, tenderTypes.ttCalc);
  2410. return {type: 1, node: obj.node, nodeIdx: obj.idx};
  2411. }
  2412. // 撤消最后一轮逼近(调过头了,回退一步)
  2413. function undoLastApproach(obj){
  2414. let closeNode = obj.node;
  2415. let coe = closeNode.data.tender_previousCoe;
  2416. if (tender == tenderTypes.ttReverseRation){
  2417. closeNode.data.rationQuantityCoe = coe
  2418. } else if (tender == tenderTypes.ttReverseGLJ){
  2419. if (calcTools.isVP_or_GLJR(closeNode)){
  2420. closeNode.data.rationQuantityCoe = coe
  2421. }
  2422. else {
  2423. closeNode.data.quantityCoe.labour = coe
  2424. closeNode.data.quantityCoe.material = coe
  2425. closeNode.data.quantityCoe.machine = coe
  2426. closeNode.data.quantityCoe.main = coe
  2427. closeNode.data.quantityCoe.equipment = coe
  2428. };
  2429. }
  2430. me.calculate(closeNode, true, true, tenderTypes.ttCalc);
  2431. if (isTest) {
  2432. let _sp = `        `; // 保留空格,打印对齐
  2433. let _node = `[行${obj.node.data.tender_rowNo} 索引${obj.nodeIdx}]`;
  2434. console.log(`${_sp} ${_node} 过调,已回退`);
  2435. }
  2436. }
  2437. let root = tender_obj.tenderTree.roots[0];
  2438. let propV = getPropV(root);
  2439. let vArr = getNodeDiffs();
  2440. let d1 = getRootDiff();
  2441. if (isTest){
  2442. let _tq = `调前${root.data.feesIndex.common.totalFee}`;
  2443. let _mb = `目标${root.data.targetTotalFee}`;
  2444. let _wbj = `调后无逼近${root.data.feesIndex.common.tenderTotalFee}`;
  2445. let _cz = `差值${d1}`;
  2446. let _js = `轮${times} 系数步距${G_DIGIT}`;
  2447. let _yx = (calcModel == 2) ? `速度优先(差比${diffProp} 差域0~${propV})` : "精度优先";
  2448. console.log(`${_tq}|${_mb}|${_wbj}|${_cz}|${_yx}|${_js}`);
  2449. }
  2450. // 多轮逼进
  2451. for (let i = 1; i <= times; i++) {
  2452. // 与目标金额差值在1以内,整数部分已相同,结果很棒。很多时候能达到完美的差值0,但不能用0判断,因为金额取小数时有问题。
  2453. if (Math.abs(d1) < MaxDiffValue) break;
  2454. // 速度优先模式下,结果到达差值范围内,即熔断逼近。
  2455. if (calcModel == 2){
  2456. if (Math.abs(d1) < propV) break;
  2457. };
  2458. let obj = approach(vArr);
  2459. if (obj.type == 2) break; // 结点耗完,列表已清空,无结点可调。
  2460. if (obj.type == 3) { // 结点过调,该结点任务已完成,不再参与调节,从列表中清除
  2461. vArr.splice(obj.nodeIdx, 1);
  2462. continue;
  2463. };
  2464. let d2 = getRootDiff();
  2465. if (isTest){
  2466. let _time = `【第 ${i} 轮】调整`;
  2467. let _node = `[行${obj.node.data.tender_rowNo} 索引${obj.nodeIdx}]`;
  2468. let _coe = `${obj.node.data.tender_previousCoe} → ${calcTools.getCoe(obj.node, tender)}`;
  2469. let _d = `差值${d1} → ${d2}`;
  2470. console.log(`${_time}${_node} ${_coe},${_d}`);
  2471. }
  2472. if (Math.abs(d2) > Math.abs(d1)){ // 逼近后差值反而变大,证明此轮调节不合适,回退一步,并将结点从列表清除
  2473. undoLastApproach(obj);
  2474. vArr.splice(obj.nodeIdx, 1);
  2475. }
  2476. else if (Math.abs(d2) == Math.abs(d1)){ // 调前调后差距相同时,会死循环,也从列表中清除
  2477. vArr.splice(obj.nodeIdx, 1);
  2478. }
  2479. else {d1 = d2}
  2480. };
  2481. // 重要注释:到这里,所有系数已处理就绪,最后直接全局正算即可。
  2482. // 到这一步,被处理的定额、及其受影响的父结点、引用结点等均已正算完成(approach方法、undoLastApproach方法),但都未保存。
  2483. // 最后全局正算目的:⑴计算除第一部以外的其它部分 ⑵保存。正算在调用外面完成。
  2484. // this.calcAllNodesAndSave(calcAllType.catAll, callback, tenderTypes.ttCalc);
  2485. };
  2486. setRationMap(){
  2487. if(this.rationMap == null){
  2488. this.rationMap = {};
  2489. for(let glj of projectObj.project.ration_glj.datas){
  2490. if(this.rationMap[glj.rationID]){
  2491. this.rationMap[glj.rationID].push(glj)
  2492. }else {
  2493. this.rationMap[glj.rationID] = [glj];
  2494. }
  2495. }
  2496. }
  2497. if(this.pgljMap == null ){
  2498. this.pgljMap = _.indexBy(projectObj.project.projectGLJ.datas.gljList, 'id');
  2499. }
  2500. };
  2501. getGljArrByRation(ration){
  2502. if (ration.type == rationType.gljRation){
  2503. let glj = JSON.parse(JSON.stringify(ration));
  2504. glj.type = glj.subType;
  2505. glj.quantity = 1;
  2506. glj.totalQuantity = parseFloatPlus(ration.quantity);
  2507. return [glj];
  2508. } else{
  2509. if(!this.rationMap) return [];
  2510. let result = this.rationMap[ration.ID];
  2511. if(!result) return [];
  2512. result = gljOprObj.combineWithProjectGlj(result,false,ration,this.pgljMap);
  2513. return result;
  2514. }
  2515. };
  2516. doTenderCalc(callback) {
  2517. $.bootstrapLoading.start();
  2518. setTimeout(()=>{
  2519. let tender = calcTools.getTenderType();
  2520. if (tender == tenderTypes.ttReverseGLJ || tender == tenderTypes.ttReverseRation) {
  2521. // 调价计算必须依赖调价树。
  2522. if (!tender_obj.tenderTree){
  2523. tender_obj.createTree();
  2524. tender_obj.createTreeNodes();
  2525. }
  2526. // 反向调价+逼近原理:
  2527. // 清理调价缓存 → 分摊目标金额(从子往父处理满载、从父往子分摊) → 全局反算 → 逼近 → 全局正算、存储
  2528. this.reverseTenderInitDatas();
  2529. this.prepareForDistribute(tender_obj.tenderTree.roots[0]);
  2530. this.distributeTargetTotalFee(tender_obj.tenderTree.roots[0]);
  2531. this.calcAllNodes(calcAllType.catAll, tender); // 先全局反算:得到每定额的coe、基础调后金额(误差大,需逼近)
  2532. this.reverseTenderApproach(callback, tender); // 逼近上述基础调后金额
  2533. }
  2534. // 全局正算(用的是主树,无需调价树)
  2535. this.calcAllNodesAndSave(calcAllType.catAll, callback, tenderTypes.ttCalc);
  2536. })
  2537. };
  2538. gatherFee(template){
  2539. // $.bootstrapLoading.start();
  2540. // setTimeout(()=>{
  2541. // 先把符合的定额筛选出来,以提高速度。
  2542. let rations = [];
  2543. let rst = 0;
  2544. for (const r of projectObj.project.Ration.datas) {
  2545. if (r.programID == template.ID) rations.push(r);
  2546. };
  2547. for (let ft of cpFeeTypes) {
  2548. let sum_uf = 0, sum_tuf = 0, sum_tf = 0, sum_ttf = 0;
  2549. for (const r of rations) {
  2550. let uf = 0, tuf = 0, tf = 0, ttf = 0;
  2551. if (r.feesIndex && r.feesIndex[ft.type]) {
  2552. uf = parseFloatPlus(r.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
  2553. tuf = parseFloatPlus(r.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
  2554. tf = parseFloatPlus(r.feesIndex[ft.type].totalFee).toDecimal(decimalObj.bills.totalPrice);
  2555. ttf = parseFloatPlus(r.feesIndex[ft.type].tenderTotalFee).toDecimal(decimalObj.bills.totalPrice);
  2556. };
  2557. sum_uf = (sum_uf + uf).toDecimal(decimalObj.process);
  2558. sum_tuf = (sum_tuf + tuf).toDecimal(decimalObj.process);
  2559. sum_tf = (sum_tf + tf).toDecimal(decimalObj.process);
  2560. sum_ttf = (sum_ttf + ttf).toDecimal(decimalObj.process);
  2561. };
  2562. for (let i = 0; i < template.calcItems.length; i++) {
  2563. let ci = template.calcItems[i];
  2564. if (ci.fieldName == ft.type){
  2565. ci.totalFee = sum_tf.toDecimal(decimalObj.bills.totalPrice);
  2566. ci.tenderTotalFee = sum_ttf.toDecimal(decimalObj.bills.totalPrice);
  2567. ci.unitFee = sum_uf.toDecimal(decimalObj.bills.unitPrice);
  2568. ci.tenderUnitFee = sum_tuf.toDecimal(decimalObj.bills.unitPrice);
  2569. if (ft.type =='common') {
  2570. template.totalFee = ci.totalFee;
  2571. rst = ci.totalFee;
  2572. }
  2573. break;
  2574. }
  2575. };
  2576. };
  2577. return rst;
  2578. // });
  2579. // $.bootstrapLoading.end();
  2580. };
  2581. //报表用取费类别汇总。调用:let obj = projectObj.project.calcProgram.getGatherFeeData();
  2582. getGatherFeeData(){
  2583. let rst = {};
  2584. let tpls = calcTools.getUsedTemplates();
  2585. let temp = 0;
  2586. for (const t of tpls) {
  2587. temp = temp + this.gatherFee(t);
  2588. }
  2589. rst.calcPrograms = tpls;
  2590. rst.totalFee = temp.toDecimal(decimalObj.bills.totalPrice);
  2591. projectObj.project.mainTree.items[0].data.totalFee = rst.totalFee;
  2592. console.log(rst);
  2593. return rst;
  2594. };
  2595. };
  2596. // export default analyzer;