calc_program.js 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335
  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. );
  62. },
  63. isInvalidNode: function (treeNode) {
  64. // 无效的、影响正常计算的行(无意义的空行、没有金额的行等)
  65. return !(
  66. treeNode.data &&
  67. treeNode.data.feesIndex &&
  68. treeNode.data.feesIndex.common &&
  69. treeNode.data.feesIndex.common.totalFee
  70. );
  71. },
  72. isCalcBaseBill: function (treeNode) {
  73. return (
  74. this.isLeafBill(treeNode) &&
  75. treeNode.children.length === 0 &&
  76. treeNode.data.calcBase
  77. );
  78. },
  79. isTotalCostBill: function (treeNode) {
  80. return (
  81. treeNode.data.flagsIndex &&
  82. treeNode.data.flagsIndex.fixed &&
  83. treeNode.data.flagsIndex.fixed.flag &&
  84. treeNode.data.flagsIndex.fixed.flag == fixedFlag.ENGINEERINGCOST
  85. );
  86. },
  87. isRationCategory: function (treeNode) {
  88. return treeNode.sourceType === ModuleNames.ration;
  89. },
  90. isRationItem: function (treeNode) {
  91. return (
  92. this.isRationCategory(treeNode) &&
  93. treeNode.data.type === rationType.ration
  94. );
  95. },
  96. isCalcManageRation: function (treeNode) {
  97. return (
  98. this.isRationCategory(treeNode) &&
  99. (treeNode.data.type === rationType.ration ||
  100. treeNode.data.type === rationType.install ||
  101. treeNode.data.type === rationType.itemIncrease)
  102. );
  103. },
  104. isVolumePrice: function (treeNode) {
  105. return (
  106. this.isRationCategory(treeNode) &&
  107. treeNode.data.type === rationType.volumePrice
  108. );
  109. },
  110. isGljRation: function (treeNode) {
  111. return (
  112. this.isRationCategory(treeNode) &&
  113. treeNode.data.type === rationType.gljRation
  114. );
  115. },
  116. isVP_or_GLJR: function (treeNode) {
  117. // 是量价或工料机类型的定额
  118. return (
  119. this.isRationCategory(treeNode) &&
  120. (treeNode.data.type == rationType.volumePrice ||
  121. treeNode.data.type == rationType.gljRation)
  122. );
  123. },
  124. isSameTypeNode: function (node1, node2) {
  125. if (
  126. node1.parent &&
  127. node2.parent &&
  128. node1.parent === node2.parent &&
  129. node1.sourceType === node1.sourceType &&
  130. node1.data &&
  131. node2.data &&
  132. node1.data.type === node2.data.type
  133. ) {
  134. return true;
  135. }
  136. return false;
  137. },
  138. isInheritFrom: function (treeNode, flagsArr) {
  139. let cur = treeNode;
  140. while (cur.parent) {
  141. cur = cur.parent;
  142. }
  143. let flag = -1;
  144. if (
  145. cur.data.flagsIndex &&
  146. cur.data.flagsIndex.fixed &&
  147. cur.data.flagsIndex.fixed.flag
  148. )
  149. flag = cur.data.flagsIndex.fixed.flag;
  150. return flagsArr.includes(flag);
  151. },
  152. isFBFX: function (treeNode) {
  153. return projectObj.project.Bills.isFBFX(treeNode);
  154. },
  155. isTechMeasure: function (treeNode) {
  156. return projectObj.project.Bills.isTechMeasure(treeNode);
  157. },
  158. canCalcToTalFeeByOwn: function (treeNode) {
  159. return !projectObj.project.Bills.cantCalcToTalFeeByOwn(treeNode);
  160. },
  161. getChildrenFormulaNodes: function (self, allFormulaNodesArr, parentNodes) {
  162. // 获取结点parentNodes下有公式的子结点
  163. let nodes = [];
  164. for (let pn of parentNodes) {
  165. for (let node of allFormulaNodesArr) {
  166. let cur = node;
  167. while (cur) {
  168. if (cur == pn && node != self) {
  169. nodes.push(node);
  170. break;
  171. }
  172. cur = cur.parent;
  173. }
  174. }
  175. }
  176. return nodes;
  177. },
  178. /* 重要说明:
  179. 此时得到的GLJList,每条glj都有tenderQuantity = glj的quantity * 定额的quantity * glj的消耗量调整系数coe。
  180. 与定额的tenderQuantity无关,与定额的子目工程量调整系数coe无关。例如:
  181. 例:定额AB0003,工程量5,下含工料机“建筑综合工”,消耗量0.202。调价:人材机单价系数4,人工系数3,子目工程量系数2。
  182. 则GLJList中的建筑综合工:quantity 1.01, tenderQuantity 3.03。marketPrice 115, tenderPrice 460。
  183. */
  184. getGLJList: function (treeNode, needOneBill) {
  185. delete treeNode.data.gljList;
  186. if (this.isRationCategory(treeNode)) {
  187. if (!calcTools.isVP_or_GLJR(treeNode)) {
  188. treeNode.data.gljList =
  189. projectObj.project.calcProgram.getGljArrByRation(treeNode.data);
  190. }
  191. } else if (this.isBill(treeNode)) {
  192. treeNode.data.gljList = projectObj.project.ration_glj.getGljArrByBill(
  193. treeNode,
  194. needOneBill
  195. );
  196. }
  197. },
  198. getLeafBills: function (treeNode) {
  199. let leafBills = [];
  200. function getBill(node) {
  201. if (!node) return;
  202. if (calcTools.isLeafBill(node)) leafBills.push(node);
  203. if (node.firstChild()) getBill(node.firstChild());
  204. if (node.nextSibling) getBill(node.nextSibling);
  205. }
  206. let fc = treeNode.firstChild();
  207. if (fc) getBill(fc);
  208. return leafBills;
  209. },
  210. forceSelect: function (treeNode, rowsCount = 1, colsCount = 2) {
  211. projectObj.mainController.tree.selected = treeNode;
  212. let idx = projectObj.project.mainTree.items.indexOf(treeNode);
  213. let sheet = projectObj.mainSpread.getActiveSheet();
  214. sheet.setSelection(idx, 0, rowsCount, colsCount);
  215. sheet.showRow(idx, GC.Spread.Sheets.VerticalPosition.center);
  216. },
  217. initFees: function (treeNode) {
  218. if (!treeNode.data.fees) {
  219. treeNode.data.fees = [];
  220. treeNode.data.feesIndex = {};
  221. treeNode.changed = true;
  222. } else if (!treeNode.data.feesIndex) {
  223. treeNode.data.feesIndex = {};
  224. for (let fee of treeNode.data.fees) {
  225. treeNode.data.feesIndex[fee.fieldName] = fee;
  226. }
  227. treeNode.changed = true;
  228. }
  229. },
  230. initFeeField: function (treeNode, fieldName) {
  231. this.initFees(treeNode);
  232. if (!treeNode.data.feesIndex[fieldName]) {
  233. let fee = {
  234. fieldName: fieldName,
  235. unitFee: 0,
  236. totalFee: 0,
  237. tenderUnitFee: 0,
  238. tenderTotalFee: 0,
  239. };
  240. treeNode.data.fees.push(fee);
  241. treeNode.data.feesIndex[fieldName] = fee;
  242. treeNode.changed = true;
  243. }
  244. },
  245. checkFeeField: function (treeNode, feeObj) {
  246. if (!feeObj) return;
  247. if (feeObj.fieldName == "") return;
  248. // 初始化前,先拦截属性未定义、又要给该属性赋0的情况
  249. if (
  250. !treeNode.data.feesIndex ||
  251. !treeNode.data.feesIndex[feeObj.fieldName]
  252. ) {
  253. if (
  254. feeObj.unitFee == 0 &&
  255. feeObj.totalFee == 0 &&
  256. feeObj.tenderUnitFee == 0 &&
  257. feeObj.tenderTotalFee == 0
  258. )
  259. return;
  260. }
  261. this.initFeeField(treeNode, feeObj.fieldName);
  262. if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee) {
  263. treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
  264. treeNode.changed = true;
  265. }
  266. if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee) {
  267. treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
  268. treeNode.changed = true;
  269. }
  270. // 不知在何种情况下,tenderUnitFee、tenderTotalFee的值会变成NaN,这里提前处理一下
  271. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee))
  272. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee = undefined;
  273. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee))
  274. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee = undefined;
  275. if (
  276. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee !=
  277. feeObj.tenderUnitFee
  278. ) {
  279. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee =
  280. feeObj.tenderUnitFee;
  281. treeNode.changed = true;
  282. }
  283. if (
  284. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee !=
  285. feeObj.tenderTotalFee
  286. ) {
  287. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee =
  288. feeObj.tenderTotalFee;
  289. treeNode.changed = true;
  290. }
  291. },
  292. setFieldValue: function (treeNode, fieldName, value) {
  293. if (fieldName.includes("feesIndex")) {
  294. let arr = fieldName.split(".");
  295. this.initFeeField(treeNode, arr[1]);
  296. treeNode.data.feesIndex[arr[1]][arr[2]] = value;
  297. if (fieldName == "feesIndex.common.unitFee") {
  298. let fee = _.find(treeNode.data.fees, { fieldName: arr[1] });
  299. if (fee) fee[arr[2]] = value;
  300. }
  301. } else {
  302. treeNode.data[fieldName] = value;
  303. }
  304. treeNode.changed = true;
  305. },
  306. initSummaryFee: function (treeNode) {
  307. if (!treeNode.data.summaryFees) {
  308. treeNode.data.summaryFees = {
  309. totalFee: 0,
  310. estimateFee: 0,
  311. safetyFee: 0,
  312. chargeFee: 0,
  313. };
  314. treeNode.changed = true;
  315. }
  316. },
  317. hasAdjustPrice: function () {
  318. // 编办是否有材料的调整价发文
  319. if (
  320. projectObj.project.projSetting.glj_col &&
  321. projectObj.project.projSetting.glj_col.showAdjustPrice == true
  322. )
  323. return true;
  324. else return false;
  325. },
  326. // 参数fieldName值: 'common.totalFee'、'equipment.unitFee'
  327. getFee: function (treeNode, fieldName) {
  328. if (!treeNode) return 0;
  329. let ns = fieldName.split(".");
  330. if (ns.length != 2) return 0;
  331. else if (
  332. treeNode.data.feesIndex &&
  333. treeNode.data.feesIndex[ns[0]] &&
  334. treeNode.data.feesIndex[ns[0]][ns[1]]
  335. )
  336. return parseFloat(treeNode.data.feesIndex[ns[0]][ns[1]]);
  337. else return 0;
  338. },
  339. rationBaseFee: function (treeNode, gljTypes, priceType, isTender) {
  340. if (!treeNode.data.gljList) return 0;
  341. let me = this,
  342. result = 0;
  343. let price = 0,
  344. temp = 0,
  345. temp2 = 0;
  346. // 机械组成物价差: 机上人工、动力燃料
  347. if (
  348. priceType == priceTypes.ptDiffPrice &&
  349. (gljTypes.includes(gljType.MACHINE_LABOUR) ||
  350. gljTypes.includes(gljType.FUEL_POWER_FEE))
  351. ) {
  352. for (let glj of treeNode.data.gljList) {
  353. if ([gljType.GENERAL_MACHINE, gljType.INSTRUMENT].includes(glj.type)) {
  354. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  355. if (!mds) mds = [];
  356. for (let md of mds) {
  357. if (gljTypes.includes(md.type)) {
  358. let gljQ = isTender
  359. ? me.uiGLJQty(glj["tenderQuantity"])
  360. : me.uiGLJQty(glj["quantity"]);
  361. let mdMP = isTender ? md["tenderPrice"] : md["marketPrice"];
  362. let mdQ = me.uiGLJQty(md.consumption);
  363. let mdAP = calcTools.hasAdjustPrice()
  364. ? md["adjustPrice"]
  365. : md["basePrice"];
  366. // if (aprice != mprice){
  367. temp = (
  368. temp + (gljQ * mdQ * mdMP).toDecimal(decimalObj.process)
  369. ).toDecimal(decimalObj.process);
  370. temp2 = (
  371. temp2 + (gljQ * mdQ * mdAP).toDecimal(decimalObj.process)
  372. ).toDecimal(decimalObj.process);
  373. // }
  374. }
  375. }
  376. }
  377. }
  378. }
  379. // 普通基数计算(包括普通价差)
  380. else {
  381. for (let glj of treeNode.data.gljList) {
  382. if (gljTypes.indexOf(glj.type) >= 0) {
  383. let qty = isTender
  384. ? me.uiGLJQty(glj["tenderQuantity"])
  385. : me.uiGLJQty(glj["quantity"]);
  386. // let mprice = isTender ? me.uiGLJPrice(glj["tenderPrice"], glj) : me.uiGLJPrice(glj["marketPrice"], glj);
  387. // let aprice = calcTools.hasAdjustPrice() ? me.uiGLJPrice(glj["adjustPrice"], glj) : me.uiGLJPrice(glj["basePrice"], glj);
  388. let mprice = isTender ? glj["tenderPrice"] : glj["marketPrice"];
  389. let aprice = calcTools.hasAdjustPrice()
  390. ? glj["adjustPrice"]
  391. : glj["basePrice"];
  392. if (priceType == priceTypes.ptDiffPrice) {
  393. // if (aprice != mprice){
  394. temp = (
  395. temp + (qty * mprice).toDecimal(decimalObj.process)
  396. ).toDecimal(decimalObj.process);
  397. temp2 = (
  398. temp2 + (qty * aprice).toDecimal(decimalObj.process)
  399. ).toDecimal(decimalObj.process);
  400. // }
  401. } else {
  402. // if (priceType == priceTypes.ptBasePrice){ price = me.uiGLJPrice(glj["basePrice"], glj);}
  403. if (priceType == priceTypes.ptBasePrice) {
  404. price = glj["basePrice"];
  405. } else if (priceType == priceTypes.ptAdjustPrice) {
  406. price = aprice;
  407. } else if (priceType == priceTypes.ptMarketPrice) {
  408. price = mprice;
  409. }
  410. /*if (projectObj.project.property.areaSetting && treeNode.data.areaIncreaseFee){
  411. let p;
  412. if ([gljType.LABOUR].includes(glj.type))
  413. p = projectObj.project.property.areaSetting.labour
  414. else if (baseMaterialTypes.includes(glj.type))
  415. p = projectObj.project.property.areaSetting.material
  416. else if ([gljType.GENERAL_MACHINE].includes(glj.type))
  417. p = projectObj.project.property.areaSetting.machine;
  418. qty = qty * (1 + p * 0.01).toDecimal(decimalObj.process);
  419. }*/
  420. temp = (qty * price).toDecimal(decimalObj.process);
  421. result = (result + temp).toDecimal(decimalObj.process);
  422. }
  423. }
  424. }
  425. }
  426. if (priceType == priceTypes.ptDiffPrice) {
  427. if (typeof isCQ2018 != "undefined") {
  428. // 如下这一句十分重要!JS计算误差导致379.08-331.695=47.38499999999999。如果直接取2位会变成47.38。所以先取6位47.385,再取2位47.39。
  429. result = (temp - temp2).toDecimal(decimalObj.process);
  430. result = result.toDecimal(decimalObj.ration.unitPrice); // 重庆2018所有都是先汇总相减后再取舍
  431. } else {
  432. if (gljTypes == baseMaterialTypes)
  433. result = (temp - temp2).toDecimal(decimalObj.ration.unitPrice);
  434. else
  435. result = (
  436. temp.toDecimal(decimalObj.ration.unitPrice) -
  437. temp2.toDecimal(decimalObj.ration.unitPrice)
  438. ).toDecimal(decimalObj.ration.unitPrice);
  439. }
  440. } else {
  441. result = result.toDecimal(decimalObj.ration.unitPrice);
  442. }
  443. return result;
  444. },
  445. // masterTypeFilter 过滤机械机型:[]全部, [1,2]特大机械 [3,4]中小机械。 detailType 如机上人工费、机械折旧费等
  446. machineDetailFee: function (
  447. treeNode,
  448. gljArr,
  449. masterTypeFilter,
  450. detailType,
  451. isTender
  452. ) {
  453. if (!gljArr) return 0;
  454. let result = 0;
  455. for (let glj of gljArr) {
  456. if (baseMachineMasterTypes.includes(glj.type)) {
  457. // 机型不符
  458. if (
  459. masterTypeFilter.length > 0 &&
  460. glj.model &&
  461. !masterTypeFilter.includes(glj.model)
  462. )
  463. continue;
  464. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  465. // 获取机械组成物(调价不深入到组成物)
  466. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  467. if (!mds) mds = [];
  468. let mdSum = 0;
  469. for (let md of mds) {
  470. if (md.type == detailType) {
  471. let q = md["consumption"] ? md["consumption"] : 0;
  472. // 下面这句从养护来,建筑暂时用不上,以后可能会用上
  473. // let p = isTender ? (md["tenderPrice"] ? md["tenderPrice"] : 0) : (md["marketPrice"] ? md["marketPrice"] : 0);
  474. let p = md["basePrice"] ? md["basePrice"] : 0;
  475. mdSum = mdSum + (q * p).toDecimal(decimalObj.glj.unitPriceHasMix);
  476. mdSum = mdSum.toDecimal(decimalObj.glj.unitPriceHasMix);
  477. }
  478. }
  479. if (typeof isCQ2018 != "undefined")
  480. result = (
  481. result + (gljQ * mdSum).toDecimal(decimalObj.process)
  482. ).toDecimal(decimalObj.process);
  483. else
  484. result = (
  485. result + (gljQ * mdSum).toDecimal(decimalObj.ration.unitPrice)
  486. ).toDecimal(decimalObj.ration.unitPrice);
  487. }
  488. }
  489. result = result.toDecimal(decimalObj.ration.unitPrice);
  490. return result;
  491. },
  492. // 叶子清单、定额、总造价清单的暂估费。(父级清单是汇总子清单的暂估费,走计算程序逻辑,不在这里)
  493. estimateFee: function (treeNode, isBase, isTender) {
  494. // isBase, isTender 这两个参数用于基数计算
  495. let me = this,
  496. sumU = 0,
  497. sumT = 0,
  498. sumTU = 0,
  499. sumTT = 0;
  500. let nodeQ = me.uiNodeQty(treeNode);
  501. let nodeTQ = me.uiNodeTenderQty(treeNode);
  502. let isGather =
  503. projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial;
  504. // 先汇总数量,再乘市场价。如果是叶子清单,进入这里的gljList中的材料,已经是同类材料跨定额汇总过的了。
  505. function eTFee() {
  506. let rst = { eT: 0, eTT: 0 };
  507. if (!treeNode.data.gljList) return rst;
  508. let GLJObjs = [];
  509. for (let glj of treeNode.data.gljList) {
  510. if (!allMaterialTypes.includes(glj.type)) continue;
  511. if (glj.isEstimate) {
  512. let q = me.uiGLJQty(glj.totalQuantity).toDecimal(decimalObj.process);
  513. GLJObjs.push({
  514. code: glj.code,
  515. name: glj.name,
  516. specs: glj.specs,
  517. unit: glj.unit,
  518. type: glj.type,
  519. quantity: q,
  520. marketPrice: glj.marketPrice,
  521. tenderQuantity: glj.tenderQuantity,
  522. tenderPrice: glj.tenderPrice,
  523. });
  524. } else {
  525. // 组成物
  526. if (!compositionTypes.includes(glj.type)) continue;
  527. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  528. if (!mds) mds = [];
  529. for (let md of mds) {
  530. if (!md.isEstimate) continue;
  531. let isExist = false;
  532. // let glj_totalQ = (nodeQ * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.glj.quantity);
  533. let glj_totalQ = me
  534. .uiGLJQty(glj.totalQuantity)
  535. .toDecimal(decimalObj.glj.quantity);
  536. let glj_tender_totalQ = (
  537. nodeTQ * me.uiGLJQty(glj.tenderQuantity)
  538. ).toDecimal(decimalObj.glj.quantity);
  539. let mdQ = (glj_totalQ * me.uiGLJQty(md.consumption)).toDecimal(
  540. decimalObj.process
  541. );
  542. let mdTQ = (
  543. glj_tender_totalQ * me.uiGLJQty(md.consumption)
  544. ).toDecimal(decimalObj.process);
  545. for (let obj of GLJObjs) {
  546. if (
  547. gljOprObj.getIndex(md, gljKeyArray) ==
  548. gljOprObj.getIndex(obj, gljKeyArray)
  549. ) {
  550. isExist = true;
  551. obj.quantity = (obj.quantity + mdQ).toDecimal(
  552. decimalObj.glj.quantity
  553. );
  554. obj.tenderQuantity = (obj.tenderQuantity + mdTQ).toDecimal(
  555. decimalObj.glj.quantity
  556. );
  557. break;
  558. }
  559. }
  560. if (!isExist)
  561. GLJObjs.push({
  562. code: md.code,
  563. name: md.name,
  564. specs: md.specs,
  565. unit: md.unit,
  566. type: md.type,
  567. quantity: mdQ,
  568. marketPrice: md.marketPrice,
  569. tenderQuantity: mdTQ,
  570. tenderPrice: md.tenderPrice,
  571. });
  572. }
  573. }
  574. }
  575. for (let obj of GLJObjs) {
  576. let t = (
  577. me.uiGLJQty(obj.quantity) * me.uiGLJPrice(obj.marketPrice, obj)
  578. ).toDecimal(decimalObj.bills.totalPrice);
  579. rst.eT = (rst.eT + t).toDecimal(decimalObj.bills.totalPrice);
  580. let tt = (
  581. me.uiGLJQty(obj.tenderQuantity) * me.uiGLJPrice(obj.tenderPrice, obj)
  582. ).toDecimal(decimalObj.bills.totalPrice);
  583. rst.eTT = (rst.eTT + tt).toDecimal(decimalObj.bills.totalPrice);
  584. }
  585. return rst;
  586. }
  587. // 汇总子结点的暂估合价
  588. function eTFeeByChildren() {
  589. let rst = { eT: 0, eTT: 0 };
  590. for (let node of treeNode.children) {
  591. if (node.data.feesIndex && node.data.feesIndex["estimate"]) {
  592. rst.eT = (
  593. rst.eT + parseFloatPlus(node.data.feesIndex["estimate"].totalFee)
  594. ).toDecimal(decimalObj.process);
  595. rst.eTT = (
  596. rst.eTT +
  597. parseFloatPlus(node.data.feesIndex["estimate"].tenderTotalFee)
  598. ).toDecimal(decimalObj.process);
  599. }
  600. }
  601. rst.eT = rst.eT.toDecimal(decimalObj.bills.totalPrice);
  602. rst.eTT = rst.eTT.toDecimal(decimalObj.bills.totalPrice);
  603. return rst;
  604. }
  605. // 先数量乘市场价,再汇总
  606. function eUFee() {
  607. if (!treeNode.data.gljList) return 0;
  608. let rst = { eU: 0, eTU: 0 };
  609. for (let glj of treeNode.data.gljList) {
  610. if (!allMaterialTypes.includes(glj.type)) continue;
  611. if (glj.isEstimate) {
  612. rst.eU =
  613. rst.eU +
  614. (
  615. me.uiGLJQty(glj.quantity) * me.uiGLJPrice(glj.marketPrice, glj)
  616. ).toDecimal(decimalObj.process);
  617. rst.eU = rst.eU.toDecimal(decimalObj.process);
  618. // 不能直接用glj.tenderPrice,这个值不可靠。当调价界面删除单价系数后,tenderPrice没有实时计算,取得的值为0
  619. rst.eTU =
  620. rst.eTU +
  621. (me.uiGLJQty(glj.tenderQuantity) * glj.tenderPrice).toDecimal(
  622. decimalObj.process
  623. );
  624. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  625. } else {
  626. // 组成物。
  627. if (!compositionTypes.includes(glj.type)) continue;
  628. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  629. if (!mds) mds = [];
  630. for (let md of mds) {
  631. if (!md.isEstimate) continue;
  632. let mdU = (
  633. me.uiGLJQty(md.consumption) * me.uiGLJPrice(md.marketPrice)
  634. ).toDecimal(decimalObj.glj.unitPrice);
  635. rst.eU =
  636. rst.eU +
  637. (mdU * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.process);
  638. rst.eU = rst.eU.toDecimal(decimalObj.process);
  639. // 数量只调到工料机级别,工料机下的组成物不调量(如机械、混凝土)。调价调的是工料机下的组成物的价。
  640. let mdTU = (me.uiGLJQty(md.consumption) * md.tenderPrice).toDecimal(
  641. decimalObj.glj.unitPrice
  642. );
  643. rst.eTU =
  644. rst.eTU +
  645. (mdTU * glj.tenderQuantity).toDecimal(decimalObj.process);
  646. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  647. }
  648. }
  649. }
  650. rst.eU = rst.eU.toDecimal(decimalObj.bills.unitPrice);
  651. rst.eTU = rst.eTU.toDecimal(decimalObj.bills.unitPrice);
  652. return rst;
  653. }
  654. // 总造价暂估费
  655. if (me.isTotalCostBill(treeNode)) {
  656. let nodes = projectObj.project.mainTree.roots;
  657. for (let node of nodes) {
  658. if (me.isTotalCostBill(node)) break;
  659. let eU = 0,
  660. eT = 0,
  661. eTU = 0,
  662. eTT = 0;
  663. if (node.data.feesIndex && node.data.feesIndex.estimate) {
  664. eU = node.data.feesIndex.estimate.unitFee;
  665. eT = node.data.feesIndex.estimate.totalFee;
  666. eTU = node.data.feesIndex.estimate.tenderUnitFee;
  667. eTT = node.data.feesIndex.estimate.tenderTotalFee;
  668. } else {
  669. (eU = 0), (eT = 0), (eTU = 0), (eTT = 0);
  670. }
  671. sumU = (sumU + parseFloatPlus(eU)).toDecimal(decimalObj.process);
  672. sumT = (sumT + parseFloatPlus(eT)).toDecimal(decimalObj.process);
  673. sumTU = (sumTU + parseFloatPlus(eTU)).toDecimal(decimalObj.process);
  674. sumTT = (sumTT + parseFloatPlus(eTT)).toDecimal(decimalObj.process);
  675. }
  676. sumU = sumU.toDecimal(decimalObj.bills.unitPrice);
  677. sumT = sumT.toDecimal(decimalObj.bills.totalPrice);
  678. sumTU = sumTU.toDecimal(decimalObj.bills.unitPrice);
  679. sumTT = sumTT.toDecimal(decimalObj.bills.totalPrice);
  680. } else if (me.isParentBill(treeNode)) {
  681. // 父清单不要汇总单价。
  682. let eTFBC = eTFeeByChildren();
  683. sumT = eTFBC.eT;
  684. sumTT = eTFBC.eTT;
  685. sumU = undefined;
  686. sumTU = undefined;
  687. } else if (me.isLeafBill(treeNode)) {
  688. if (projectObj.project.Bills.isEngineerEst(treeNode)) {
  689. if (treeNode.data.feesIndex["common"] != undefined) {
  690. sumT = treeNode.data.feesIndex["common"].totalFee;
  691. sumU = treeNode.data.feesIndex["common"].unitFee;
  692. sumTT = treeNode.data.feesIndex["common"].tenderTotalFee;
  693. sumTU = treeNode.data.feesIndex["common"].tenderUnitFee;
  694. }
  695. } else {
  696. if (isGather) {
  697. me.getGLJList(treeNode, false);
  698. let eTF = eTFee();
  699. sumT = eTF.eT;
  700. sumTT = eTF.eTT;
  701. } else {
  702. let eTFBC = eTFeeByChildren();
  703. sumT = eTFBC.eT;
  704. sumTT = eTFBC.eTT;
  705. }
  706. let q = nodeQ ? nodeQ : 1;
  707. sumU = (sumT / q).toDecimal(decimalObj.bills.totalPrice);
  708. let tq = nodeTQ ? nodeTQ : 1;
  709. sumTU = (sumTT / tq).toDecimal(decimalObj.bills.totalPrice);
  710. }
  711. } else if (me.isRationCategory(treeNode)) {
  712. me.getGLJList(treeNode, false);
  713. let eUF = eUFee();
  714. sumU = eUF.eU;
  715. sumTU = eUF.eTU;
  716. if (isBase) {
  717. if (isTender) return sumTU;
  718. else return sumU;
  719. }
  720. if (isGather) {
  721. let eTF = eTFee();
  722. sumT = eTF.eT;
  723. sumTT = eTF.eTT;
  724. } else {
  725. sumT = (nodeQ * sumU).toDecimal(decimalObj.ration.totalPrice);
  726. sumTT = (nodeTQ * sumTU).toDecimal(decimalObj.ration.totalPrice);
  727. }
  728. }
  729. me.checkFeeField(treeNode, {
  730. fieldName: "estimate",
  731. unitFee: sumU,
  732. totalFee: sumT,
  733. tenderUnitFee: sumTU,
  734. tenderTotalFee: sumTT,
  735. });
  736. },
  737. marketPriceToBase: function (treeNode, baseName, isTender) {
  738. if (!calcTools.isVP_or_GLJR(treeNode)) return;
  739. let result = 0,
  740. me = this;
  741. function isRCJZC(treeNode, baseName) {
  742. // 基数名称中是否包含人材机主设,且树结点类型要匹配一致
  743. let rst =
  744. (treeNode.data.subType === gljType.LABOUR &&
  745. baseName.includes("人工")) || // 人工费、市场人工费
  746. (baseMaterialTypes.includes(treeNode.data.subType) &&
  747. baseName.includes("材料")) ||
  748. // (treeNode.data.subType === gljType.GENERAL_MACHINE && (baseName.includes('机械') || baseName.includes('机具'))) ||
  749. (baseMachineTypes.includes(treeNode.data.subType) &&
  750. (baseName.includes("机械") || baseName.includes("机具"))) ||
  751. (treeNode.data.subType === gljType.MAIN_MATERIAL &&
  752. baseName.includes("主材")) ||
  753. (treeNode.data.subType === gljType.EQUIPMENT &&
  754. baseName.includes("设备"));
  755. return rst;
  756. }
  757. if (
  758. baseName.includes("甲供") ||
  759. baseName.includes("甲定") ||
  760. baseName.includes("分包")
  761. ) {
  762. result = 0;
  763. } else if (baseName.includes("价差")) {
  764. if (treeNode.data.type == rationType.gljRation) {
  765. if (isRCJZC(treeNode, baseName)) {
  766. let aprice = me.uiGLJPrice(treeNode.data.basePrice); // 量价虚拟的工料机不可能有发文,这里直接取定额价。
  767. let mprice = me.uiGLJPrice(treeNode.data.marketUnitFee);
  768. result = (mprice - aprice).toDecimal(decimalObj.ration.unitPrice);
  769. }
  770. }
  771. } else if (baseName.includes("机上人工")) {
  772. if (treeNode.data.subType === gljType.GENERAL_MACHINE) {
  773. let glj = {
  774. code: treeNode.data.code,
  775. name: treeNode.data.name,
  776. specs: treeNode.data.specs,
  777. unit: treeNode.data.unit,
  778. quantity: 1,
  779. type: treeNode.data.subType, // 注意:这里要取subType
  780. };
  781. result = me.machineDetailFee(
  782. treeNode,
  783. [glj],
  784. [],
  785. gljType.MACHINE_LABOUR,
  786. isTender
  787. );
  788. }
  789. } else {
  790. if (isRCJZC(treeNode, baseName)) {
  791. if (calcTools.isVolumePrice(treeNode)) {
  792. if (isTender) {
  793. let coe = this.tenderCoe_GLJPrice();
  794. if (treeNode.data.marketUnitFee)
  795. result = (
  796. parseFloat(treeNode.data.marketUnitFee) * coe
  797. ).toDecimal(decimalObj.ration.unitPrice);
  798. else result = 0;
  799. } else
  800. result = treeNode.data.marketUnitFee
  801. ? parseFloat(treeNode.data.marketUnitFee).toDecimal(
  802. decimalObj.ration.unitPrice
  803. )
  804. : 0;
  805. } else if (calcTools.isGljRation(treeNode)) {
  806. // result = treeNode.data.basePrice ? parseFloat(treeNode.data.basePrice).toDecimal(decimalObj.ration.unitPrice) : 0;
  807. // 这里要取基价或市场价,但不能直接取basePrice,受限于项目属性的三个选项。
  808. if (baseName.includes("定额"))
  809. result = gljOprObj.getBasePrice(treeNode);
  810. else
  811. result = treeNode.data.marketUnitFee
  812. ? parseFloat(treeNode.data.marketUnitFee).toDecimal(
  813. decimalObj.ration.unitPrice
  814. )
  815. : gljOprObj.getBasePrice(treeNode);
  816. }
  817. }
  818. }
  819. return result;
  820. },
  821. partASupplyFee: function (
  822. treeNode,
  823. baseName,
  824. isTender,
  825. isRationPirce = true
  826. ) {
  827. // isRationPirce 为true时表示取定额价。如:甲供定额材料费
  828. if (!treeNode.data.gljList) return 0;
  829. let projectGLJ = projectObj.project.projectGLJ;
  830. let supplyT = [];
  831. if (baseName.includes("甲供")) supplyT = [supplyType.BFJG, supplyType.WQJG];
  832. // 字段中存储的是汉字、数字混杂!
  833. else if (baseName.includes("甲定")) supplyT = [supplyType.JDYG];
  834. let gljT = [],
  835. compT = [];
  836. if (baseName.includes("人工")) gljT = [gljType.LABOUR];
  837. // 含人工的:如甲供人工、甲定人工
  838. else if (baseName.includes("材料")) {
  839. gljT = baseMaterialTypes;
  840. compT = compositionTypes;
  841. } else if (baseName.includes("机械") || baseName.includes("机具")) {
  842. gljT = baseMachineTypes;
  843. compT = [
  844. gljType.GENERAL_MACHINE,
  845. gljType.INSTRUMENT,
  846. gljType.OTHER_MACHINE_USED,
  847. ]; // 取并集,兼容重庆2018新定额
  848. } else if (baseName.includes("主材")) {
  849. gljT = [gljType.MAIN_MATERIAL];
  850. compT = [gljType.MAIN_MATERIAL];
  851. } else if (baseName.includes("设备")) {
  852. gljT = [gljType.EQUIPMENT];
  853. }
  854. // alert(JSON.stringify(projectGLJ.testGLJs()));
  855. let supplyGLJs = projectGLJ.getGLJsBySupply(supplyT, gljT);
  856. if (supplyGLJs.length == 0) return 0;
  857. let supplyGLJsIdx = {};
  858. for (let sglj of supplyGLJs) {
  859. supplyGLJsIdx[sglj.id] = sglj;
  860. }
  861. function isSupply(composition, supplies) {
  862. for (let supply of supplies) {
  863. if (
  864. supply.code == composition.code &&
  865. supply.name == composition.name &&
  866. supply.unit == composition.unit &&
  867. supply.specs == composition.specs &&
  868. supply.type == composition.type
  869. ) {
  870. composition.basePrice = supply.unit_price.base_price;
  871. composition.marketPrice = supply.unit_price.market_price;
  872. composition.supply = supply.supply;
  873. composition.supplyX = 1;
  874. if (composition.supply == supplyType.BFJG) {
  875. let Q = supply.quantity ? supply.quantity : 1;
  876. composition.supplyX = supply.supply_quantity / Q;
  877. }
  878. return true;
  879. }
  880. }
  881. return false;
  882. }
  883. let sum = 0;
  884. for (let glj of treeNode.data.gljList) {
  885. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  886. let X = 1; // 部分甲供系数(默认1,即完全甲供)
  887. let tempSGLJ = supplyGLJsIdx[glj.projectGLJID];
  888. // 当前材料是甲供材料:①普通 ②商品硂等不计组成物的母体材料
  889. if (tempSGLJ) {
  890. // 处理部分甲供
  891. if (baseName.includes("甲供") && tempSGLJ.supply == supplyType.BFJG) {
  892. let Q = isTender ? tempSGLJ.tenderQuantity : tempSGLJ.quantity;
  893. // let Q = tempSGLJ.quantity;
  894. Q = Q ? Q : 1;
  895. X = tempSGLJ.supply_quantity / Q;
  896. }
  897. let gljP = isRationPirce
  898. ? glj.basePrice
  899. : isTender
  900. ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(glj))
  901. : glj.marketPrice;
  902. sum = (sum + gljP * gljQ * X).toDecimal(decimalObj.process);
  903. } else {
  904. // 当前材料不是甲供材料
  905. // 混凝土等。组成物的母体,母体如果有组成物,则母体无法作为甲供材料,无法设置,此时要看其组成物是否是甲供材料;母体如果没有组成物,则母体有可能成为甲供材料。
  906. if (compT.includes(glj.type)) {
  907. let pGLJ = projectGLJ.getDataByID(glj.projectGLJID);
  908. let compositions = pGLJ.ratio_data; // 组成物明细
  909. if (compositions.length > 0) {
  910. for (let c of compositions) {
  911. if (isSupply(c, supplyGLJs)) {
  912. X = 1;
  913. if (baseName.includes("甲供") && c.supply == supplyType.BFJG) {
  914. X = c.supplyX;
  915. }
  916. let cP = isRationPirce
  917. ? c.basePrice
  918. : isTender
  919. ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(c))
  920. : c.marketPrice;
  921. sum = (sum + cP * c.consumption * gljQ * X).toDecimal(
  922. decimalObj.process
  923. );
  924. }
  925. }
  926. }
  927. }
  928. }
  929. }
  930. sum = sum.toDecimal(decimalObj.ration.unitPrice);
  931. return sum;
  932. },
  933. getCalcType: function (treeNode) {
  934. if (this.isRationCategory(treeNode)) {
  935. return treeNodeCalcType.ctRationCalcProgram;
  936. } else if (this.isNullBill(treeNode)) {
  937. return treeNodeCalcType.ctNull;
  938. } else if (this.isLeafBill(treeNode)) {
  939. if (treeNode.children && treeNode.children.length > 0) {
  940. // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
  941. if (
  942. projectObj.project.property.billsCalcMode ===
  943. leafBillGetFeeType.billsPrice
  944. )
  945. return treeNodeCalcType.ctBillCalcProgram;
  946. // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
  947. else return treeNodeCalcType.ctGatherRationsFees;
  948. } else {
  949. // 公式计算
  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.ctCalcBaseValue)
  2031. me.innerCalcBillExpr(treeNode);
  2032. // 叶子清单:手工修改单价或金额(无定额、无公式计算,什么都没有时)。
  2033. else if (treeNode.calcType == treeNodeCalcType.ctNull)
  2034. me.innerCalcBillCustom(treeNode);
  2035. // 定额:计算程序
  2036. else me.innerCalcRation(treeNode, tenderType);
  2037. if (!calcTools.isTotalCostBill(treeNode))
  2038. // 已在上面的分支中计算过
  2039. calcTools.estimateFee(treeNode);
  2040. if (treeNode.changed && !changedArr.includes(treeNode))
  2041. changedArr.push(treeNode);
  2042. }
  2043. // 清单部分抽取出来,供分摊清单公用。commonCalcType:1 叶子清单汇总定额的费用类别; 2 父清单汇总子清单的费用类别。3: 分摊:叶子清单汇总定额的费用类别。
  2044. innerCalcBill(treeNode, commonCalcType, tender = tenderTypes.ttCalc) {
  2045. let me = this;
  2046. treeNode.data.programID = null;
  2047. calcTools.initFees(treeNode);
  2048. let nodes = [];
  2049. if (commonCalcType == 1) {
  2050. calcTools.getGLJList(treeNode, true);
  2051. nodes = me.project.Ration.getRationNodes(treeNode);
  2052. } else if (commonCalcType == 2) {
  2053. // 固定清单 "材料(工程设备)暂估价" 比较特殊,不进行父项汇总(需求是这么要求的)
  2054. // nodes = treeNode.children
  2055. nodes = me.project.Bills.getGatherNodes(treeNode);
  2056. } else if (commonCalcType == 3) nodes = treeNode.children;
  2057. function isBaseFeeType(type) {
  2058. return (
  2059. ["labour", "material", "machine", "mainMaterial", "equipment"].indexOf(
  2060. type
  2061. ) > -1
  2062. );
  2063. }
  2064. let nQ = calcTools.uiNodeQty(treeNode);
  2065. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2066. let bq = nQ ? nQ : 1;
  2067. let btq = nTQ ? nTQ : 1;
  2068. let rst = [];
  2069. for (let ft of cpFeeTypes) {
  2070. let ftObj = {};
  2071. ftObj.fieldName = ft.type;
  2072. ftObj.name = ft.name;
  2073. let buf = 0,
  2074. btf = 0,
  2075. btuf = 0,
  2076. bttf = 0;
  2077. if (commonCalcType == 2) {
  2078. for (let node of nodes) {
  2079. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  2080. btf = (
  2081. btf + parseFloatPlus(node.data.feesIndex[ft.type].totalFee)
  2082. ).toDecimal(decimalObj.process);
  2083. bttf = (
  2084. bttf + parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee)
  2085. ).toDecimal(decimalObj.process);
  2086. }
  2087. }
  2088. } else if (commonCalcType == 1 || commonCalcType == 3) {
  2089. if (treeNode.data.lockUnitPrice == true) {
  2090. // 清单单价锁定
  2091. if (treeNode.data.feesIndex && treeNode.data.feesIndex[ft.type]) {
  2092. buf = parseFloatPlus(
  2093. treeNode.data.feesIndex[ft.type].unitFee
  2094. ).toDecimal(decimalObj.bills.unitPrice);
  2095. btuf = parseFloatPlus(
  2096. treeNode.data.feesIndex[ft.type].tenderUnitFee
  2097. ).toDecimal(decimalObj.bills.unitPrice);
  2098. btf = (bq * buf).toDecimal(decimalObj.bills.totalPrice);
  2099. bttf = (btq * btuf).toDecimal(decimalObj.bills.totalPrice);
  2100. }
  2101. } else {
  2102. let sum_rtf = 0,
  2103. sum_rttf = 0;
  2104. for (let node of nodes) {
  2105. let ruf = 0,
  2106. rtuf = 0,
  2107. rtf = 0,
  2108. rttf = 0;
  2109. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  2110. ruf = parseFloatPlus(
  2111. node.data.feesIndex[ft.type].unitFee
  2112. ).toDecimal(decimalObj.bills.unitPrice);
  2113. rtuf = parseFloatPlus(
  2114. node.data.feesIndex[ft.type].tenderUnitFee
  2115. ).toDecimal(decimalObj.bills.unitPrice);
  2116. rtf = parseFloatPlus(
  2117. node.data.feesIndex[ft.type].totalFee
  2118. ).toDecimal(decimalObj.bills.totalPrice);
  2119. rttf = parseFloatPlus(
  2120. node.data.feesIndex[ft.type].tenderTotalFee
  2121. ).toDecimal(decimalObj.bills.totalPrice);
  2122. }
  2123. // 取费方式为子目含量,清单行/列的XX单价应 =ROUND( ∑ROUND(定额XX单价*含量,清单单价精度),清单单价精度)
  2124. if (
  2125. me.project.property.billsCalcMode ===
  2126. leafBillGetFeeType.rationContent
  2127. ) {
  2128. buf = (
  2129. buf +
  2130. (ruf * parseFloatPlus(node.data.contain)).toDecimal(
  2131. decimalObj.bills.unitPrice
  2132. )
  2133. ).toDecimal(decimalObj.process);
  2134. if (node.data.tenderQuantity)
  2135. node.data.tenderContaion = (
  2136. node.data.tenderQuantity / bq
  2137. ).toDecimal(decimalObj.process);
  2138. else node.data.tenderContaion = node.data.contain;
  2139. btuf = (
  2140. btuf +
  2141. (rtuf * parseFloatPlus(node.data.tenderContaion)).toDecimal(
  2142. decimalObj.bills.unitPrice
  2143. )
  2144. ).toDecimal(decimalObj.process);
  2145. }
  2146. sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
  2147. sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
  2148. }
  2149. if (
  2150. me.project.property.billsCalcMode ==
  2151. leafBillGetFeeType.rationPriceConverse ||
  2152. me.project.property.billsCalcMode == leafBillGetFeeType.rationPrice
  2153. ) {
  2154. buf = (sum_rtf / bq).toDecimal(decimalObj.process);
  2155. btuf = (sum_rttf / btq).toDecimal(decimalObj.process);
  2156. }
  2157. if (
  2158. isBaseFeeType(ft.type) ||
  2159. (me.project.property.billsCalcMode ===
  2160. leafBillGetFeeType.rationPrice &&
  2161. ft.type == "common")
  2162. ) {
  2163. btf = sum_rtf;
  2164. bttf = sum_rttf;
  2165. } else {
  2166. btf = (buf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(
  2167. decimalObj.process
  2168. );
  2169. bttf = (btuf.toDecimal(decimalObj.bills.unitPrice) * btq).toDecimal(
  2170. decimalObj.process
  2171. );
  2172. }
  2173. }
  2174. }
  2175. ftObj.totalFee = btf.toDecimal(decimalObj.bills.totalPrice);
  2176. ftObj.tenderTotalFee = bttf.toDecimal(decimalObj.bills.totalPrice);
  2177. ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
  2178. ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
  2179. calcTools.checkFeeField(treeNode, ftObj);
  2180. rst.push(ftObj);
  2181. }
  2182. treeNode.data.calcTemplate = { calcItems: rst };
  2183. }
  2184. innerCalcBillExpr(treeNode) {
  2185. delete treeNode.data.gljList;
  2186. let me = this;
  2187. me.deleteProperties(treeNode, ["programID"]);
  2188. me.deleteUselessFees(treeNode, ["common", "rationCommon"]);
  2189. let nQ = calcTools.uiNodeQty(treeNode);
  2190. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2191. let f = calcTools.getFeeRateByNode(treeNode);
  2192. let b = treeNode.data.calcBaseValue ? treeNode.data.calcBaseValue : 0;
  2193. let tb = treeNode.data.tenderCalcBaseValue
  2194. ? treeNode.data.tenderCalcBaseValue
  2195. : 0;
  2196. let q = nQ ? nQ : 1;
  2197. let tq = nTQ ? nTQ : 1;
  2198. let uf = ((b * f * 0.01) / q).toDecimal(decimalObj.bills.unitPrice);
  2199. let tuf = ((tb * f * 0.01) / tq).toDecimal(decimalObj.bills.unitPrice);
  2200. let tf =
  2201. me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice
  2202. ? (b * f) / 100
  2203. : uf * q;
  2204. tf = tf.toDecimal(decimalObj.bills.totalPrice);
  2205. let ttf =
  2206. me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice
  2207. ? (tb * f) / 100
  2208. : tuf * tq;
  2209. ttf = ttf.toDecimal(decimalObj.bills.totalPrice);
  2210. calcTools.checkFeeField(treeNode, {
  2211. fieldName: "common",
  2212. unitFee: uf,
  2213. totalFee: tf,
  2214. tenderUnitFee: tuf,
  2215. tenderTotalFee: ttf,
  2216. });
  2217. // 总造价清单还要做单项工程、建设项目的四大项金额汇总
  2218. if (calcTools.isTotalCostBill(treeNode)) {
  2219. // 公式叶子清单没有暂估费,但总造价清单除外。
  2220. calcTools.estimateFee(treeNode);
  2221. calcTools.initSummaryFee(treeNode);
  2222. treeNode.data.summaryFees.totalFee = tf;
  2223. treeNode.data.summaryFees.estimateFee = calcTools.getFee(
  2224. treeNode,
  2225. "estimate.totalFee"
  2226. );
  2227. treeNode.data.summaryFees.safetyFee = calcTools.getFee(
  2228. calcTools.getNodeByFlag(fixedFlag.SAFETY_CONSTRUCTION),
  2229. "common.totalFee"
  2230. );
  2231. treeNode.data.summaryFees.chargeFee = calcTools.getFee(
  2232. calcTools.getNodeByFlag(fixedFlag.CHARGE),
  2233. "common.totalFee"
  2234. );
  2235. }
  2236. treeNode.data.calcTemplate = { calcItems: [] };
  2237. }
  2238. innerCalcBillCustom(treeNode) {
  2239. let me = this;
  2240. delete treeNode.data.gljList;
  2241. me.deleteProperties(treeNode, [
  2242. "calcBase",
  2243. "calcBaseValue",
  2244. "tenderCalcBaseValue",
  2245. "programID",
  2246. ]);
  2247. me.deleteUselessFees(treeNode, ["rationCommon"]);
  2248. // 2017-09-27 需求改了,除了第 1 、 2.2部分以外,都可以手工修改综合单价、综合合价并参与计算
  2249. // 在没有公式的情况下可以手工修改综合单价并参与计算
  2250. if (calcTools.canCalcToTalFeeByOwn(treeNode)) {
  2251. if (treeNode.data.feesIndex && treeNode.data.feesIndex.common) {
  2252. let ftObj = { fieldName: "common" };
  2253. let nQ = calcTools.uiNodeQty(treeNode);
  2254. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2255. ftObj.unitFee = parseFloatPlus(treeNode.data.feesIndex.common.unitFee);
  2256. ftObj.totalFee = (ftObj.unitFee * nQ).toDecimal(
  2257. decimalObj.bills.totalPrice
  2258. );
  2259. ftObj.tenderUnitFee = ftObj.unitFee;
  2260. ftObj.tenderTotalFee = (ftObj.tenderUnitFee * nTQ).toDecimal(
  2261. decimalObj.bills.totalPrice
  2262. );
  2263. calcTools.checkFeeField(treeNode, ftObj);
  2264. }
  2265. } else {
  2266. if (treeNode.data.fees && treeNode.data.fees.length > 0) {
  2267. treeNode.data.fees = null;
  2268. treeNode.data.feesIndex = null;
  2269. treeNode.changed = true;
  2270. }
  2271. }
  2272. treeNode.data.calcTemplate = { calcItems: [] };
  2273. }
  2274. // 定额部分抽取出来,供分摊定额公用。
  2275. innerCalcRation(treeNode, tenderType = tenderTypes.ttCalc) {
  2276. let me = this;
  2277. let fnArr = [];
  2278. // 如果是反算工料机,这里要先保证coe有值。
  2279. if (tenderType == tenderTypes.ttReverseGLJ) {
  2280. let coe = (
  2281. treeNode.data.tender_activeTarget / treeNode.data.tender_activeTotal
  2282. ).toDecimal(decimalObj.process);
  2283. treeNode.data.quantityCoe = {
  2284. labour: coe,
  2285. material: coe,
  2286. machine: coe,
  2287. main: coe,
  2288. equipment: coe,
  2289. };
  2290. }
  2291. calcTools.getGLJList(treeNode, true);
  2292. let nQ = calcTools.uiNodeQty(treeNode);
  2293. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2294. if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
  2295. // 量价、工料机类型的定额要求"市场合价"
  2296. if (calcTools.isVP_or_GLJR(treeNode)) {
  2297. let u = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
  2298. let t = (u * nQ).toDecimal(decimalObj.ration.totalPrice);
  2299. if (treeNode.data.marketTotalFee != t) {
  2300. treeNode.data.marketTotalFee = t;
  2301. treeNode.changed = true;
  2302. }
  2303. }
  2304. }
  2305. let template = me.compiledTemplates[treeNode.data.programID];
  2306. treeNode.data.calcTemplate = template;
  2307. if (treeNode && template && template.hasCompiled) {
  2308. //2018-08-27 空行的时候,取费专业为空,template也为空,加入template非空判断
  2309. let $CE = executeObj;
  2310. $CE.treeNode = treeNode;
  2311. $CE.template = template;
  2312. calcTools.initFees(treeNode);
  2313. for (let idx of template.compiledSeq) {
  2314. let calcItem = template.calcItems[idx];
  2315. $CE.tempCalcItem = calcItem;
  2316. let feeRate = 100; // 100%
  2317. if (calcItem.feeRate != undefined)
  2318. feeRate = parseFloat(calcItem.feeRate).toDecimal(decimalObj.feeRate);
  2319. calcItem.unitFee = (
  2320. eval(calcItem.compiledExpr) *
  2321. feeRate *
  2322. 0.01
  2323. ).toDecimal(decimalObj.decimal("unitPrice", treeNode));
  2324. calcItem.totalFee = (calcItem.unitFee * nQ).toDecimal(
  2325. decimalObj.decimal("totalPrice", treeNode)
  2326. );
  2327. let tExpr = analyzer.getCompiledTenderExpr(calcItem.compiledExpr);
  2328. calcItem.tenderUnitFee = (eval(tExpr) * feeRate * 0.01).toDecimal(
  2329. decimalObj.decimal("unitPrice", treeNode)
  2330. );
  2331. calcItem.tenderTotalFee = (calcItem.tenderUnitFee * nTQ).toDecimal(
  2332. decimalObj.decimal("totalPrice", treeNode)
  2333. );
  2334. if (calcItem.fieldName) {
  2335. fnArr.push(calcItem.fieldName);
  2336. calcTools.checkFeeField(treeNode, calcItem);
  2337. }
  2338. }
  2339. if (
  2340. tenderType == tenderTypes.ttReverseRation ||
  2341. tenderType == tenderTypes.ttReverseGLJ
  2342. )
  2343. this.reverseTenderCalc(treeNode, tenderType);
  2344. me.deleteUselessFees(treeNode, fnArr);
  2345. }
  2346. }
  2347. // 存储、刷新零散的多个结点。
  2348. saveNodes(treeNodes, callback) {
  2349. if (treeNodes.length < 1) {
  2350. $.bootstrapLoading.end();
  2351. this.rationMap = null;
  2352. this.pgljMap = null;
  2353. return;
  2354. }
  2355. let me = this;
  2356. let dataArr = [];
  2357. for (let node of treeNodes) {
  2358. if (node.changed) {
  2359. // console.log(node.data.name);
  2360. let data = calcTools.cutNodeForSave(node);
  2361. let newData = { type: node.sourceType, data: data };
  2362. dataArr.push(newData);
  2363. }
  2364. }
  2365. if (dataArr.length < 1) {
  2366. $.bootstrapLoading.end();
  2367. return;
  2368. }
  2369. if (projectObj.project.projectInfo.lastFileVer != VERSION) {
  2370. let data = {
  2371. ID: projectObj.project.ID(),
  2372. lastFileVer: VERSION,
  2373. };
  2374. let newData = { type: "project", data: data };
  2375. dataArr.push(newData);
  2376. }
  2377. $.bootstrapLoading.start();
  2378. let startTime = +new Date();
  2379. me.project.updateNodes(dataArr, function (data) {
  2380. me.rationMap = null;
  2381. me.pgljMap = null;
  2382. if (callback) {
  2383. callback(data);
  2384. }
  2385. for (let node of treeNodes) {
  2386. delete node.changed;
  2387. }
  2388. projectObj.mainController.refreshTreeNode(treeNodes, false, false);
  2389. projectObj.project.projectInfo.lastFileVer = VERSION;
  2390. // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
  2391. if (activeSubSheetIsCalcProgram())
  2392. calcProgramObj.refreshCalcProgram(
  2393. projectObj.project.mainTree.selected,
  2394. 2
  2395. );
  2396. $.bootstrapLoading.end();
  2397. });
  2398. }
  2399. // 计算本节点及所有会被影响到的节点,如:所有父节点(默认,可选)、公式引用节点(默认,可选)。
  2400. // 修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点。
  2401. calculate(treeNode, calcParents = true, calcFormulas = true, tender) {
  2402. let me = this;
  2403. let changedNodes = [];
  2404. me.innerCalc(treeNode, changedNodes, tender);
  2405. if (treeNode.changed) {
  2406. // 计算父结点
  2407. if (calcParents) {
  2408. let curNode = treeNode.parent;
  2409. while (curNode) {
  2410. me.innerCalc(curNode, changedNodes, tender);
  2411. curNode = curNode.parent;
  2412. }
  2413. }
  2414. // 父结点算完,再计算所有的公式结点(必须先算完父结点,再算公式结点)
  2415. if (calcFormulas) {
  2416. me.calcFormulaNodes(changedNodes, tender);
  2417. }
  2418. }
  2419. return changedNodes;
  2420. }
  2421. // 计算并保存一个树节点。(修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点)
  2422. calcAndSave(treeNode, callback, tender) {
  2423. this.calcNodesAndSave([treeNode], callback, tender);
  2424. /* let changedNodes = this.calculate(treeNode, true, true, tender); 统一调用相同的方法
  2425. this.saveNodes(changedNodes, callback);*/
  2426. }
  2427. /* 计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。参数取值如下:
  2428. calcAllType.catAll 计算所有树结点 (默认值)
  2429. calcAllType.catBills 计算所有清单 (改变项目属性中清单取费算法时会用到)
  2430. calcAllType.catRations 计算所有定额、工料机形式的定额、量价,因为它们都走自己的计算程序 (改变人工系数、费率值、工料机单价时会用到)
  2431. (calcAllType.catRations时程序中做了特殊处理,实际上是计算所有树结点!)
  2432. 调价相关参数:
  2433. tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  2434. */
  2435. calcAllNodes(calcType = calcAllType.catAll, tender) {
  2436. let me = this;
  2437. let changedNodes = [];
  2438. function calcNodes(nodes) {
  2439. for (let node of nodes) {
  2440. if (node.children.length > 0) {
  2441. calcNodes(node.children);
  2442. }
  2443. if (calcType == calcAllType.catAll || calcType == node.sourceType) {
  2444. node.calcType = calcTools.getCalcType(node);
  2445. if (node.calcType != treeNodeCalcType.ctCalcBaseValue)
  2446. me.innerCalc(node, changedNodes, tender);
  2447. }
  2448. }
  2449. }
  2450. // calcAllType.catRations 参数情况不会计算父结点(因为父结点是清单),所以这里进行特殊处理。
  2451. if (calcType == calcAllType.catRations) calcType == calcAllType.catAll;
  2452. calcNodes(me.project.mainTree.roots);
  2453. me.calcFormulaNodes(changedNodes, tender);
  2454. if (tender) {
  2455. for (let node of projectObj.project.mainTree.items) {
  2456. this.clearTenderCache(node);
  2457. }
  2458. }
  2459. return changedNodes;
  2460. }
  2461. // tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  2462. calcAllNodesAndSave(calcType = calcAllType.catAll, callback, tender) {
  2463. let changedNodes = this.calcAllNodes(calcType, tender);
  2464. this.saveNodes(changedNodes, callback);
  2465. }
  2466. // 计算零散的、混杂的树节点:清单、定额混合等(如:用到某一计算程序的定额和清单)。
  2467. // 计算多条零散的定额,并计算他们所属的清单、父清单、引用清单。如:批量替换工料机后受影响的定额。
  2468. // 计算多条零散的清单,并计算他们的父清单、引用清单。如:花选删除树结点(如花选清单、定额等,不区分树结点类型)。
  2469. calcNodesAndSave(nodes, callback, tender) {
  2470. let me = this,
  2471. rationNodes = [],
  2472. billNodes = [],
  2473. leafBills = [],
  2474. allChangedNodes = [];
  2475. for (let node of nodes) {
  2476. if (node.sourceType == ModuleNames.ration) rationNodes.push(node);
  2477. else billNodes.push(node);
  2478. }
  2479. // 多条定额同属一条叶子清单时,避免叶子清单重复计算
  2480. for (let ration of rationNodes) {
  2481. me.innerCalc(ration, allChangedNodes, tender);
  2482. let leafBill = ration.parent;
  2483. if (leafBill && leafBills.indexOf(leafBill) < 0) leafBills.push(leafBill);
  2484. }
  2485. billNodes.merge(leafBills);
  2486. for (let bill of billNodes) {
  2487. let changeBills = me.calculate(bill, true, false, tender);
  2488. allChangedNodes.merge(changeBills);
  2489. }
  2490. me.calcFormulaNodes(allChangedNodes, tender);
  2491. me.saveNodes(allChangedNodes, callback);
  2492. }
  2493. // 计算全部公式项。 (changedArr:将通过本方法后发生改变的节点存入changedArr中)
  2494. calcFormulaNodes(changedArr, tender) {
  2495. let me = this;
  2496. let formulaNodes = cbTools.getFormulaNodes(true);
  2497. if (formulaNodes.length == 0) return;
  2498. for (let formulaNode of formulaNodes) {
  2499. formulaNode.data.userCalcBase = formulaNode.data.calcBase; // 这句不该出现,projectObj.project.calcBase中要改进。
  2500. projectObj.project.calcBase.calculate(formulaNode, true);
  2501. if (projectObj.project.calcBase.success) {
  2502. // 计算公式结点
  2503. me.innerCalc(formulaNode, changedArr, tender);
  2504. // 计算父结点
  2505. if (formulaNode.changed) {
  2506. let curNode = formulaNode.parent;
  2507. while (curNode) {
  2508. me.innerCalc(curNode, changedArr, tender);
  2509. curNode = curNode.parent;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. }
  2515. // 计算叶子清单下的所有子结点、自身、所有父结点、公式引用结点(即跟该叶子清单相关的所有结点)。最后打包存储。
  2516. calcLeafAndSave(treeNode, tender) {
  2517. let me = this;
  2518. if (!calcTools.isLeafBill(treeNode)) return;
  2519. if (treeNode.children && treeNode.children.length > 0) {
  2520. let changedNodes = [];
  2521. for (let child of treeNode.children) {
  2522. me.innerCalc(child, changedNodes);
  2523. }
  2524. let curChangeds = me.calculate(treeNode, true, true, tender);
  2525. changedNodes.merge(curChangeds);
  2526. me.saveNodes(changedNodes);
  2527. }
  2528. }
  2529. // 排除指定项的综合合价计算(用于带循环计算的情况。这里的汇总只到清单级别即可:清单单价取费时,汇总到清单和汇总到定额两个值不一样)
  2530. getTotalFee(baseNodes, excludeNodes, tender) {
  2531. let rst = 0;
  2532. const totalFeeType = tender ? "common.tenderTotalFee" : "common.totalFee";
  2533. function calcNodes(nodes) {
  2534. for (let node of nodes) {
  2535. if (!node) {
  2536. continue;
  2537. }
  2538. if (!excludeNodes.includes(node)) {
  2539. if (
  2540. node.source &&
  2541. node.source.children &&
  2542. node.source.children.length > 0
  2543. ) {
  2544. calcNodes(node.children);
  2545. } else {
  2546. if (node.sourceType == ModuleNames.bills) {
  2547. rst = (rst + calcTools.getFee(node, totalFeeType)).toDecimal(
  2548. decimalObj.decimal("totalPrice", node)
  2549. );
  2550. }
  2551. }
  2552. }
  2553. }
  2554. }
  2555. calcNodes(baseNodes);
  2556. return rst;
  2557. }
  2558. // 税前工程造价 ,adj调价
  2559. getBeforeTaxTotalFee(excludeNodes, tender) {
  2560. let baseNodes = [],
  2561. me = this;
  2562. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.SUB_ENGINERRING));
  2563. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.MEASURE));
  2564. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.OTHER));
  2565. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.CHARGE));
  2566. return me.getTotalFee(baseNodes, excludeNodes, tender);
  2567. }
  2568. // 清理调价缓存数据
  2569. clearTenderCache(treeNode) {
  2570. // 这些属性值为什么不定义在一个对象里?因为每次要判断对象是否存在,十分麻烦。不如直接写简单。分散书写,统一处理也很好用。
  2571. if (treeNode.data.tender_activeTotal)
  2572. delete treeNode.data.tender_activeTotal;
  2573. if (treeNode.data.tender_activeTarget)
  2574. delete treeNode.data.tender_activeTarget;
  2575. if (treeNode.data.tender_fullLoad) delete treeNode.data.tender_fullLoad;
  2576. if (treeNode.data.tender_distribute) {
  2577. delete treeNode.data.targetTotalFee;
  2578. delete treeNode.data.targetUnitFee;
  2579. delete treeNode.data.tender_distribute;
  2580. }
  2581. }
  2582. initGljPriceTenderCoe() {
  2583. if (
  2584. projectObj.project.property.tenderSetting &&
  2585. projectObj.project.property.tenderSetting.gljPriceTenderCoe &&
  2586. projectObj.project.property.tenderSetting.gljPriceTenderCoe != 1
  2587. ) {
  2588. projectObj.project.property.tenderSetting.gljPriceTenderCoe = 1; // 修改缓存值,用于计算
  2589. projectObj.project.property.needRestoreGgljPriceTenderCoe = true; // 做个标记,告诉回调函数
  2590. }
  2591. }
  2592. // 反向调价-初始化调价树、清理缓存数据等
  2593. reverseTenderInitDatas() {
  2594. for (let node of tender_obj.tenderTree.items) {
  2595. if (node.data.rationQuantityCoe) node.data.rationQuantityCoe = null;
  2596. let qcObj = node.data.quantityCoe;
  2597. if (qcObj) {
  2598. for (let pn in qcObj) {
  2599. qcObj[pn] = null;
  2600. }
  2601. }
  2602. this.clearTenderCache(node);
  2603. }
  2604. // 反向调价时人材机单价调整系数要归1:因为既可以调量又可以调价,以哪个为基准进行反调?过于复杂,仅以通用的调量逻辑为基准即可满足需求。
  2605. this.initGljPriceTenderCoe();
  2606. }
  2607. // 反向调价简单计算:只计算当前单一结点,由目标金额计算定额量系数或工料机量系数coe,再根据此coe计算定额的调后量、调后合价。
  2608. // ⑴只计算参数指定的一个单一的结点,连父结点、引用结点都不计算。此结点只会是定额、量价、工料机款定额,不会是清单。
  2609. // ⑵执行此方法的前提:已在其它地方把总的目标金额分摊好了,此结点已获取目标金额。
  2610. reverseTenderCalc(treeNode, tender) {
  2611. if (tender == tenderTypes.ttReverseRation) {
  2612. if (
  2613. treeNode.data.feesIndex.common &&
  2614. treeNode.data.feesIndex.common.tenderUnitFee !=
  2615. treeNode.data.feesIndex.common.unitFee
  2616. ) {
  2617. treeNode.data.feesIndex.common.tenderUnitFee =
  2618. treeNode.data.feesIndex.common.unitFee;
  2619. treeNode.changed = true;
  2620. }
  2621. }
  2622. if (!treeNode.data.targetTotalFee) {
  2623. // 没有目标金额、但有输入目标单价的:根据目标单价算出目标金额。
  2624. if (treeNode.data.targetUnitFee) {
  2625. treeNode.data.targetTotalFee = (
  2626. treeNode.data.targetUnitFee * treeNode.data.quantity
  2627. ).toDecimal(decimalObj.decimal("totalPrice", treeNode));
  2628. treeNode.changed = true;
  2629. } else {
  2630. // 既没有目标金额也没有目标单价,此时要初始化使调价合价=原始综合合价,调价单价=原始综合单价。
  2631. if (
  2632. treeNode.data.feesIndex.common &&
  2633. treeNode.data.feesIndex.common.tenderUnitFee !=
  2634. treeNode.data.feesIndex.common.unitFee
  2635. ) {
  2636. treeNode.data.feesIndex.common.tenderUnitFee =
  2637. treeNode.data.feesIndex.common.unitFee;
  2638. treeNode.changed = true;
  2639. }
  2640. if (
  2641. treeNode.data.feesIndex.common &&
  2642. treeNode.data.feesIndex.common.tenderTotalFee !=
  2643. treeNode.data.feesIndex.common.totalFee
  2644. ) {
  2645. treeNode.data.feesIndex.common.tenderTotalFee =
  2646. treeNode.data.feesIndex.common.totalFee;
  2647. treeNode.changed = true;
  2648. }
  2649. return;
  2650. }
  2651. }
  2652. // 经过前面的一通折腾还是没有目标单价的话,那么就要通过目标金额算出来。
  2653. if (
  2654. !treeNode.data.targetUnitFee ||
  2655. parseFloat(treeNode.data.targetUnitFee) == 0
  2656. ) {
  2657. if (calcTools.hasQuantity(treeNode))
  2658. treeNode.data.targetUnitFee = (
  2659. treeNode.data.targetTotalFee / treeNode.data.quantity
  2660. ).toDecimal(decimalObj.decimal("unitPrice", treeNode));
  2661. }
  2662. // 系数=调后单价/调前单价
  2663. let coe = 1;
  2664. if (treeNode.data.feesIndex.common.totalFee != 0)
  2665. coe = (
  2666. treeNode.data.targetUnitFee / treeNode.data.feesIndex.common.unitFee
  2667. ).toDecimal(decimalObj.process);
  2668. // 量价、工料机款式的定额:它们无下挂工料机可调,直接调树结点的消耗量。
  2669. let isVP_RevGLJ =
  2670. tender == tenderTypes.ttReverseGLJ && calcTools.isVP_or_GLJR(treeNode);
  2671. if (tender == tenderTypes.ttReverseRation || isVP_RevGLJ) {
  2672. treeNode.data.tenderQuantity = (treeNode.data.quantity * coe).toDecimal(
  2673. decimalObj.decimal("quantity", treeNode)
  2674. );
  2675. if (treeNode.data.rationQuantityCoe != coe) {
  2676. treeNode.data.rationQuantityCoe = coe;
  2677. treeNode.changed = true;
  2678. }
  2679. if (isVP_RevGLJ) {
  2680. treeNode.data.quantityCoe = {
  2681. labour: 0,
  2682. material: 0,
  2683. machine: 0,
  2684. main: 0,
  2685. equipment: 0,
  2686. };
  2687. treeNode.changed = true;
  2688. }
  2689. let ttf = (
  2690. treeNode.data.tenderQuantity *
  2691. treeNode.data.feesIndex.common.tenderUnitFee
  2692. ).toDecimal(decimalObj.decimal("totalPrice", treeNode));
  2693. if (treeNode.data.feesIndex.common.tenderTotalFee != ttf) {
  2694. treeNode.data.feesIndex.common.tenderTotalFee = ttf;
  2695. treeNode.changed = true;
  2696. }
  2697. } else if (tender == tenderTypes.ttReverseGLJ) {
  2698. let qcObj = treeNode.data.quantityCoe;
  2699. if (!qcObj || calcTools.isEmptyObject(qcObj)) {
  2700. treeNode.data.quantityCoe = {
  2701. labour: coe,
  2702. material: coe,
  2703. machine: coe,
  2704. main: coe,
  2705. equipment: coe,
  2706. };
  2707. treeNode.changed = true;
  2708. } else {
  2709. // 这种写法会漏掉属性,导致界面显示不统一。
  2710. /* for (let pn in qcObj){
  2711. if (qcObj[pn] != coe){
  2712. qcObj[pn] = coe;
  2713. treeNode.changed = true;
  2714. }
  2715. };*/
  2716. if (qcObj.labour != coe) {
  2717. qcObj.labour = coe;
  2718. treeNode.changed = true;
  2719. }
  2720. if (qcObj.material != coe) {
  2721. qcObj.material = coe;
  2722. treeNode.changed = true;
  2723. }
  2724. if (qcObj.machine != coe) {
  2725. qcObj.machine = coe;
  2726. treeNode.changed = true;
  2727. }
  2728. if (qcObj.main != coe) {
  2729. qcObj.main = coe;
  2730. treeNode.changed = true;
  2731. }
  2732. if (qcObj.equipment != coe) {
  2733. qcObj.equipment = coe;
  2734. treeNode.changed = true;
  2735. }
  2736. }
  2737. projectObj.project.calcProgram.calculate(
  2738. treeNode,
  2739. false,
  2740. false,
  2741. tenderTypes.ttCalc
  2742. ); // 再正向算
  2743. }
  2744. }
  2745. // 反向调价-分摊前的准备工作。包括:
  2746. // ⑴结点是否满载
  2747. // ⑵若是满载,汇总孩子的金额、目标金额给它
  2748. // ⑶标记此结点的目标金额来自孩子,未来它不往下分摊(汇上来再摊下去无用功)
  2749. prepareForDistribute(treeNode) {
  2750. if (!treeNode) return;
  2751. if (treeNode.firstChild()) this.prepareForDistribute(treeNode.firstChild());
  2752. if (treeNode.children.length == 0) {
  2753. } else {
  2754. let full = true;
  2755. for (let i = 0; i < treeNode.children.length; i++) {
  2756. let child = treeNode.children[i];
  2757. if (
  2758. !child.data.tender_fullLoad &&
  2759. !calcTools.hasTargetTotalFee(child)
  2760. ) {
  2761. full = false;
  2762. break;
  2763. }
  2764. }
  2765. if (full) {
  2766. let total = 0,
  2767. target = 0;
  2768. for (let i = 0; i < treeNode.children.length; i++) {
  2769. let child = treeNode.children[i];
  2770. total = total + parseFloat(child.data.feesIndex["common"].totalFee);
  2771. target = target + parseFloat(child.data.targetTotalFee);
  2772. }
  2773. treeNode.data.tender_activeTotal = total;
  2774. treeNode.data.tender_activeTarget = target;
  2775. treeNode.data.targetTotalFee = target;
  2776. treeNode.data.tender_distribute = 2;
  2777. }
  2778. treeNode.data.tender_fullLoad = full;
  2779. }
  2780. if (treeNode.nextSibling) this.prepareForDistribute(treeNode.nextSibling);
  2781. }
  2782. // 反向调价-分摊目标合价:从父到子往下分摊。
  2783. distributeTargetTotalFee(treeNode) {
  2784. if (!treeNode) return;
  2785. if (treeNode.data.feesIndex && treeNode.data.feesIndex["common"]) {
  2786. // 空清单忽略
  2787. // 默认能够执行到这里时每个节点已经被初始化,缓存已删除
  2788. treeNode.data.tender_activeTotal =
  2789. treeNode.data.feesIndex["common"].totalFee;
  2790. // 开始分摊:只分摊自有目标金额、从父结点分摊到的金额(不分摊子结点汇总上来的金额)
  2791. if (
  2792. calcTools.hasTargetTotalFee(treeNode) &&
  2793. !(
  2794. treeNode.data.tender_distribute &&
  2795. treeNode.data.tender_distribute == 2
  2796. )
  2797. ) {
  2798. treeNode.data.tender_activeTarget = treeNode.data.targetTotalFee;
  2799. // 先把会破坏金额比例关系的孩子排除:1.有目标金额的 2.满载的(孙子全满,没有分摊空间,所以实质上该孩子的金额已被锁死无法分摊)
  2800. for (let i = 0; i < treeNode.children.length; i++) {
  2801. let child = treeNode.children[i];
  2802. if (!child.data.feesIndex || !child.data.feesIndex["common"])
  2803. continue; // 空白行清单、定额
  2804. child.data.tender_activeTotal =
  2805. child.data.feesIndex["common"].totalFee;
  2806. if (calcTools.hasTargetTotalFee(child)) {
  2807. child.data.tender_activeTarget = child.data.targetTotalFee;
  2808. console.log(treeNode.data.tender_activeTotal);
  2809. console.log(child.data.tender_activeTotal);
  2810. treeNode.data.tender_activeTotal =
  2811. treeNode.data.tender_activeTotal - child.data.tender_activeTotal;
  2812. treeNode.data.tender_activeTarget =
  2813. treeNode.data.tender_activeTarget -
  2814. child.data.tender_activeTarget;
  2815. }
  2816. }
  2817. if (treeNode.data.tender_activeTotal != 0) {
  2818. let coe = (
  2819. treeNode.data.tender_activeTarget / treeNode.data.tender_activeTotal
  2820. ).toDecimal(decimalObj.process);
  2821. for (let i = 0; i < treeNode.children.length; i++) {
  2822. let child = treeNode.children[i];
  2823. if (!child.data.feesIndex || !child.data.feesIndex["common"])
  2824. continue; // 空白行清单、定额
  2825. if (!calcTools.hasTargetTotalFee(child)) {
  2826. child.data.tender_activeTarget = (
  2827. coe * child.data.tender_activeTotal
  2828. ).toDecimal(decimalObj.decimal("totalPrice", treeNode));
  2829. child.data.targetTotalFee = child.data.tender_activeTarget;
  2830. child.data.tender_distribute = 1; // 1表示分摊金额来自父结点。2表示分摊金额来自孩子结点。
  2831. }
  2832. }
  2833. }
  2834. }
  2835. }
  2836. if (treeNode.firstChild())
  2837. this.distributeTargetTotalFee(treeNode.firstChild());
  2838. if (treeNode.nextSibling)
  2839. this.distributeTargetTotalFee(treeNode.nextSibling);
  2840. }
  2841. // 反向调价逼近
  2842. reverseTenderApproach(callback, tender) {
  2843. let me = this;
  2844. function root0() {
  2845. return tender_obj.tenderTree.roots[0];
  2846. }
  2847. if (!root0().data.targetTotalFee) return; // 根结点没有指定目标金额时,逼近会带来莫名其妙的结果
  2848. let G_DIGIT = 0.01; // 系数调整步距(0.1最终结果误差大。0.001目标金额与逼前金额差距大时无法有效逼近)
  2849. let MaxDiffValue = 0.1; // 可接受的最大差值。(如果实际差值比这个大:说明列表结点耗尽,无法达到指定精度。公路设为1,建筑设为0.1)
  2850. let times = 300; // 逼近计算的极限次数。正常情况下“单位系数金额”列表中的结点耗尽即退出,这里指定轮数是最后保险阀,防止无限死循环。
  2851. let calcModel = 1; // 计算模式:1 精度优先(差值不接近0不停,直到结点用完或极限次数用完。时间长精度高)2 速度优先(达到指定差值范围即熔断逼近。时间短差值大)
  2852. let diffProp = 0.0001; // 计算模式=2(速度优先)时有效。 通过这个金额比例值计算可接受的最大差值D。差值D = 根结点金额 * diffProp
  2853. let isTest = true; // 测试
  2854. // 按指定的比例获取可接受的差值:如目标金额的万分之一。
  2855. function getPropV(node) {
  2856. let v = parseFloat((node.data.targetTotalFee * diffProp).toFixed(0)); // node.data.feesIndex.common.totalFee
  2857. return Math.max(v, MaxDiffValue);
  2858. }
  2859. // 取根结点的:调后金额跟目标金额差值,看还有多少误差需要处理。
  2860. function getRootDiff() {
  2861. return (
  2862. root0().data.feesIndex.common.tenderTotalFee -
  2863. root0().data.targetTotalFee
  2864. ).toDecimal(3);
  2865. }
  2866. // 生成每单位差值的定额结点列表。
  2867. function getNodeDiffs() {
  2868. let arr = [];
  2869. for (let i = 0; i < tender_obj.tenderTree.items.length; i++) {
  2870. let node = tender_obj.tenderTree.items[i];
  2871. if (calcTools.isInvalidNode(node)) continue;
  2872. // 量价还是要参与,因为它贡献了金额,如果它的金额比重很大,它退出了,会导致其它结点过调。
  2873. // if (calcTools.isRationCategory(node) && (!calcTools.isVP_or_GLJR(node))){
  2874. if (calcTools.isRationCategory(node)) {
  2875. let coe = calcTools.getCoe(node, tender);
  2876. if (coe != 0) {
  2877. let diff = Math.abs(
  2878. node.data.feesIndex.common.tenderTotalFee -
  2879. node.data.feesIndex.common.totalFee
  2880. );
  2881. node.data.tender_diffValuePerCoe = (
  2882. (diff * G_DIGIT) /
  2883. coe
  2884. ).toDecimal(decimalObj.process);
  2885. node.data.tender_rowNo = i + 1; // node在UI上显示的行号
  2886. arr.push(node);
  2887. }
  2888. }
  2889. }
  2890. arr.sort(function sortArr(a, b) {
  2891. return a.data.tender_diffValuePerCoe - b.data.tender_diffValuePerCoe;
  2892. });
  2893. if (isTest) {
  2894. let arr2 = [];
  2895. for (let i = 0; i < arr.length; i++) {
  2896. arr2.push({
  2897. row: arr[i].data.tender_rowNo,
  2898. code: arr[i].data.code + " " + arr[i].data.name,
  2899. diff: arr[i].data.tender_diffValuePerCoe,
  2900. });
  2901. }
  2902. console.log(arr2);
  2903. }
  2904. return arr;
  2905. }
  2906. // 每单位差值的定额结点列表中,取离给定值最近的定额结点。
  2907. function getCloseNode(arr, value) {
  2908. let index = 0;
  2909. let d_value = Number.MAX_VALUE;
  2910. for (let i = 0; i < arr.length; i++) {
  2911. let new_d_value = Math.abs(arr[i].data.tender_diffValuePerCoe - value);
  2912. if (new_d_value <= d_value) {
  2913. if (
  2914. new_d_value === d_value &&
  2915. arr[i].data.tender_diffValuePerCoe <
  2916. arr[index].data.tender_diffValuePerCoe
  2917. ) {
  2918. continue;
  2919. }
  2920. index = i;
  2921. d_value = new_d_value;
  2922. }
  2923. }
  2924. return { idx: index, node: arr[index] };
  2925. }
  2926. // 逼近(单轮)。arr 参考取值列表。返回{type, node, nodeIdx}。
  2927. // type:1正常,2无结点,3结点过调。node:结点。nodeIdx:结点在列表中的索引位置。node.data.tender_rowNo 在UI上的行号。
  2928. function approach(arr) {
  2929. let v = getRootDiff();
  2930. let obj = getCloseNode(arr, Math.abs(v)); // {idx, node} 极端:{0, undefind}
  2931. let closeNode = obj.node;
  2932. if (!closeNode) return { type: 2, node: undefined, nodeIdx: -1 }; // arr 被清空了
  2933. let d = v > 0 ? -G_DIGIT : G_DIGIT;
  2934. let coe = calcTools.getCoe(closeNode, tender);
  2935. if (coe + d < 0) return { type: 3, node: obj.node, nodeIdx: obj.idx }; // 再调的话,系数就变负数了,过调
  2936. if (tender == tenderTypes.ttReverseRation) {
  2937. closeNode.data.tender_previousCoe = closeNode.data.rationQuantityCoe; // tender_previousCoe: 上一次的调整系数,用于撤回
  2938. closeNode.data.rationQuantityCoe = (
  2939. closeNode.data.rationQuantityCoe + d
  2940. ).toDecimal(decimalObj.process);
  2941. } else if (tender == tenderTypes.ttReverseGLJ) {
  2942. if (calcTools.isVP_or_GLJR(closeNode)) {
  2943. closeNode.data.tender_previousCoe = closeNode.data.rationQuantityCoe;
  2944. closeNode.data.rationQuantityCoe = (
  2945. closeNode.data.rationQuantityCoe + d
  2946. ).toDecimal(decimalObj.process);
  2947. } else {
  2948. closeNode.data.tender_previousCoe = closeNode.data.quantityCoe.labour;
  2949. closeNode.data.quantityCoe.labour = (
  2950. closeNode.data.quantityCoe.labour + d
  2951. ).toDecimal(decimalObj.process);
  2952. closeNode.data.quantityCoe.material = (
  2953. closeNode.data.quantityCoe.material + d
  2954. ).toDecimal(decimalObj.process);
  2955. closeNode.data.quantityCoe.machine = (
  2956. closeNode.data.quantityCoe.machine + d
  2957. ).toDecimal(decimalObj.process);
  2958. closeNode.data.quantityCoe.main = (
  2959. closeNode.data.quantityCoe.main + d
  2960. ).toDecimal(decimalObj.process);
  2961. closeNode.data.quantityCoe.equipment = (
  2962. closeNode.data.quantityCoe.equipment + d
  2963. ).toDecimal(decimalObj.process);
  2964. }
  2965. }
  2966. me.calculate(closeNode, true, true, tenderTypes.ttCalc);
  2967. return { type: 1, node: obj.node, nodeIdx: obj.idx };
  2968. }
  2969. // 撤消最后一轮逼近(调过头了,回退一步)
  2970. function undoLastApproach(obj) {
  2971. let closeNode = obj.node;
  2972. let coe = closeNode.data.tender_previousCoe;
  2973. if (tender == tenderTypes.ttReverseRation) {
  2974. closeNode.data.rationQuantityCoe = coe;
  2975. } else if (tender == tenderTypes.ttReverseGLJ) {
  2976. if (calcTools.isVP_or_GLJR(closeNode)) {
  2977. closeNode.data.rationQuantityCoe = coe;
  2978. } else {
  2979. closeNode.data.quantityCoe.labour = coe;
  2980. closeNode.data.quantityCoe.material = coe;
  2981. closeNode.data.quantityCoe.machine = coe;
  2982. closeNode.data.quantityCoe.main = coe;
  2983. closeNode.data.quantityCoe.equipment = coe;
  2984. }
  2985. }
  2986. me.calculate(closeNode, true, true, tenderTypes.ttCalc);
  2987. if (isTest) {
  2988. let _sp = `        `; // 保留空格,打印对齐
  2989. let _node = `[行${obj.node.data.tender_rowNo} 索引${obj.nodeIdx}]`;
  2990. console.log(`${_sp} ${_node} 过调,已回退`);
  2991. }
  2992. }
  2993. let root = tender_obj.tenderTree.roots[0];
  2994. let propV = getPropV(root);
  2995. let vArr = getNodeDiffs();
  2996. let d1 = getRootDiff();
  2997. if (isTest) {
  2998. let _tq = `调前${root.data.feesIndex.common.totalFee}`;
  2999. let _mb = `目标${root.data.targetTotalFee}`;
  3000. let _wbj = `调后无逼近${root.data.feesIndex.common.tenderTotalFee}`;
  3001. let _cz = `差值${d1}`;
  3002. let _js = `轮${times} 系数步距${G_DIGIT}`;
  3003. let _yx =
  3004. calcModel == 2
  3005. ? `速度优先(差比${diffProp} 差域0~${propV})`
  3006. : "精度优先";
  3007. console.log(`${_tq}|${_mb}|${_wbj}|${_cz}|${_yx}|${_js}`);
  3008. }
  3009. // 多轮逼进
  3010. for (let i = 1; i <= times; i++) {
  3011. // 与目标金额差值在1以内,整数部分已相同,结果很棒。很多时候能达到完美的差值0,但不能用0判断,因为金额取小数时有问题。
  3012. if (Math.abs(d1) < MaxDiffValue) break;
  3013. // 速度优先模式下,结果到达差值范围内,即熔断逼近。
  3014. if (calcModel == 2) {
  3015. if (Math.abs(d1) < propV) break;
  3016. }
  3017. let obj = approach(vArr);
  3018. if (obj.type == 2) break; // 结点耗完,列表已清空,无结点可调。
  3019. if (obj.type == 3) {
  3020. // 结点过调,该结点任务已完成,不再参与调节,从列表中清除
  3021. vArr.splice(obj.nodeIdx, 1);
  3022. continue;
  3023. }
  3024. let d2 = getRootDiff();
  3025. if (isTest) {
  3026. let _time = `【第 ${i} 轮】调整`;
  3027. let _node = `[行${obj.node.data.tender_rowNo} 索引${obj.nodeIdx}]`;
  3028. let _coe = `${obj.node.data.tender_previousCoe} → ${calcTools.getCoe(
  3029. obj.node,
  3030. tender
  3031. )}`;
  3032. let _d = `差值${d1} → ${d2}`;
  3033. console.log(`${_time}${_node} ${_coe},${_d}`);
  3034. }
  3035. if (Math.abs(d2) > Math.abs(d1)) {
  3036. // 逼近后差值反而变大,证明此轮调节不合适,回退一步,并将结点从列表清除
  3037. undoLastApproach(obj);
  3038. vArr.splice(obj.nodeIdx, 1);
  3039. } else if (Math.abs(d2) == Math.abs(d1)) {
  3040. // 调前调后差距相同时,会死循环,也从列表中清除
  3041. vArr.splice(obj.nodeIdx, 1);
  3042. } else {
  3043. d1 = d2;
  3044. }
  3045. }
  3046. // 重要注释:到这里,所有系数已处理就绪,最后直接全局正算即可。
  3047. // 到这一步,被处理的定额、及其受影响的父结点、引用结点等均已正算完成(approach方法、undoLastApproach方法),但都未保存。
  3048. // 最后全局正算目的:⑴计算除第一部以外的其它部分 ⑵保存。正算在调用外面完成。
  3049. // this.calcAllNodesAndSave(calcAllType.catAll, callback, tenderTypes.ttCalc);
  3050. }
  3051. setRationMap() {
  3052. if (this.rationMap == null) {
  3053. this.rationMap = {};
  3054. for (let glj of projectObj.project.ration_glj.datas) {
  3055. if (this.rationMap[glj.rationID]) {
  3056. this.rationMap[glj.rationID].push(glj);
  3057. } else {
  3058. this.rationMap[glj.rationID] = [glj];
  3059. }
  3060. }
  3061. }
  3062. if (this.pgljMap == null) {
  3063. this.pgljMap = _.indexBy(
  3064. projectObj.project.projectGLJ.datas.gljList,
  3065. "id"
  3066. );
  3067. }
  3068. }
  3069. getGljArrByRation(ration) {
  3070. if (ration.type == rationType.gljRation) {
  3071. let glj = JSON.parse(JSON.stringify(ration));
  3072. glj.type = glj.subType;
  3073. glj.quantity = 1;
  3074. glj.totalQuantity = parseFloatPlus(ration.quantity);
  3075. return [glj];
  3076. } else {
  3077. if (!this.rationMap) return [];
  3078. let result = this.rationMap[ration.ID];
  3079. if (!result) return [];
  3080. result = gljOprObj.combineWithProjectGlj(
  3081. result,
  3082. false,
  3083. ration,
  3084. this.pgljMap
  3085. );
  3086. return result;
  3087. }
  3088. }
  3089. doTenderCalc(callback) {
  3090. $.bootstrapLoading.start();
  3091. setTimeout(() => {
  3092. let tender = calcTools.getTenderType();
  3093. if (
  3094. tender == tenderTypes.ttReverseGLJ ||
  3095. tender == tenderTypes.ttReverseRation
  3096. ) {
  3097. // 调价计算必须依赖调价树。
  3098. if (!tender_obj.tenderTree) {
  3099. tender_obj.createTree();
  3100. tender_obj.createTreeNodes();
  3101. }
  3102. // 反向调价+逼近原理:
  3103. // 清理调价缓存 → 分摊目标金额(从子往父处理满载、从父往子分摊) → 全局反算 → 逼近 → 全局正算、存储
  3104. this.reverseTenderInitDatas();
  3105. this.prepareForDistribute(tender_obj.tenderTree.roots[0]);
  3106. this.distributeTargetTotalFee(tender_obj.tenderTree.roots[0]);
  3107. this.calcAllNodes(calcAllType.catAll, tender); // 先全局反算:得到每定额的coe、基础调后金额(误差大,需逼近)
  3108. this.reverseTenderApproach(callback, tender); // 逼近上述基础调后金额
  3109. }
  3110. // 全局正算(用的是主树,无需调价树)
  3111. this.calcAllNodesAndSave(
  3112. calcAllType.catAll,
  3113. callback,
  3114. tenderTypes.ttCalc
  3115. );
  3116. });
  3117. }
  3118. }
  3119. // export default analyzer;