calc_program.js 118 KB

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