calc_program.js 114 KB

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